|
38 | 38 | import numbers |
39 | 39 | import numpy as np |
40 | 40 | import os |
| 41 | +import pathlib |
41 | 42 | import textwrap |
42 | 43 | from typing import Optional, Any |
43 | 44 | import warnings |
@@ -428,18 +429,30 @@ def model( |
428 | 429 | # set variables |
429 | 430 | self._model_name = name # Model class name |
430 | 431 | self._libraries = libraries # may be needed if model is derived from other model |
431 | | - if file is not None: |
432 | | - file_name = self._getconn.omcpath(file).resolve() |
433 | | - else: |
434 | | - file_name = None |
435 | | - self._file_name = file_name # Model file/package name |
436 | 432 | self._variable_filter = variable_filter |
437 | 433 |
|
438 | | - if self._file_name is not None and not self._file_name.is_file(): # if file does not exist |
439 | | - raise IOError(f"{self._file_name} does not exist!") |
440 | | - |
441 | 434 | if self._libraries: |
442 | 435 | self._loadLibrary(libraries=self._libraries) |
| 436 | + |
| 437 | + self._file_name = None |
| 438 | + if file is not None: |
| 439 | + file_path = pathlib.Path(file) |
| 440 | + # special handling for OMCProcessLocal - consider a relative path |
| 441 | + if isinstance(self._getconn.omc_process, OMCProcessLocal) and not file_path.is_absolute(): |
| 442 | + file_path = pathlib.Path.cwd() / file_path |
| 443 | + if not file_path.is_file(): |
| 444 | + raise IOError(f"Model file {file_path} does not exist!") |
| 445 | + |
| 446 | + self._file_name = self.getWorkDirectory() / file_path.name |
| 447 | + if (isinstance(self._getconn.omc_process, OMCProcessLocal) |
| 448 | + and file_path.as_posix() == self._file_name.as_posix()): |
| 449 | + pass |
| 450 | + elif self._file_name.is_file(): |
| 451 | + raise IOError(f"Simulation model file {self._file_name} exist - not overwriting!") |
| 452 | + else: |
| 453 | + content = file_path.read_text(encoding='utf-8') |
| 454 | + self._file_name.write_text(content) |
| 455 | + |
443 | 456 | if self._file_name is not None: |
444 | 457 | self._loadFile(fileName=self._file_name) |
445 | 458 |
|
|
0 commit comments