|
38 | 38 | import logging |
39 | 39 | import numbers |
40 | 40 | import os |
| 41 | +import pathlib |
41 | 42 | import queue |
42 | 43 | import textwrap |
43 | 44 | import threading |
@@ -439,18 +440,30 @@ def model( |
439 | 440 | # set variables |
440 | 441 | self._model_name = name # Model class name |
441 | 442 | self._libraries = libraries # may be needed if model is derived from other model |
442 | | - if file is not None: |
443 | | - file_name = self._getconn.omcpath(file).resolve() |
444 | | - else: |
445 | | - file_name = None |
446 | | - self._file_name = file_name # Model file/package name |
447 | 443 | self._variable_filter = variable_filter |
448 | 444 |
|
449 | | - if self._file_name is not None and not self._file_name.is_file(): # if file does not exist |
450 | | - raise IOError(f"{self._file_name} does not exist!") |
451 | | - |
452 | 445 | if self._libraries: |
453 | 446 | self._loadLibrary(libraries=self._libraries) |
| 447 | + |
| 448 | + self._file_name = None |
| 449 | + if file is not None: |
| 450 | + file_path = pathlib.Path(file) |
| 451 | + # special handling for OMCProcessLocal - consider a relative path |
| 452 | + if isinstance(self._getconn.omc_process, OMCProcessLocal) and not file_path.is_absolute(): |
| 453 | + file_path = pathlib.Path.cwd() / file_path |
| 454 | + if not file_path.is_file(): |
| 455 | + raise IOError(f"Model file {file_path} does not exist!") |
| 456 | + |
| 457 | + self._file_name = self.getWorkDirectory() / file_path.name |
| 458 | + if (isinstance(self._getconn.omc_process, OMCProcessLocal) |
| 459 | + and file_path.as_posix() == self._file_name.as_posix()): |
| 460 | + pass |
| 461 | + elif self._file_name.is_file(): |
| 462 | + raise IOError(f"Simulation model file {self._file_name} exist - not overwriting!") |
| 463 | + else: |
| 464 | + content = file_path.read_text(encoding='utf-8') |
| 465 | + self._file_name.write_text(content) |
| 466 | + |
454 | 467 | if self._file_name is not None: |
455 | 468 | self._loadFile(fileName=self._file_name) |
456 | 469 |
|
|
0 commit comments