Skip to content

Commit

Permalink
Copy over FileGenerator from main branch to resolve merge conflict
Browse files Browse the repository at this point in the history
This branch was created before a fix was added thats why i just commented out the code
  • Loading branch information
Toddelismyname committed Dec 5, 2024
1 parent 660eca4 commit 86362d2
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions FileGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
from generation_utils.StructureHandler import StructureHandler
import yaml
from generation_utils.Logger import Logger
import shutil
# from precice_struct import PS_PreCICEConfig
# from ui_struct.UI_UserInput import UI_UserInput
# from myutils.UT_PCErrorLogging import UT_PCErrorLogging
import sys
# Insert controller into syspath so imports within controller submodule will still work
sys.path.insert(0, str(( Path(__file__).parent / 'controller' ).resolve()))
# Import controller classes
from controller.ui_struct.UI_UserInput import UI_UserInput
from controller.myutils.UT_PCErrorLogging import UT_PCErrorLogging
from precice_struct import PS_PreCICEConfig
import argparse

class FileGenerator:
def __init__(self, file: Path) -> None:
""" Class which takes care of generating the content of the necessary files
:param file: Input yaml file that is needed for generation of the precice-config.xml file"""
self.input_file = file
#self.precice_config = PS_PreCICEConfig()
#self.mylog = UT_PCErrorLogging()
#self.user_ui = UI_UserInput()
self.precice_config = PS_PreCICEConfig()
self.mylog = UT_PCErrorLogging()
self.user_ui = UI_UserInput()
self.logger = Logger()
self.structure = StructureHandler()

Expand All @@ -33,26 +37,25 @@ def generate_precice_config(self) -> None:
self.logger.error(f"Error reading input YAML file: {str(e)}")
return

# # Build the ui
# self.logger.info("Building the user input info...")
# self.user_ui.init_from_yaml(config, self.mylog)
#
# # Generate the precice-config.xml file
# self.logger.info("Generating preCICE config...")
# self.precice_config.create_config(self.user_ui)
#
# # Set the target of the file and write out to it
# # Warning: self.structure.precice_config is of type Path, so it needs to be converted to str
# target = str(self.structure.precice_config)
# try:
# self.logger.info(f"Writing preCICE config to {target}...")
# self.precice_config.write_precice_xml_config(target, self.mylog)
# except Exception as e:
# self.logger.error(f"Failed to write preCICE XML config: {str(e)}")
# return
#
# self.logger.success(f"XML generation completed successfully: {target}")
self.logger.success(f"XML generation completed successfully:")
# Build the ui
self.logger.info("Building the user input info...")
self.user_ui.init_from_yaml(config, self.mylog)

# Generate the precice-config.xml file
self.logger.info("Generating preCICE config...")
self.precice_config.create_config(self.user_ui)

# Set the target of the file and write out to it
# Warning: self.structure.precice_config is of type Path, so it needs to be converted to str
target = str(self.structure.precice_config)
try:
self.logger.info(f"Writing preCICE config to {target}...")
self.precice_config.write_precice_xml_config(target, self.mylog)
except Exception as e:
self.logger.error(f"Failed to write preCICE XML config: {str(e)}")
return

self.logger.success(f"XML generation completed successfully: {target}")

def generate_README(self) -> None:
"""Generates the README.md file"""
Expand Down Expand Up @@ -101,6 +104,16 @@ def generate_adapter_config(self) -> None:
pass

if __name__ == "__main__":
fileGenerator = FileGenerator(Path("./examples/3/topology.yaml"))
parser = argparse.ArgumentParser(description="Takes topology.yaml files as input and writes out needed files to start the precice.")
parser.add_argument(
"-f", "--file",
type=Path,
required=False,
help="Input topology.yaml file",
default=Path("controller/examples/1/topology.yaml")
)
args = parser.parse_args()

fileGenerator = FileGenerator(args.file)
fileGenerator.generate_precice_config()
fileGenerator.generate_README()
fileGenerator.generate_README()

0 comments on commit 86362d2

Please sign in to comment.