17 from colours
import warning
22 for line
in open(settings.partdictpath):
24 if '<DICTIONARY>' in line:
28 partdict[line.split()[1]] = line.split()[0]
35 def inlist(partA, listA):
36 if isinstance(listA, list):
40 if isinstance(part, list):
41 if inlist(partA, part):
47 def convertToList(stringA):
48 stringA = stringA.replace(
'(',
' ( ')
49 stringA = stringA.replace(
')',
' ) ')
50 stringA = stringA.replace(
']',
' ] ')
51 stringA = stringA.replace(
'[',
' [ ')
52 stringA = stringA.replace(
'}',
' } ')
53 stringA = stringA.replace(
'{',
' { ')
54 list_base = stringA.split()
55 list_base = cleanList(
'{}', list_base)
56 list_base = cleanList(
'[]', list_base)
57 list_base = cleanList(
'()', list_base)
58 while len(list_base) == 1:
59 list_base = list_base[0]
60 list_base = postProcess(list_base)
64 def postProcess(list_base):
65 if not isinstance(list_base, list):
66 warning(
'Error building descriptor, not a list')
68 while i < len(list_base):
69 if isinstance(list_base[i], list):
70 if len(list_base[i]) == 1:
72 if isinstance(list_base[i - 1], str):
73 if list_base[i][0] ==
'os' or list_base[i][0] ==
'nos':
74 list_base[i - 1] = list_base[i - 1] +
'[' \
75 + list_base[i][0] +
']'
79 list_base[i - 1] = list_base[i - 1] +
'(' \
80 + list_base[i][0] +
')'
84 list_base[i] = list_base[i][0]
85 warning(
"You have a lone particle enclosed in '()' or some such stuff: " + list_base[i])
87 list_base[i] =
'(' + list_base[i][0] +
')'
89 list_base[i] = postProcess(list_base[i])
94 def cleanList(stringA, list_base):
98 while inlist(tag1, list_base):
100 for i
in range(len(list_base)):
101 if isinstance(list_base[i], list):
102 list_base[i] = cleanList(stringA, list_base[i])
103 if tag1 == list_base[i]:
105 if tag2 == list_base[i]:
106 newlist = list_base[start_index + 1:i]
107 list_base = list_base[:start_index] + [newlist] + list_base[i + 1:]
114 def convertPart(partA):
115 if partA
in partdict:
116 return partdict[partA]
118 if partA
not in [partdict[x]
for x
in partdict]
and not partA.lower() ==
'cc' and not partA ==
'->':
124 def compareList(listA, listB):
125 while not (listA == []
and listB == []):
131 if comparePart(partA, partB):
143 def comparePart(partA, partB):
144 if isinstance(partA, list)
and isinstance(partB, list):
145 return compareList(partA, partB)
146 elif not isinstance(partA, list)
and not isinstance(partB, list):
147 if convertPart(partA) == convertPart(partB):