Skip to content

Commit 08fe595

Browse files
committed
??? some cleanup
1 parent d02ed07 commit 08fe595

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

OMPython/OMCSession.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
429429
if not self._session.sendExpression(f'mkdir("{self.as_posix()}")'):
430430
raise OMCSessionException(f"Error on directory creation for {self.as_posix()}!")
431431

432-
def cwd(self) -> OMPathABC:
432+
def cwd(self) -> OMPathBase:
433433
"""
434434
Returns the current working directory as an OMPathBase object.
435435
"""
@@ -444,7 +444,7 @@ def unlink(self, missing_ok: bool = False) -> None:
444444
if not res and not missing_ok:
445445
raise FileNotFoundError(f"Cannot delete file {self.as_posix()} - it does not exists!")
446446

447-
def resolve(self, strict: bool = False) -> OMPathABC:
447+
def resolve(self, strict: bool = False) -> OMPathBase:
448448
"""
449449
Resolve the path to an absolute path. This is done based on available OMC functions.
450450
"""
@@ -878,6 +878,7 @@ def __del__(self):
878878
self._omc_process.kill()
879879
self._omc_process.wait()
880880
finally:
881+
881882
self._omc_process = None
882883

883884
@staticmethod
@@ -1878,6 +1879,9 @@ def write_text(self, data: str):
18781879
"""
18791880
Write text data to the file represented by this path.
18801881
"""
1882+
if not isinstance(data, str):
1883+
raise TypeError(f"data must be str, not {data.__class__.__name__}")
1884+
18811885
return self._path().write_text(data=data, encoding='utf-8')
18821886

18831887
def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
@@ -1960,7 +1964,7 @@ def is_dir(self) -> bool:
19601964
except subprocess.CalledProcessError:
19611965
return False
19621966

1963-
def is_absolute(self):
1967+
def is_absolute(self) -> bool:
19641968
"""
19651969
Check if the path is an absolute path.
19661970
"""
@@ -1986,20 +1990,23 @@ def read_text(self) -> str:
19861990
return result.stdout.decode('utf-8')
19871991
raise FileNotFoundError(f"Cannot read file: {self.as_posix()}")
19881992

1989-
def write_text(self, data: str):
1993+
def write_text(self, data: str) -> int:
19901994
"""
19911995
Write text data to the file represented by this path.
19921996
"""
1997+
if not isinstance(data, str):
1998+
raise TypeError(f"data must be str, not {data.__class__.__name__}")
1999+
19932000
data_escape = self._session.escape_str(data)
19942001

19952002
cmdl = self.get_session().get_cmd_prefix()
19962003
cmdl += ['bash', '-c', f'printf %s "{data_escape}" > "{self.as_posix()}"']
19972004

19982005
try:
19992006
subprocess.run(cmdl, check=True)
2000-
return True
2007+
return len(data)
20012008
except subprocess.CalledProcessError:
2002-
return False
2009+
raise IOError(f"Error writing data to file {self.as_posix()}!")
20032010

20042011
def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
20052012
"""

0 commit comments

Comments
 (0)