|
38 | 38 | import numbers |
39 | 39 | import numpy as np |
40 | 40 | import os |
| 41 | +import pathlib |
41 | 42 | import platform |
42 | 43 | import re |
43 | 44 | import subprocess |
@@ -472,18 +473,30 @@ def model( |
472 | 473 | # set variables |
473 | 474 | self._model_name = name # Model class name |
474 | 475 | self._libraries = libraries # may be needed if model is derived from other model |
475 | | - if file is not None: |
476 | | - file_name = self._getconn.omcpath(file).resolve() |
477 | | - else: |
478 | | - file_name = None |
479 | | - self._file_name = file_name # Model file/package name |
480 | 476 | self._variable_filter = variable_filter |
481 | 477 |
|
482 | | - if self._file_name is not None and not self._file_name.is_file(): # if file does not exist |
483 | | - raise IOError(f"{self._file_name} does not exist!") |
484 | | - |
485 | 478 | if self._libraries: |
486 | 479 | self._loadLibrary(libraries=self._libraries) |
| 480 | + |
| 481 | + self._file_name = None |
| 482 | + if file is not None: |
| 483 | + file_path = pathlib.Path(file) |
| 484 | + # special handling for OMCProcessLocal - consider a relative path |
| 485 | + if isinstance(self._getconn.omc_process, OMCProcessLocal) and not file_path.is_absolute(): |
| 486 | + file_path = pathlib.Path.cwd() / file_path |
| 487 | + if not file_path.is_file(): |
| 488 | + raise IOError(f"Model file {file_path} does not exist!") |
| 489 | + |
| 490 | + self._file_name = self.getWorkDirectory() / file_path.name |
| 491 | + if (isinstance(self._getconn.omc_process, OMCProcessLocal) |
| 492 | + and file_path.as_posix() == self._file_name.as_posix()): |
| 493 | + pass |
| 494 | + elif self._file_name.is_file(): |
| 495 | + raise IOError(f"Simulation model file {self._file_name} exist - not overwriting!") |
| 496 | + else: |
| 497 | + content = file_path.read_text(encoding='utf-8') |
| 498 | + self._file_name.write_text(content) |
| 499 | + |
487 | 500 | if self._file_name is not None: |
488 | 501 | self._loadFile(fileName=self._file_name) |
489 | 502 |
|
|
0 commit comments