Mercurial > traipse_dev
annotate orpg/plugindb.py @ 226:b29454610f36 beta
Traipse Beta 'OpenRPG' {100503-00}
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 (Patch-2)
Moved to Stable!
New Features:
New Namespace method with two new syntaxes
New Namespace Internal is context sensitive, always!
New Namespace External is 'as narrow as you make it'
New Namespace FutureCheck helps ensure you don't receive an incorrect node
New Namespace 2.0 documentation in the User Manual
New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @!
New Mini Library with minis from Devin Knight
New PluginDB access for URL2Link plugin
New to Forms, they now show their content in Design Mode
New to Update Manager, checks Repo for updates on software start
New to Mini Lib node, change title in design mode
New to Game Tree, never lose a node, appends a number to the end of corrupted trees
New to Server GUI, Traipse Suite's Debug Console
New Warhammer PC Sheet
Updates:
Update to White Board layer, uses a pencil image for color button
Update to Grid Layer, uses a grid image for color button
Update to Chat Window, size of drop down menus
Update to default lobby message
Update to template Text node
Update to 4e PC Sheet node
Update to how display names are acquired
Update to Server, added some 'Pious' technology
Update to features node
Fixes:
Fix to Server GUI startup errors
Fix to Server GUI Rooms tab updating
Fix to Chat and Settings if non existant die roller is picked
Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated
Fix to Alias Lib's Export to Tree, Open, Save features
Fix to alias node, now works properly
Fix to Splitter node, minor GUI cleanup
Fix to Backgrounds not loading through remote loader
Fix to Node name errors
Fix to rolling dice in chat Whispers
Fix to Splitters Sizing issues
Fix to URL2Link plugin, modified regex compilation should remove memory leak
Fix to mapy.py, a roll back due to zoomed grid issues
Fix to whiteboard_handler, Circles work by you clicking the center of the circle
Fix to Servers parse_incoming_dom which was outdated and did not respect XML
Fix to a broken link in the server welcome message
Fix to InterParse and logger requiring traceback
Fix to Update Manager Status Bar
Fix to failed image and erroneous pop up
Fix to Mini Lib node that was preventing use
Fix to plugins that parce dice but did not call InterParse
Fix to nodes for name changing by double click
Fix to Game Tree, node ordering on drag and drop corrected
Fix to Game Tree, corrupted error message was not showing
Fix to Update Manager, checks for internet connection
Fix to Update Manager, Auto Update corrections
Fix to Server GUI's broadcast, room, player messaging
author | sirebral |
---|---|
date | Mon, 03 May 2010 03:29:14 -0500 |
parents | d263c8ff4d7c |
children |
rev | line source |
---|---|
135 | 1 from __future__ import with_statement |
2 | |
66 | 3 from orpg.dirpath import dir_struct |
135 | 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 |
135 | 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 |
135 | 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) |
135 | 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 |
135 | 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) |
135 | 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 = [] |
140 | 58 for litem in parent.find('list').findall('lobject'): |
135 | 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 if plugin is None or plugin.find(listname) is None: | |
71 msg = ["plugindb: no value has been stored for", listname, "in", | |
72 plugname, "so the default has been returned"] | |
73 logger.info(' '.join(msg), verbose) | |
74 return defaultval | |
75 | |
76 retlist = self.FetchList(plugin.find(listname)) | |
77 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
|
78 return retlist |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
79 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
80 def BuildList(self, val): |
135 | 81 list_el = Element('list') |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
82 for item in val: |
135 | 83 i = Element('lobject') |
84 if isinstance(item, bool): | |
85 i.set('type', 'bool') | |
86 i.text = str(item) | |
87 elif isinstance(item, int):#it's an int | |
88 i.set('type', 'int') | |
89 i.text = str(item) | |
90 elif isinstance(item, float):#it's a float | |
91 i.set('type', 'float') | |
92 i.text = str(item) | |
93 elif isinstance(item, (list, tuple)):#it's a list | |
94 i.set('type', 'list') | |
95 i.append(self.BuildList(item)) | |
96 elif isinstance(item, dict):#it's a dictionary | |
97 i.set('type', 'dict') | |
98 i.append(self.BuildDict(item)) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
99 else: |
135 | 100 i.set('type', 'str') |
101 i.text = self.safe(item) | |
102 list_el.append(i) | |
103 return list_el | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
104 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
105 def SetList(self, plugname, listname, val): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
106 listname = self.safe(listname) |
135 | 107 plugin = self.etree.find(plugname) |
108 if plugin is None: | |
109 plugin = Element(plugname) | |
110 self.etree.getroot().append(plugin) | |
111 list_el = plugin.find(listname) | |
112 if list_el is None: | |
113 list_el = Element(listname) | |
114 list_el.set('type', 'list') | |
115 plugin.append(list_el) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
116 else: |
135 | 117 list_el.remove(list_el.find('list')) |
118 list_el.append(self.BuildList(val)) | |
119 self.SaveDoc() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
120 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
121 def BuildDict(self, val): |
135 | 122 dict_el = Element('dict') |
123 for key, item in val.iteritems(): | |
124 i = Element('dobject') | |
125 | |
126 if isinstance(item, bool): | |
127 i.set('type', 'bool') | |
128 i.set('name', self.safe(key)) | |
129 i.text = str(item) | |
130 elif isinstance(item, int):#it's an int | |
131 i.set('type', 'int') | |
132 i.set('name', self.safe(key)) | |
133 i.text = str(item) | |
134 elif isinstance(item, float):#it's a float | |
135 i.set('type', 'float') | |
136 i.set('name', self.safe(key)) | |
137 i.text = str(item) | |
138 elif isinstance(item, (list, tuple)):#it's a list | |
139 i.set('type', 'list') | |
140 i.set('name', self.safe(key)) | |
141 i.append(self.BuildList(item)) | |
142 elif isinstance(item, dict):#it's a dictionary | |
143 i.set('type', 'dict') | |
144 i.set('name', self.safe(key)) | |
145 i.append(self.BuildDict(item)) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
146 else: |
135 | 147 i.set('type', 'str') |
148 i.set('name', self.safe(key)) | |
149 i.text = self.safe(item) | |
150 dict_el.append(i) | |
151 return dict_el | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
152 |
135 | 153 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
|
154 dictname = self.safe(dictname) |
135 | 155 plugin = self.etree.find(plugname) |
156 if plugin is None: | |
157 plugin = Element(plugname) | |
158 self.etree.getroot().append(plugin) | |
159 dict_el = plugin.find(dictname) | |
160 if dict_el is None: | |
161 dict_el = Element(dictname) | |
162 dict_el.set('type', 'dict') | |
163 plugin.append(dict_el) | |
164 | 164 else: |
165 refs = dict_el.findall('dict') | |
166 keys = val.keys() | |
167 for r in refs: | |
168 if r.find('dobject').get('name') in keys: | |
169 logger.debug('Duplicate Dictionary Reference', True); return | |
135 | 170 dict_el.append(self.BuildDict(val)) |
171 self.SaveDoc() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
172 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
173 def FetchDict(self, parent): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
174 retdict = {} |
164 | 175 for ditem in parent.find('dict').findall('dobject'): |
135 | 176 key = self.normal(ditem.get('name')) |
177 if ditem.get('type') == 'int': value = int(ditem.text) | |
178 elif ditem.get('type') == 'bool': value = ditem.text == 'True' | |
179 elif ditem.get('type') == 'float': value = float(ditem.text) | |
180 elif ditem.get('type') == 'list': value = self.FetchList(ditem) | |
181 elif ditem.get('type') == 'dict': value = self.FetchDict(ditem) | |
164 | 182 else: value = str(self.normal(ditem.text)) |
135 | 183 retdict[key] = value |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
184 return retdict |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
185 |
135 | 186 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
|
187 dictname = self.safe(dictname) |
135 | 188 plugin = self.etree.find(plugname) |
189 if plugin is None or plugin.find(dictname) is None: | |
190 msg = ["plugindb: no value has been stored for", dictname, "in", | |
191 plugname, "so the default has been returned"] | |
192 logger.info(' '.join(msg), verbose) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
193 return defaultval |
135 | 194 retdict = self.FetchDict(plugin.find(dictname)) |
195 logger.debug("successfully found dict value", verbose) | |
196 return retdict | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
197 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
198 def safe(self, string): |
135 | 199 return string.replace("<", "$$lt$$").replace(">", "$$gt$$")\ |
200 .replace("&","$$amp$$").replace('"',"$$quote$$") | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
201 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
202 def normal(self, string): |
135 | 203 return string.replace("$$lt$$", "<").replace("$$gt$$", ">")\ |
204 .replace("$$amp$$","&").replace("$$quote$$",'"') | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
205 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
206 def SaveDoc(self): |
135 | 207 with open(self.filename, "w") as f: |
208 self.etree.write(f) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
209 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
210 def LoadDoc(self): |
135 | 211 with open(self.filename) as f: |
212 self.etree.parse(f) | |
213 | |
214 plugindb = PluginDB() |