annotate orpg/plugindb.py @ 135:dcf4fbe09b70 beta

Traipse Beta 'OpenRPG' {091010-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 (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!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Tue, 10 Nov 2009 14:11:28 -0600
parents c54768cffbd4
children 8e07c1a2c69b
rev   line source
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
1 from __future__ import with_statement
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
2
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 23
diff changeset
3 from orpg.dirpath import dir_struct
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
4 from orpg.tools.validate import validate
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
7 from xml.etree.ElementTree import ElementTree, Element, parse
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
8 from xml.etree.ElementPath import find
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
9
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
10 class PluginDB(object):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
11 etree = ElementTree()
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
14 def __new__(cls, *args, **kwargs):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
15 it = cls.__dict__.get("__it__")
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
16 if it is not None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
17 return it
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
18 cls.__it__ = it = object.__new__(cls)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
19 it._init()
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
20 return it
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
21
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
22 def _init(self):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
23 validate.config_file("plugindb.xml", "default_plugindb.xml")
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
24 self.LoadDoc()
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
25
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
28
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
29 plugin = self.etree.find(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
30 if plugin is None or plugin.find(strname) is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
31 msg = ["plugindb: no value has been stored for", strname, "in",
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
32 plugname, "so the default has been returned"]
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
36 logger.debug("successfully found the str value", verbose)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
37 return self.normal(plugin.find(strname).text)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
42
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
43 plugin = self.etree.find(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
44 if plugin is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
45 plugin = Element(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
46 self.etree.getroot().append(plugin)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
47
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
48 str_el = plugin.find(strname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
49 if str_el is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
50 str_el = Element(strname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
51 str_el.set('type', 'str')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
52 plugin.append(str_el)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
53 str_el.text = val
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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 = []
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
58 for litem in parent.findall('lobject'):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
59 if litem.get('type') == 'int': retlist.append(int(litem.text))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
60 if litem.get('type') == 'bool': retlist.append(litem.text == 'True')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
61 elif litem.get('type') == 'float': retlist.append(float(litem.text))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
62 elif litem.get('type') == 'list': retlist.append(self.FetchList(litem))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
63 elif litem.get('type') == 'dict': retlist.append(self.FetchDict(litem))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
64 else: retlist.append(str(self.normal(litem.text)))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
65 return retlist
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
66
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
67 def GetList(self, plugname, listname, defaultval=list(), verbose=False):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
68 listname = self.safe(listname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
69 plugin = self.etree.find(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
70
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
71 if plugin is None or plugin.find(listname) is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
72 msg = ["plugindb: no value has been stored for", listname, "in",
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
73 plugname, "so the default has been returned"]
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
74 logger.info(' '.join(msg), verbose)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
75 return defaultval
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
76
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
77 retlist = self.FetchList(plugin.find(listname))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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):
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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:
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
84 i = Element('lobject')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
85 if isinstance(item, bool):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
86 i.set('type', 'bool')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
87 i.text = str(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
88 elif isinstance(item, int):#it's an int
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
89 i.set('type', 'int')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
90 i.text = str(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
91 elif isinstance(item, float):#it's a float
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
92 i.set('type', 'float')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
93 i.text = str(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
94 elif isinstance(item, (list, tuple)):#it's a list
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
95 i.set('type', 'list')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
96 i.append(self.BuildList(item))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
97 elif isinstance(item, dict):#it's a dictionary
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
98 i.set('type', 'dict')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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:
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
101 i.set('type', 'str')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
102 i.text = self.safe(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
103 list_el.append(i)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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)
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
108 plugin = self.etree.find(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
109 if plugin is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
110 plugin = Element(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
111 self.etree.getroot().append(plugin)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
112 list_el = plugin.find(listname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
113 if list_el is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
114 list_el = Element(listname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
115 list_el.set('type', 'list')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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:
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
118 list_el.remove(list_el.find('list'))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
119 list_el.append(self.BuildList(val))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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):
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
123 dict_el = Element('dict')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
124 for key, item in val.iteritems():
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
125 i = Element('dobject')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
126
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
127 if isinstance(item, bool):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
128 i.set('type', 'bool')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
129 i.set('name', self.safe(key))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
130 i.text = str(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
131 elif isinstance(item, int):#it's an int
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
132 i.set('type', 'int')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
133 i.set('name', self.safe(key))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
134 i.text = str(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
135 elif isinstance(item, float):#it's a float
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
136 i.set('type', 'float')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
137 i.set('name', self.safe(key))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
138 i.text = str(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
139 elif isinstance(item, (list, tuple)):#it's a list
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
140 i.set('type', 'list')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
141 i.set('name', self.safe(key))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
142 i.append(self.BuildList(item))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
143 elif isinstance(item, dict):#it's a dictionary
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
144 i.set('type', 'dict')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
145 i.set('name', self.safe(key))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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:
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
148 i.set('type', 'str')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
149 i.set('name', self.safe(key))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
150 i.text = self.safe(item)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
151 dict_el.append(i)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
152 return dict_el
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
153
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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)
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
156 plugin = self.etree.find(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
157 if plugin is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
158 plugin = Element(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
159 self.etree.getroot().append(plugin)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
160 dict_el = plugin.find(dictname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
161 if dict_el is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
162 dict_el = Element(dictname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
163 dict_el.set('type', 'dict')
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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:
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
166 dict_el.remove(list_el.find('dict'))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
167 dict_el.append(self.BuildDict(val))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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 = {}
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
172 for ditem in parent.findall('dobject'):
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
173 key = self.normal(ditem.get('name'))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
174 if ditem.get('type') == 'int': value = int(ditem.text)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
175 elif ditem.get('type') == 'bool': value = ditem.text == 'True'
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
176 elif ditem.get('type') == 'float': value = float(ditem.text)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
177 elif ditem.get('type') == 'list': value = self.FetchList(ditem)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
178 elif ditem.get('type') == 'dict': value = self.FetchDict(ditem)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
179 else: value = str(self.normal(ditem[0]))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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)
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
185 plugin = self.etree.find(plugname)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
186 if plugin is None or plugin.find(dictname) is None:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
187 msg = ["plugindb: no value has been stored for", dictname, "in",
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
188 plugname, "so the default has been returned"]
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
191 retdict = self.FetchDict(plugin.find(dictname))
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
192 logger.debug("successfully found dict value", verbose)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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):
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
196 return string.replace("<", "$$lt$$").replace(">", "$$gt$$")\
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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):
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
200 return string.replace("$$lt$$", "<").replace("$$gt$$", ">")\
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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):
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
204 with open(self.filename, "w") as f:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
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):
135
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
208 with open(self.filename) as f:
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
209 self.etree.parse(f)
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
210
dcf4fbe09b70 Traipse Beta 'OpenRPG' {091010-00}
sirebral
parents: 66
diff changeset
211 plugindb = PluginDB()