Skip to content

Commit d240737

Browse files
allow Measurement __init__ to take pathlib.Path (#55)
1 parent 5ebc040 commit d240737

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

cuvis/Measurement.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import datetime
44
import os
55
import numpy as np
6+
from pathlib import Path
67

78
from ._cuvis_il import cuvis_il
89
from .cuvis_aux import SDKException, SessionData, Capabilities, MeasurementFlags, SensorInfo, GPSData
@@ -31,22 +32,26 @@ class Measurement(object):
3132
session_info: SessionData
3233
frame_id: int
3334

34-
def __init__(self, base: Union[int, str]):
35+
def __init__(self, base: Union[int, str, Path]):
3536
self._handle = None
3637
self._session = None
3738

3839
if isinstance(base, int):
3940
self._handle = base
40-
elif isinstance(base, str) and os.path.exists(base):
41+
elif isinstance(base, str) or isinstance(base, Path):
42+
base = Path(base)
43+
if not base.exists():
44+
raise FileNotFoundError(
45+
'Could not open Measurement. File does not exists.')
46+
4147
_ptr = cuvis_il.new_p_int()
42-
if cuvis_il.status_ok != cuvis_il.cuvis_measurement_load(base,
48+
if cuvis_il.status_ok != cuvis_il.cuvis_measurement_load(str(base),
4349
_ptr):
4450
raise SDKException()
4551
self._handle = cuvis_il.p_int_value(_ptr)
4652
else:
47-
raise SDKException(
48-
"Could not open Measurement! Either handle not"
49-
" available or file not found!")
53+
raise ValueError(
54+
"Could not open Measurement! Unknown Input")
5055
self.refresh()
5156
pass
5257

cuvis/SessionFile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, base: Union[Path, str]):
2323
raise SDKException()
2424
self._handle = cuvis_il.p_int_value(_ptr)
2525
else:
26-
raise SDKException(
26+
raise FileNotFoundError(
2727
"Could not open SessionFile File! File not found!")
2828

2929
def get_measurement(self, frameNo: int = 0, itemtype: SessionItemType = SessionItemType.no_gaps) -> Optional[Measurement]:

0 commit comments

Comments
 (0)