Mercurial > traipse_dev
annotate upmana/manifest.py @ 197:fcd6aafbe232 alpha
Traipse Alpha 'OpenRPG' {100426-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)
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 PluginDB access for URL2Link plugin
New to Forms, they now show their content in Design Mode
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
author | sirebral |
---|---|
date | Mon, 26 Apr 2010 14:30:16 -0500 |
parents | 8e07c1a2c69b |
children |
rev | line source |
---|---|
121 | 1 from __future__ import with_statement |
2 | |
66 | 3 from orpg.dirpath import dir_struct |
121 | 4 from upmana.validate import validate |
5 from orpg.tools.orpg_log import logger | |
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 | 9 from xml.etree.ElementTree import ElementTree, Element, parse, fromstring |
10 from xml.etree.ElementPath import find | |
11 | |
12 class ManifestChanges(object): | |
13 etree = ElementTree() | |
122 | 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 | 16 def __new__(cls, *args, **kwargs): |
17 it = cls.__dict__.get("__it__") | |
18 if it is not None: | |
19 return it | |
20 cls.__it__ = it = object.__new__(cls) | |
21 it._init() | |
22 return it | |
23 | |
24 def _init(self): | |
122 | 25 validate.config_file('upmana.xml', "default_upmana.xml") |
121 | 26 self.LoadDoc() |
27 | |
28 def PluginChildren(self, plugname): | |
29 plugin = self.etree.find(plugname) | |
30 children = plugin.getchildren() | |
31 nodes = [] | |
32 for child in children: | |
33 nodes.append(child.tag) | |
34 return nodes | |
35 | |
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 | 38 plugin = self.etree.find(plugname) |
39 if plugin is None or plugin.find(strname) is None: | |
40 msg = ["plugindb: no value has been stored for", strname, "in", | |
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 | 43 return self.normal(plugin.find(strname).text or '') |
121 | 44 |
45 def DelString(self, plugname, strname): | |
46 strname = self.safe(strname) | |
47 plugin = self.etree.find(plugname) | |
48 plugin.remove(plugin.find(strname)) | |
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 | 54 plugin = self.etree.find(plugname) |
55 if plugin is None: | |
56 plugin = Element(plugname) | |
57 self.etree.getroot().append(plugin) | |
58 str_el = plugin.find(strname) | |
59 if str_el is None: | |
60 str_el = Element(strname) | |
61 str_el.set('type', 'str') | |
62 plugin.append(str_el) | |
63 str_el.text = val | |
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 = [] |
139 | 68 for litem in parent.find('list').findall('lobject'): |
121 | 69 if litem.get('type') == 'int': retlist.append(int(litem.text)) |
70 if litem.get('type') == 'bool': retlist.append(litem.text == 'True') | |
71 elif litem.get('type') == 'float': retlist.append(float(litem.text)) | |
72 elif litem.get('type') == 'list': retlist.append(self.FetchList(litem)) | |
73 elif litem.get('type') == 'dict': retlist.append(self.FetchDict(litem)) | |
74 else: retlist.append(str(self.normal(litem.text))) | |
75 return retlist | |
76 | |
77 def GetList(self, plugname, listname, defaultval=list(), verbose=False): | |
78 listname = self.safe(listname) | |
79 plugin = self.etree.find(plugname) | |
80 if plugin is None or plugin.find(listname) is None: | |
81 msg = ["plugindb: no value has been stored for", listname, "in", | |
82 plugname, "so the default has been returned"] | |
83 return defaultval | |
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 | 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 | 90 i = Element('lobject') |
91 if isinstance(item, bool): | |
92 i.set('type', 'bool') | |
93 i.text = str(item) | |
94 elif isinstance(item, int):#it's an int | |
95 i.set('type', 'int') | |
96 i.text = str(item) | |
97 elif isinstance(item, float):#it's a float | |
98 i.set('type', 'float') | |
99 i.text = str(item) | |
100 elif isinstance(item, (list, tuple)):#it's a list | |
101 i.set('type', 'list') | |
102 i.append(self.BuildList(item)) | |
103 elif isinstance(item, dict):#it's a dictionary | |
104 i.set('type', 'dict') | |
105 i.append(self.BuildDict(item)) | |
106 else: | |
107 i.set('type', 'str') | |
108 i.text = self.safe(item) | |
109 list_el.append(i) | |
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 | 114 plugin = self.etree.find(plugname) |
115 if plugin is None: | |
116 plugin = Element(plugname) | |
117 self.etree.getroot().append(plugin) | |
118 list_el = plugin.find(listname) | |
119 if list_el is None: | |
120 list_el = Element(listname) | |
121 list_el.set('type', 'list') | |
122 plugin.append(list_el) | |
33
3687514e0218
I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff
changeset
|
123 else: |
121 | 124 list_el.remove(list_el.find('list')) |
125 list_el.append(self.BuildList(val)) | |
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 | 129 dict_el = Element('dict') |
130 for key, item in val.items(): | |
131 i = Element('dobject') | |
132 if isinstance(item, bool): | |
133 i.set('type', 'bool') | |
134 i.set('name', self.safe(key)) | |
135 i.text = str(item) | |
136 elif isinstance(item, int):#it's an int | |
137 i.set('type', 'int') | |
138 i.set('name', self.safe(key)) | |
139 i.text = str(item) | |
140 elif isinstance(item, float):#it's a float | |
141 i.set('type', 'float') | |
142 i.set('name', self.safe(key)) | |
143 i.text = str(item) | |
144 elif isinstance(item, (list, tuple)):#it's a list | |
145 i.set('type', 'list') | |
146 i.set('name', self.safe(key)) | |
147 i.append(self.BuildList(item)) | |
148 elif isinstance(item, dict):#it's a dictionary | |
149 i.set('type', 'dict') | |
150 i.set('name', self.safe(key)) | |
151 i.append(self.BuildDict(item)) | |
152 else: | |
153 i.set('type', 'str') | |
154 i.set('name', self.safe(key)) | |
155 i.text = self.safe(item) | |
156 dict_el.append(i) | |
157 return dict_el | |
33
3687514e0218
I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff
changeset
|
158 |
121 | 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 | 161 plugin = self.etree.find(plugname) |
162 if plugin is None: | |
163 plugin = Element(plugname) | |
164 self.etree.getroot().append(plugin) | |
165 dict_el = plugin.find(dictname) | |
166 if dict_el is None: | |
167 dict_el = Element(dictname) | |
168 dict_el.set('type', 'dict') | |
169 plugin.append(dict_el) | |
33
3687514e0218
I actally forgot the Update Manager's new package. Sorry.
sirebral
parents:
diff
changeset
|
170 else: |
121 | 171 dict_el.remove(list_el.find('dict')) |
172 dict_el.append(self.BuildDict(val)) | |
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 | 177 for ditem in parent.findall('dobject'): |
178 key = self.normal(ditem.get('name')) | |
179 if ditem.get('type') == 'int': value = int(ditem.text) | |
180 elif ditem.get('type') == 'bool': value = ditem.text == 'True' | |
181 elif ditem.get('type') == 'float': value = float(ditem.text) | |
182 elif ditem.get('type') == 'list': value = self.FetchList(ditem) | |
183 elif ditem.get('type') == 'dict': value = self.FetchDict(ditem) | |
184 else: value = str(self.normal(ditem[0])) | |
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 | 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 | 190 plugin = self.etree.find(plugname) |
191 if plugin is None or plugin.find(dictname) is None: | |
192 msg = ["plugindb: no value has been stored for", dictname, "in", | |
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 | 195 retdict = self.FetchDict(plugin.find(dictname)) |
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 | 199 return string.replace("<", "$$lt$$").replace(">", "$$gt$$")\ |
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 | 203 return string.replace("$$lt$$", "<").replace("$$gt$$", ">")\ |
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 | 207 with open(self.filename, "w") as f: |
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 | 211 with open(self.filename) as f: |
212 self.etree.parse(f) | |
213 | |
214 manifest = ManifestChanges() |