|
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 |
@@ -446,18 +447,30 @@ def model( |
446 | 447 | # set variables |
447 | 448 | self._model_name = name # Model class name |
448 | 449 | self._libraries = libraries # may be needed if model is derived from other model |
449 | | - if file is not None: |
450 | | - file_name = self._session.omcpath(file).resolve() |
451 | | - else: |
452 | | - file_name = None |
453 | | - self._file_name = file_name # Model file/package name |
454 | 450 | self._variable_filter = variable_filter |
455 | 451 |
|
456 | | - if self._file_name is not None and not self._file_name.is_file(): # if file does not exist |
457 | | - raise IOError(f"{self._file_name} does not exist!") |
458 | | - |
459 | 452 | if self._libraries: |
460 | 453 | self._loadLibrary(libraries=self._libraries) |
| 454 | + |
| 455 | + self._file_name = None |
| 456 | + if file is not None: |
| 457 | + file_path = pathlib.Path(file) |
| 458 | + # special handling for OMCProcessLocal - consider a relative path |
| 459 | + if isinstance(self._session.omc_process, OMCProcessLocal) and not file_path.is_absolute(): |
| 460 | + file_path = pathlib.Path.cwd() / file_path |
| 461 | + if not file_path.is_file(): |
| 462 | + raise IOError(f"Model file {file_path} does not exist!") |
| 463 | + |
| 464 | + self._file_name = self.getWorkDirectory() / file_path.name |
| 465 | + if (isinstance(self._session.omc_process, OMCProcessLocal) |
| 466 | + and file_path.as_posix() == self._file_name.as_posix()): |
| 467 | + pass |
| 468 | + elif self._file_name.is_file(): |
| 469 | + raise IOError(f"Simulation model file {self._file_name} exist - not overwriting!") |
| 470 | + else: |
| 471 | + content = file_path.read_text(encoding='utf-8') |
| 472 | + self._file_name.write_text(content) |
| 473 | + |
461 | 474 | if self._file_name is not None: |
462 | 475 | self._loadFile(fileName=self._file_name) |
463 | 476 |
|
@@ -1685,7 +1698,7 @@ def convertFmu2Mo( |
1685 | 1698 | raise ModelicaSystemError(f"Missing FMU file: {fmu_path.as_posix()}") |
1686 | 1699 |
|
1687 | 1700 | filename = self._requestApi(apiName='importFMU', entity=fmu_path.as_posix()) |
1688 | | - filepath = self._getconn.omcpath(filename) |
| 1701 | + filepath = self._session.omcpath(filename) |
1689 | 1702 |
|
1690 | 1703 | # report proper error message |
1691 | 1704 | if not filepath.is_file(): |
|
0 commit comments