Skip to content

Commit

Permalink
Merge pull request #11 from DHI/pathlib
Browse files Browse the repository at this point in the history
Pathlib + f-strings
  • Loading branch information
wuwwen authored Mar 25, 2024
2 parents d18f131 + a873b13 commit 55edd4a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions mikeplus/engines/engine1d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os.path
from pathlib import Path
import subprocess
from DHI.Mike.Install import MikeImport, MikeProducts

Expand Down Expand Up @@ -37,15 +37,14 @@ def run(self,
simMuid = muid[0]

product_info = MikeImport.ActiveProduct()
mike1d_exec = os.path.join(product_info.InstallRoot, 'bin', 'x64', 'DHI.Mike1D.Application.exe')
dbOrMuppFile = self._dataTables.DataSource.BaseFullPath
dir = os.path.dirname(os.path.abspath(dbOrMuppFile))
file = os.path.basename(dbOrMuppFile)
file_name = file.split('.')[0]
log_file = os.path.join(dir, file_name + '_' + simMuid + '.log')
self._result_file = os.path.join(dir, file_name + '_' + simMuid + '.res1d')
print("Simulation is started. Simulation id is '" + simMuid + "'")
subprocess.run([mike1d_exec, str(dbOrMuppFile), "-simulationid=" + simMuid, "-logfilename=" + log_file])
mike1d_exec = Path(product_info.InstallRoot) / 'bin' / 'x64' / 'DHI.Mike1D.Application.exe'
dbOrMuppFile = Path(self._dataTables.DataSource.BaseFullPath)
dir = dbOrMuppFile.parent
file_name = dbOrMuppFile.stem
log_file = Path(dir) / f"{file_name}_{simMuid}.log"
self._result_file = Path(dir) / f"{file_name}_{simMuid}.res1d"
print(f"Simulation is started. Simulation id is '{simMuid}'.")
subprocess.run([mike1d_exec, str(dbOrMuppFile), f"-simulationid={simMuid}", f"-logfilename={log_file}"])
if self._print_log(log_file) is False:
print("Simulation is finished without logFile generated.")

Expand All @@ -61,7 +60,7 @@ def result_file(self):
return self._result_file

def _print_log(self, logFile):
if os.path.exists(logFile):
if Path(logFile).exists():
with open(logFile) as f:
lines = f.readlines()
for line in lines:
Expand Down

0 comments on commit 55edd4a

Please sign in to comment.