comparison orpg/plugindb.py @ 23:551cd440acce traipse_dev

Final Dev build of the Day. Should reduce RAM usage more.
author sirebral
date Sat, 25 Jul 2009 21:05:18 -0500
parents 4385a7d0efd1
children c54768cffbd4
comparison
equal deleted inserted replaced
22:88cea66228d6 23:551cd440acce
14 for plugin in self.xml_dom: 14 for plugin in self.xml_dom:
15 if plugname == plugin._name: 15 if plugname == plugin._name:
16 for child in plugin._dir: 16 for child in plugin._dir:
17 if child._name == strname: 17 if child._name == strname:
18 #str() on this to make sure it's ASCII, not unicode, since orpg can't handle unicode. 18 #str() on this to make sure it's ASCII, not unicode, since orpg can't handle unicode.
19 if verbose: 19 if verbose: print "successfully found the value"
20 print "successfully found the value" 20 if len(child): return str( self.normal(child[0]) )
21 if len(child): 21 else: return ""
22 return str( self.normal(child[0]) )
23 else:
24 return ""
25 else: 22 else:
26 if verbose: 23 if verbose:
27 print "plugindb: no value has been stored for " + strname + " in " + plugname + " so the default has been returned" 24 print "plugindb: no value has been stored for " + strname + " in " + plugname + " so the default has been returned"
28 return defaultval 25 return defaultval
29 26
41 self.SaveDoc() 38 self.SaveDoc()
42 return "added plugin" 39 return "added plugin"
43 40
44 def FetchList(self, parent): 41 def FetchList(self, parent):
45 retlist = [] 42 retlist = []
46 if not len(parent): 43 if not len(parent): return []
47 return []
48 for litem in parent[0]._dir: 44 for litem in parent[0]._dir:
49 if len(litem): 45 if len(litem):
50 if litem._attrs["type"] == "int": 46 if litem._attrs["type"] == "int": retlist += [int(litem[0])]
51 retlist += [int(litem[0])] 47 elif litem._attrs["type"] == "long": retlist += [long(litem[0])]
52 elif litem._attrs["type"] == "long": 48 elif litem._attrs["type"] == "float": retlist += [float(litem[0])]
53 retlist += [long(litem[0])] 49 elif litem._attrs["type"] == "list": retlist += [self.FetchList(litem)]
54 elif litem._attrs["type"] == "float": 50 elif litem._attrs["type"] == "dict": retlist += [self.FetchDict(litem)]
55 retlist += [float(litem[0])] 51 else: retlist += [str( self.normal(litem[0]) )]
56 elif litem._attrs["type"] == "list": 52 else: retlist += [""]
57 retlist += [self.FetchList(litem)]
58 elif litem._attrs["type"] == "dict":
59 retlist += [self.FetchDict(litem)]
60 else:
61 retlist += [str( self.normal(litem[0]) )]
62 else:
63 retlist += [""]
64 return retlist 53 return retlist
65 54
66 def GetList(self, plugname, listname, defaultval, verbose=0): 55 def GetList(self, plugname, listname, defaultval, verbose=0):
67 listname = self.safe(listname) 56 listname = self.safe(listname)
68 for plugin in self.xml_dom: 57 for plugin in self.xml_dom:
69 if plugname == plugin._name: 58 if plugname == plugin._name:
70 for child in plugin._dir: 59 for child in plugin._dir:
71 if child._name == listname and child._attrs["type"] == "list": 60 if child._name == listname and child._attrs["type"] == "list":
72 retlist = self.FetchList(child) 61 retlist = self.FetchList(child)
73 if verbose: 62 if verbose: print "successfully found the value"
74 print "successfully found the value"
75 return retlist 63 return retlist
76 else: 64 else:
77 if verbose: 65 if verbose:
78 print "plugindb: no value has been stored for " + listname + " in " + plugname + " so the default has been returned" 66 print "plugindb: no value has been stored for " + listname + " in " + plugname + " so the default has been returned"
79 return defaultval 67 return defaultval
155 if not len(parent): 143 if not len(parent):
156 return {} 144 return {}
157 for ditem in parent[0]._dir: 145 for ditem in parent[0]._dir:
158 if len(ditem): 146 if len(ditem):
159 ditem._attrs["name"] = self.normal(ditem._attrs["name"]) 147 ditem._attrs["name"] = self.normal(ditem._attrs["name"])
160 if ditem._attrs["type"] == "int": 148 if ditem._attrs["type"] == "int": retdict[ditem._attrs["name"]] = int(ditem[0])
161 retdict[ditem._attrs["name"]] = int(ditem[0]) 149 elif ditem._attrs["type"] == "long": retdict[ditem._attrs["name"]] = long(ditem[0])
162 elif ditem._attrs["type"] == "long": 150 elif ditem._attrs["type"] == "float": retdict[ditem._attrs["name"]] = float(ditem[0])
163 retdict[ditem._attrs["name"]] = long(ditem[0]) 151 elif ditem._attrs["type"] == "list": retdict[ditem._attrs["name"]] = self.FetchList(ditem)
164 elif ditem._attrs["type"] == "float": 152 elif ditem._attrs["type"] == "dict": retdict[ditem._attrs["name"]] = self.FetchDict(ditem)
165 retdict[ditem._attrs["name"]] = float(ditem[0]) 153 else: retdict[ditem._attrs["name"]] = str( self.normal(ditem[0]) )
166 elif ditem._attrs["type"] == "list": 154 else: retdict[ditem._attrs["name"]] = ""
167 retdict[ditem._attrs["name"]] = self.FetchList(ditem)
168 elif ditem._attrs["type"] == "dict":
169 retdict[ditem._attrs["name"]] = self.FetchDict(ditem)
170 else:
171 retdict[ditem._attrs["name"]] = str( self.normal(ditem[0]) )
172 else:
173 retdict[ditem._attrs["name"]] = ""
174 return retdict 155 return retdict
175 156
176 def GetDict(self, plugname, dictname, defaultval, verbose=0): 157 def GetDict(self, plugname, dictname, defaultval, verbose=0):
177 dictname = self.safe(dictname) 158 dictname = self.safe(dictname)
178 for plugin in self.xml_dom: 159 for plugin in self.xml_dom:
179 if plugname == plugin._name: 160 if plugname == plugin._name:
180 for child in plugin._dir: 161 for child in plugin._dir:
181 if child._name == dictname and child._attrs["type"] == "dict": 162 if child._name == dictname and child._attrs["type"] == "dict": return self.FetchDict(child)
182 return self.FetchDict(child)
183 else: 163 else:
184 if verbose: 164 if verbose:
185 print "plugindb: no value has been stored for " + dictname + " in " + plugname + " so the default has been returned" 165 print "plugindb: no value has been stored for " + dictname + " in " + plugname + " so the default has been returned"
186 return defaultval 166 return defaultval
187 167