forked from HydrologicEngineeringCenter/hec-dss-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsspath.py
45 lines (34 loc) · 1.39 KB
/
dsspath.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from record_type import RecordType
class DssPath:
"""manage parts of DSS path /A/B/C/D/E/F/
condenses D part for timeseries records
"""
_timeSeriesFamily = [ RecordType.IrregularTimeSeries, RecordType.RegularTimeSeries, RecordType.RegularTimeSeriesProfile ]
def __init__(self,path,recType):
"""
path is raw dss pathname
recType is a RecordType , such as RecordType.RegularTimeSeries
"""
if path[0]!='/' or path[-1]!= '/':
raise Exception("Invalid DSS Path: '"+path+"'")
path = path[1:-1] # remove beginning and ending '/'
self.rawPath= path
split_parts = path.split('/')
if len(split_parts) >= 6:
self.A, self.B, self.C, self.D, self.E, self.F = split_parts[:6]
self.recType = recType
def __str__(self):
return "/"+self.A+"/"+self.B+"/"+self.C+"/"+self.D+"/"+self.E+"/"+self.F+"/"
def pathWithoutDate(self):
s = "/"+self.A+"/"+self.B+"/"+self.C+"//"+self.E+"/"+self.F+"/"
rval = DssPath(s,self.recType)
return rval
def isTimeSeries(self):
return self.recType in DssPath._timeSeriesFamily
def print(self):
print("a:"+self.path.A)
print("b:"+self.path.B)
print("c:"+self.path.C)
print("d:"+self.path.D)
print("e:"+self.path.E)
print("f:"+self.path.F)