Commits (2)
......@@ -101,10 +101,7 @@ def check_paths(repo_path: Path, workflow_path: Path):
logging.debug(" * Available citygml : %s", gml.name)
def prepare_workflow(workflow_path, citygmls):
if isinstance(citygmls, str):
citygmls = [citygmls]
def prepare_workflow(workflow_path: Path, citygmls: list[str]):
tree = et.parse(workflow_path / PARAMS)
root = tree.getroot()
......@@ -137,8 +134,8 @@ def prepare_workflow(workflow_path, citygmls):
return name
def get_all_files(folder):
files = [f for f in Path(folder).glob('**/*') if f.is_file() and f.name != PARAMS]
def get_all_files(folder: Path) -> dict[Path, float]:
files = [f for f in folder.glob('**/*') if f.is_file() and f.name != PARAMS]
return {f: f.stat().st_mtime for f in files}
......@@ -149,7 +146,7 @@ def simstadt_script():
return './SimStadt.sh'
def run_simstadt(simstadt_path, workflow_path, name):
def run_simstadt(simstadt_path: Path, workflow_path:Path , name: str):
os.chdir(simstadt_path)
try:
logging.info("\n# Launching %s:", name)
......@@ -166,16 +163,19 @@ def run_simstadt(simstadt_path, workflow_path, name):
logging.info(result.stderr)
def compare_written_files(repo_path, before, after):
def compare_written_files(repo_path: Path, before, after) -> list[Path]:
modified_files = []
logging.info("# Listing written files :")
for result_file, modification_time in after.items():
before_time = before.get(result_file, 0)
if modification_time > before_time:
logging.info(" * '%s'", result_file.relative_to(repo_path))
modified_files.append(result_file)
logging.info("\n")
return modified_files
def run_workflow(simstadt_path: Path, workflow_path: Path, citygmls: list[str]):
def run_workflow(simstadt_path: Path, workflow_path: Path, citygmls: list[str]) -> list[Path]:
repo_path = workflow_path.parent.parent
check_paths(repo_path, workflow_path)
......@@ -186,7 +186,7 @@ def run_workflow(simstadt_path: Path, workflow_path: Path, citygmls: list[str]):
run_simstadt(simstadt_path, workflow_path, name)
after = get_all_files(workflow_path)
compare_written_files(repo_path, before, after)
return compare_written_files(repo_path, before, after)
def main(glob: str, repo: Path, project_name: str, workflows: list[str], citygmls: list[str]):
......
from run_simstadt_workflow import find_simstadt
from pathlib import Path
import shutil
from run_simstadt_workflow import find_simstadt, check_paths, SCRIPT_DIR, prepare_workflow, run_workflow
SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/'
REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository'
PROJECT_NAME = 'Gruenbuehl'
CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010_2buildings.gml']
PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj'
PARAMS = 'params.xml'
print(find_simstadt(SIMSTADT2_GLOB))
TEMPLATE_NAME = '99_HeatDemand'
TEMPLATE = SCRIPT_DIR / 'Template' / f'{TEMPLATE_NAME}.flow' # Heat demand, with custom BuildingPhysics
WORKFLOW_PATH = PROJECT_PATH / f'{TEMPLATE_NAME}.flow'
shutil.copytree(TEMPLATE, WORKFLOW_PATH, dirs_exist_ok=True)
check_paths(REPO_PATH, WORKFLOW_PATH)
prepare_workflow(WORKFLOW_PATH, CITYGMLS)
output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), WORKFLOW_PATH, CITYGMLS)
print(next(file for file in output_files if 'HEATING.csv' in file.name))