/
RDMFieldDictionary.py
124 lines (104 loc) · 4.64 KB
/
RDMFieldDictionary.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class RDMFieldDictionary:
_dict = {}
_enum = {}
def __init__(self, rdmFieldDictFile, enumtypeFile):
self.rdmFieldDictFile = rdmFieldDictFile
self.enumtypeFile = enumtypeFile
self._loadRDMFieldDictionary()
self._loadEnumType()
def GetExpanedEnumString(self, name, enumid):
if name in self._dict.keys():
if(self._dict[name]["enum"]==None):
return None
if enumid in self._enum[self._dict[name]["enum"]].keys():
return self._enum[self._dict[name]["enum"]][enumid]["str"]
else:
return None
else:
return None
def GetFieldByName(self, name):
if name in self._dict.keys():
return self._dict[name]
else:
return None
def _loadEnumType(self):
fieldList = []
enumList={}
file1 = open(self.enumtypeFile, 'r')
while True:
line = file1.readline()
if not line:
break
if line.startswith("!"):
continue
if line.startswith(" ") == False:
if enumList != {}:
self._enum[fieldList[0]] = enumList
enumList = {}
for name in fieldList:
self._dict[name]["enum"] = fieldList[0]
fieldList = []
fieldList.append(line.split()[0])
else:
enum_id = line.lstrip().split()[0]
if(line.lstrip().split()[1].startswith("#")):
first_hash = line.find("#")
second_hash = line.find("#",first_hash+1)+1
enum_expand = line[first_hash:second_hash]
enum_description = line[second_hash:].lstrip()
#print("'",enum_expand,"'", enum_description)
else:
first_doublequote = line.find("\"")
second_doublequote = line.find("\"",first_doublequote+1)
enum_expand = line[first_doublequote+1:second_doublequote].strip()
enum_description = line[second_doublequote+1:].lstrip()
#print("'",enum_expand,"'", enum_description)
enumList[int(enum_id)] = {"enum": enum_id,
"str": enum_expand,
"description": enum_description}
#first_dquote = line.find("\"")
#print(enumid)
#start_offset = len(field_name)
#first_dquote = line.find("\"")
#field_description = line[start_offset:].lstrip().split("\"")[1]
#start_offset = line.find("\"",line.find("\"")+1)+1
#sub_line = line[start_offset:]
#sub_str = sub_line.lstrip().split()
file1.close()
def _loadRDMFieldDictionary(self):
file1 = open(self.rdmFieldDictFile, 'r')
while True:
line = file1.readline()
if not line:
break
if line.startswith("!"):
continue
field_name = line.split()[0]
start_offset = len(field_name)
first_dquote = line.find("\"")
field_description = line[start_offset:].lstrip().split("\"")[1]
start_offset = line.find("\"",line.find("\"")+1)+1
sub_line = line[start_offset:]
sub_str = sub_line.lstrip().split()
field_id = sub_str[0]
ripple_to = sub_str[1]
field_type = sub_str[2]
if field_type == "ENUMERATED":
field_length = sub_str[3]+":"+sub_str[5]
rwf_type = sub_str[7]
rwf_length = sub_str[8]
else:
field_length = sub_str[3]
rwf_type = sub_str[4]
rwf_length = sub_str[5]
self._dict[field_name] = {"name":field_name,
"decscription": field_description,
"id": field_id,
"ripple": ripple_to,
"type": field_type,
"length": field_length,
"rwftype": rwf_type,
"rwflength": rwf_length,
"enum": None
}
file1.close()