Mercurial > traipse_dev
annotate orpg/plugindb.py @ 130:d54e1328dbb1 alpha
Traipse Alpha 'OpenRPG' {091003-02}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for
developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds
fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of
the user.
Update Summary (Cleaning up for Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
**Pretty important update that can help remove thousands of dead children from your gametree.
**Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now.
Check your gametree and look for dead children!!
Dead Node Children, not that's a
O O
-v-v- Happy Halloween!
author | sirebral |
---|---|
date | Tue, 03 Nov 2009 21:06:03 -0600 |
parents | 36919b8a3ef9 |
children | 8e07c1a2c69b |
rev | line source |
---|---|
122 | 1 from __future__ import with_statement |
2 | |
66 | 3 from orpg.dirpath import dir_struct |
122 | 4 from orpg.tools.validate import validate |
5 from orpg.tools.orpg_log import logger | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
6 |
122 | 7 from xml.etree.ElementTree import ElementTree, Element, parse |
8 from xml.etree.ElementPath import find | |
9 | |
10 class PluginDB(object): | |
11 etree = ElementTree() | |
12 filename = dir_struct["user"] + "plugindb.xml" | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
13 |
122 | 14 def __new__(cls, *args, **kwargs): |
15 it = cls.__dict__.get("__it__") | |
16 if it is not None: | |
17 return it | |
18 cls.__it__ = it = object.__new__(cls) | |
19 it._init() | |
20 return it | |
21 | |
22 def _init(self): | |
23 validate.config_file("plugindb.xml", "default_plugindb.xml") | |
24 self.LoadDoc() | |
25 | |
26 def GetString(self, plugname, strname, defaultval="", verbose=False): | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
27 strname = self.safe(strname) |
122 | 28 |
29 plugin = self.etree.find(plugname) | |
30 if plugin is None or plugin.find(strname) is None: | |
31 msg = ["plugindb: no value has been stored for", strname, "in", | |
32 plugname, "so the default has been returned"] | |
33 logger.info(' '.join(msg), verbose) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
34 return defaultval |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
35 |
122 | 36 logger.debug("successfully found the str value", verbose) |
37 return self.normal(plugin.find(strname).text) | |
38 | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
39 def SetString(self, plugname, strname, val): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
40 val = self.safe(val) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
41 strname = self.safe(strname) |
122 | 42 |
43 plugin = self.etree.find(plugname) | |
44 if plugin is None: | |
45 plugin = Element(plugname) | |
46 self.etree.getroot().append(plugin) | |
47 | |
48 str_el = plugin.find(strname) | |
49 if str_el is None: | |
50 str_el = Element(strname) | |
51 str_el.set('type', 'str') | |
52 plugin.append(str_el) | |
53 str_el.text = val | |
54 self.SaveDoc() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
55 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
56 def FetchList(self, parent): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
57 retlist = [] |
122 | 58 for litem in parent.findall('lobject'): |
59 if litem.get('type') == 'int': retlist.append(int(litem.text)) | |
60 if litem.get('type') == 'bool': retlist.append(litem.text == 'True') | |
61 elif litem.get('type') == 'float': retlist.append(float(litem.text)) | |
62 elif litem.get('type') == 'list': retlist.append(self.FetchList(litem)) | |
63 elif litem.get('type') == 'dict': retlist.append(self.FetchDict(litem)) | |
64 else: retlist.append(str(self.normal(litem.text))) | |
65 return retlist | |
66 | |
67 def GetList(self, plugname, listname, defaultval=list(), verbose=False): | |
68 listname = self.safe(listname) | |
69 plugin = self.etree.find(plugname) | |
70 | |
71 if plugin is None or plugin.find(listname) is None: | |
72 msg = ["plugindb: no value has been stored for", listname, "in", | |
73 plugname, "so the default has been returned"] | |
74 logger.info(' '.join(msg), verbose) | |
75 return defaultval | |
76 | |
77 retlist = self.FetchList(plugin.find(listname)) | |
78 logger.debug("successfully found the list value", verbose) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
79 return retlist |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
80 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
81 def BuildList(self, val): |
122 | 82 list_el = Element('list') |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
83 for item in val: |
122 | 84 i = Element('lobject') |
85 if isinstance(item, bool): | |
86 i.set('type', 'bool') | |
87 i.text = str(item) | |
88 elif isinstance(item, int):#it's an int | |
89 i.set('type', 'int') | |
90 i.text = str(item) | |
91 elif isinstance(item, float):#it's a float | |
92 i.set('type', 'float') | |
93 i.text = str(item) | |
94 elif isinstance(item, (list, tuple)):#it's a list | |
95 i.set('type', 'list') | |
96 i.append(self.BuildList(item)) | |
97 elif isinstance(item, dict):#it's a dictionary | |
98 i.set('type', 'dict') | |
99 i.append(self.BuildDict(item)) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
100 else: |
122 | 101 i.set('type', 'str') |
102 i.text = self.safe(item) | |
103 list_el.append(i) | |
104 return list_el | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
105 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
106 def SetList(self, plugname, listname, val): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
107 listname = self.safe(listname) |
122 | 108 plugin = self.etree.find(plugname) |
109 if plugin is None: | |
110 plugin = Element(plugname) | |
111 self.etree.getroot().append(plugin) | |
112 list_el = plugin.find(listname) | |
113 if list_el is None: | |
114 list_el = Element(listname) | |
115 list_el.set('type', 'list') | |
116 plugin.append(list_el) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
117 else: |
122 | 118 list_el.remove(list_el.find('list')) |
119 list_el.append(self.BuildList(val)) | |
120 self.SaveDoc() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
121 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
122 def BuildDict(self, val): |
122 | 123 dict_el = Element('dict') |
124 for key, item in val.iteritems(): | |
125 i = Element('dobject') | |
126 | |
127 if isinstance(item, bool): | |
128 i.set('type', 'bool') | |
129 i.set('name', self.safe(key)) | |
130 i.text = str(item) | |
131 elif isinstance(item, int):#it's an int | |
132 i.set('type', 'int') | |
133 i.set('name', self.safe(key)) | |
134 i.text = str(item) | |
135 elif isinstance(item, float):#it's a float | |
136 i.set('type', 'float') | |
137 i.set('name', self.safe(key)) | |
138 i.text = str(item) | |
139 elif isinstance(item, (list, tuple)):#it's a list | |
140 i.set('type', 'list') | |
141 i.set('name', self.safe(key)) | |
142 i.append(self.BuildList(item)) | |
143 elif isinstance(item, dict):#it's a dictionary | |
144 i.set('type', 'dict') | |
145 i.set('name', self.safe(key)) | |
146 i.append(self.BuildDict(item)) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
147 else: |
122 | 148 i.set('type', 'str') |
149 i.set('name', self.safe(key)) | |
150 i.text = self.safe(item) | |
151 dict_el.append(i) | |
152 return dict_el | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
153 |
122 | 154 def SetDict(self, plugname, dictname, val): |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
155 dictname = self.safe(dictname) |
122 | 156 plugin = self.etree.find(plugname) |
157 if plugin is None: | |
158 plugin = Element(plugname) | |
159 self.etree.getroot().append(plugin) | |
160 dict_el = plugin.find(dictname) | |
161 if dict_el is None: | |
162 dict_el = Element(dictname) | |
163 dict_el.set('type', 'dict') | |
164 plugin.append(dict_el) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
165 else: |
122 | 166 dict_el.remove(list_el.find('dict')) |
167 dict_el.append(self.BuildDict(val)) | |
168 self.SaveDoc() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
169 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
170 def FetchDict(self, parent): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
171 retdict = {} |
122 | 172 for ditem in parent.findall('dobject'): |
173 key = self.normal(ditem.get('name')) | |
174 if ditem.get('type') == 'int': value = int(ditem.text) | |
175 elif ditem.get('type') == 'bool': value = ditem.text == 'True' | |
176 elif ditem.get('type') == 'float': value = float(ditem.text) | |
177 elif ditem.get('type') == 'list': value = self.FetchList(ditem) | |
178 elif ditem.get('type') == 'dict': value = self.FetchDict(ditem) | |
179 else: value = str(self.normal(ditem[0])) | |
180 retdict[key] = value | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
181 return retdict |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
182 |
122 | 183 def GetDict(self, plugname, dictname, defaultval=dict(), verbose=False): |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
184 dictname = self.safe(dictname) |
122 | 185 plugin = self.etree.find(plugname) |
186 if plugin is None or plugin.find(dictname) is None: | |
187 msg = ["plugindb: no value has been stored for", dictname, "in", | |
188 plugname, "so the default has been returned"] | |
189 logger.info(' '.join(msg), verbose) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
190 return defaultval |
122 | 191 retdict = self.FetchDict(plugin.find(dictname)) |
192 logger.debug("successfully found dict value", verbose) | |
193 return retdict | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
194 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
195 def safe(self, string): |
122 | 196 return string.replace("<", "$$lt$$").replace(">", "$$gt$$")\ |
197 .replace("&","$$amp$$").replace('"',"$$quote$$") | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
198 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
199 def normal(self, string): |
122 | 200 return string.replace("$$lt$$", "<").replace("$$gt$$", ">")\ |
201 .replace("$$amp$$","&").replace("$$quote$$",'"') | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
202 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
203 def SaveDoc(self): |
122 | 204 with open(self.filename, "w") as f: |
205 self.etree.write(f) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
206 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
207 def LoadDoc(self): |
122 | 208 with open(self.filename) as f: |
209 self.etree.parse(f) | |
210 | |
211 plugindb = PluginDB() |