annotate upmana/manifest.py @ 134:82c47d583493 alpha

Traipse Alpha 'OpenRPG' {091010-01} 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!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!! Dead Node Children, now that's a O O -v-v- Happy Halloween!
author sirebral
date Tue, 10 Nov 2009 13:32:07 -0600
parents 36919b8a3ef9
children 8e07c1a2c69b
rev   line source
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
1 from __future__ import with_statement
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
2
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 59
diff changeset
3 from orpg.dirpath import dir_struct
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
4 from upmana.validate import validate
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
5 from orpg.tools.orpg_log import logger
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
6 from os import sep, getcwd
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
7 from types import *
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
8
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
9 from xml.etree.ElementTree import ElementTree, Element, parse, fromstring
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
10 from xml.etree.ElementPath import find
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
11
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
12 class ManifestChanges(object):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
13 etree = ElementTree()
122
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 121
diff changeset
14 filename = dir_struct['home'] + 'upmana' + sep + 'upmana.xml'
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
15
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
16 def __new__(cls, *args, **kwargs):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
17 it = cls.__dict__.get("__it__")
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
18 if it is not None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
19 return it
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
20 cls.__it__ = it = object.__new__(cls)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
21 it._init()
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
22 return it
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
23
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
24 def _init(self):
122
36919b8a3ef9 Traipse Alpha 'OpenRPG' {091031-00}
sirebral
parents: 121
diff changeset
25 validate.config_file('upmana.xml', "default_upmana.xml")
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
26 self.LoadDoc()
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
27
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
28 def PluginChildren(self, plugname):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
29 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
30 children = plugin.getchildren()
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
31 nodes = []
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
32 for child in children:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
33 nodes.append(child.tag)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
34 return nodes
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
35
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
36 def GetString(self, plugname, strname, defaultval="", verbose=False):
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
37 strname = self.safe(strname)
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
38 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
39 if plugin is None or plugin.find(strname) is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
40 msg = ["plugindb: no value has been stored for", strname, "in",
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
41 plugname, "so the default has been returned"]
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
42 return defaultval
134
82c47d583493 Traipse Alpha 'OpenRPG' {091010-01}
sirebral
parents: 122
diff changeset
43 return self.normal(plugin.find(strname).text or '')
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
44
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
45 def DelString(self, plugname, strname):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
46 strname = self.safe(strname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
47 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
48 plugin.remove(plugin.find(strname))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
49 self.SaveDoc()
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
50
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
51 def SetString(self, plugname, strname, val):
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
52 val = self.safe(val)
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
53 strname = self.safe(strname)
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
54 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
55 if plugin is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
56 plugin = Element(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
57 self.etree.getroot().append(plugin)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
58 str_el = plugin.find(strname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
59 if str_el is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
60 str_el = Element(strname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
61 str_el.set('type', 'str')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
62 plugin.append(str_el)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
63 str_el.text = val
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
64 self.SaveDoc()
34
8b630fc8a343 Updated the Update Manager to 0.3. Settings are being created with a clone
sirebral
parents: 33
diff changeset
65
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
66 def FetchList(self, parent):
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
67 retlist = []
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
68 for litem in parent.findall('lobject'):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
69 if litem.get('type') == 'int': retlist.append(int(litem.text))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
70 if litem.get('type') == 'bool': retlist.append(litem.text == 'True')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
71 elif litem.get('type') == 'float': retlist.append(float(litem.text))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
72 elif litem.get('type') == 'list': retlist.append(self.FetchList(litem))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
73 elif litem.get('type') == 'dict': retlist.append(self.FetchDict(litem))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
74 else: retlist.append(str(self.normal(litem.text)))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
75 return retlist
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
76
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
77 def GetList(self, plugname, listname, defaultval=list(), verbose=False):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
78 listname = self.safe(listname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
79 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
80 if plugin is None or plugin.find(listname) is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
81 msg = ["plugindb: no value has been stored for", listname, "in",
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
82 plugname, "so the default has been returned"]
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
83 return defaultval
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
84 retlist = self.FetchList(plugin.find(listname))
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
85 return retlist
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
86
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
87 def BuildList(self, val):
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
88 list_el = Element('list')
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
89 for item in val:
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
90 i = Element('lobject')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
91 if isinstance(item, bool):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
92 i.set('type', 'bool')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
93 i.text = str(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
94 elif isinstance(item, int):#it's an int
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
95 i.set('type', 'int')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
96 i.text = str(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
97 elif isinstance(item, float):#it's a float
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
98 i.set('type', 'float')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
99 i.text = str(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
100 elif isinstance(item, (list, tuple)):#it's a list
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
101 i.set('type', 'list')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
102 i.append(self.BuildList(item))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
103 elif isinstance(item, dict):#it's a dictionary
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
104 i.set('type', 'dict')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
105 i.append(self.BuildDict(item))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
106 else:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
107 i.set('type', 'str')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
108 i.text = self.safe(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
109 list_el.append(i)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
110 return list_el
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
111
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
112 def SetList(self, plugname, listname, val):
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
113 listname = self.safe(listname)
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
114 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
115 if plugin is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
116 plugin = Element(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
117 self.etree.getroot().append(plugin)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
118 list_el = plugin.find(listname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
119 if list_el is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
120 list_el = Element(listname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
121 list_el.set('type', 'list')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
122 plugin.append(list_el)
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
123 else:
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
124 list_el.remove(list_el.find('list'))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
125 list_el.append(self.BuildList(val))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
126 self.SaveDoc()
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
127
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
128 def BuildDict(self, val):
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
129 dict_el = Element('dict')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
130 for key, item in val.items():
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
131 i = Element('dobject')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
132 if isinstance(item, bool):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
133 i.set('type', 'bool')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
134 i.set('name', self.safe(key))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
135 i.text = str(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
136 elif isinstance(item, int):#it's an int
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
137 i.set('type', 'int')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
138 i.set('name', self.safe(key))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
139 i.text = str(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
140 elif isinstance(item, float):#it's a float
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
141 i.set('type', 'float')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
142 i.set('name', self.safe(key))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
143 i.text = str(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
144 elif isinstance(item, (list, tuple)):#it's a list
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
145 i.set('type', 'list')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
146 i.set('name', self.safe(key))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
147 i.append(self.BuildList(item))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
148 elif isinstance(item, dict):#it's a dictionary
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
149 i.set('type', 'dict')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
150 i.set('name', self.safe(key))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
151 i.append(self.BuildDict(item))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
152 else:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
153 i.set('type', 'str')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
154 i.set('name', self.safe(key))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
155 i.text = self.safe(item)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
156 dict_el.append(i)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
157 return dict_el
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
158
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
159 def SetDict(self, plugname, dictname, val):
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
160 dictname = self.safe(dictname)
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
161 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
162 if plugin is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
163 plugin = Element(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
164 self.etree.getroot().append(plugin)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
165 dict_el = plugin.find(dictname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
166 if dict_el is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
167 dict_el = Element(dictname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
168 dict_el.set('type', 'dict')
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
169 plugin.append(dict_el)
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
170 else:
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
171 dict_el.remove(list_el.find('dict'))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
172 dict_el.append(self.BuildDict(val))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
173 self.SaveDoc()
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
174
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
175 def FetchDict(self, parent):
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
176 retdict = {}
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
177 for ditem in parent.findall('dobject'):
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
178 key = self.normal(ditem.get('name'))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
179 if ditem.get('type') == 'int': value = int(ditem.text)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
180 elif ditem.get('type') == 'bool': value = ditem.text == 'True'
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
181 elif ditem.get('type') == 'float': value = float(ditem.text)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
182 elif ditem.get('type') == 'list': value = self.FetchList(ditem)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
183 elif ditem.get('type') == 'dict': value = self.FetchDict(ditem)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
184 else: value = str(self.normal(ditem[0]))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
185 retdict[key] = value
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
186 return retdict
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
187
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
188 def GetDict(self, plugname, dictname, defaultval=dict(), verbose=False):
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
189 dictname = self.safe(dictname)
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
190 plugin = self.etree.find(plugname)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
191 if plugin is None or plugin.find(dictname) is None:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
192 msg = ["plugindb: no value has been stored for", dictname, "in",
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
193 plugname, "so the default has been returned"]
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
194 return defaultval
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
195 retdict = self.FetchDict(plugin.find(dictname))
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
196 return retdict
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
197
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
198 def safe(self, string):
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
199 return string.replace("<", "$$lt$$").replace(">", "$$gt$$")\
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
200 .replace("&","$$amp$$").replace('"',"$$quote$$")
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
201
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
202 def normal(self, string):
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
203 return string.replace("$$lt$$", "<").replace("$$gt$$", ">")\
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
204 .replace("$$amp$$","&").replace("$$quote$$",'"')
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
205
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
206 def SaveDoc(self):
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
207 with open(self.filename, "w") as f:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
208 self.etree.write(f)
33
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
209
3687514e0218 I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff changeset
210 def LoadDoc(self):
121
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
211 with open(self.filename) as f:
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
212 self.etree.parse(f)
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
213
496dbf12a6cb Traipse Alpha 'OpenRPG' {091030-00}
sirebral
parents: 66
diff changeset
214 manifest = ManifestChanges()