Mercurial > traipse_dev
comparison upmana/manifest.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 | e842a5f1b775 |
comparison
equal
deleted
inserted
replaced
101:394ebb3b6a0f | 135:dcf4fbe09b70 |
---|---|
1 import xmltramp | 1 from __future__ import with_statement |
2 | |
2 from orpg.dirpath import dir_struct | 3 from orpg.dirpath import dir_struct |
3 import upmana.validate | 4 from upmana.validate import validate |
4 from os import sep | 5 from orpg.tools.orpg_log import logger |
6 from os import sep, getcwd | |
5 from types import * | 7 from types import * |
6 | 8 |
7 class ManifestChanges: | 9 from xml.etree.ElementTree import ElementTree, Element, parse, fromstring |
8 def __init__(self, filename="updatemana.xml"): | 10 from xml.etree.ElementPath import find |
9 self.filename = dir_struct["home"] + 'upmana' + sep + filename | 11 |
10 upmana.validate.Validate(dir_struct["home"] + 'upmana' + sep).config_file(filename,"default_manifest.xml") | 12 class ManifestChanges(object): |
11 self.xml_dom = self.LoadDoc() | 13 etree = ElementTree() |
12 | 14 filename = dir_struct['home'] + 'upmana' + sep + 'upmana.xml' |
13 def GetString(self, plugname, strname, defaultval, verbose=0): | 15 |
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): | |
25 validate.config_file('upmana.xml', "default_upmana.xml") | |
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): | |
14 strname = self.safe(strname) | 37 strname = self.safe(strname) |
15 for plugin in self.xml_dom: | 38 plugin = self.etree.find(plugname) |
16 if plugname == plugin._name: | 39 if plugin is None or plugin.find(strname) is None: |
17 for child in plugin._dir: | 40 msg = ["plugindb: no value has been stored for", strname, "in", |
18 if child._name == strname: | 41 plugname, "so the default has been returned"] |
19 #str() on this to make sure it's ASCII, not unicode, since orpg can't handle unicode. | |
20 if verbose: print "successfully found the value" | |
21 if len(child): return str( self.normal(child[0]) ) | |
22 else: return "" | |
23 else: | |
24 if verbose: | |
25 print "manifest: no value has been stored for " + strname + " in " + plugname + " so the default has been returned" | |
26 return defaultval | 42 return defaultval |
43 return self.normal(plugin.find(strname).text or '') | |
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() | |
27 | 50 |
28 def SetString(self, plugname, strname, val): | 51 def SetString(self, plugname, strname, val): |
29 #Set Node, <repo, name, description, value> | |
30 #Set Setting, <setting, value> | |
31 val = self.safe(val) | 52 val = self.safe(val) |
32 strname = self.safe(strname) | 53 strname = self.safe(strname) |
33 for plugin in self.xml_dom: | 54 plugin = self.etree.find(plugname) |
34 ##this isn't absolutely necessary, but it saves the trouble of sending a parsed object instead of a simple string. | 55 if plugin is None: |
35 if plugname == plugin._name: | 56 plugin = Element(plugname) |
36 plugin[strname] = val | 57 self.etree.getroot().append(plugin) |
37 plugin[strname]._attrs["type"] = "string" | 58 str_el = plugin.find(strname) |
38 self.SaveDoc() | 59 if str_el is None: |
39 return "found plugin" | 60 str_el = Element(strname) |
40 else: | 61 str_el.set('type', 'str') |
41 self.xml_dom[plugname] = xmltramp.parse("<" + strname + " type=\"string\">" + val + "</" + strname + ">") | 62 plugin.append(str_el) |
42 self.SaveDoc() | 63 str_el.text = val |
43 return "added plugin" | 64 self.SaveDoc() |
44 | |
45 | 65 |
46 def FetchList(self, parent): | 66 def FetchList(self, parent): |
47 retlist = [] | 67 retlist = [] |
48 if not len(parent): return [] | 68 for litem in parent.findall('lobject'): |
49 for litem in parent[0]._dir: | 69 if litem.get('type') == 'int': retlist.append(int(litem.text)) |
50 if len(litem): | 70 if litem.get('type') == 'bool': retlist.append(litem.text == 'True') |
51 if litem._attrs["type"] == "int": retlist += [int(litem[0])] | 71 elif litem.get('type') == 'float': retlist.append(float(litem.text)) |
52 elif litem._attrs["type"] == "long": retlist += [long(litem[0])] | 72 elif litem.get('type') == 'list': retlist.append(self.FetchList(litem)) |
53 elif litem._attrs["type"] == "float": retlist += [float(litem[0])] | 73 elif litem.get('type') == 'dict': retlist.append(self.FetchDict(litem)) |
54 elif litem._attrs["type"] == "list": retlist += [self.FetchList(litem)] | 74 else: retlist.append(str(self.normal(litem.text))) |
55 elif litem._attrs["type"] == "dict": retlist += [self.FetchDict(litem)] | |
56 else: retlist += [str( self.normal(litem[0]) )] | |
57 else: retlist += [""] | |
58 return retlist | 75 return retlist |
59 | 76 |
60 def GetList(self, plugname, listname, defaultval, verbose=0): | 77 def GetList(self, plugname, listname, defaultval=list(), verbose=False): |
61 listname = self.safe(listname) | 78 listname = self.safe(listname) |
62 for plugin in self.xml_dom: | 79 plugin = self.etree.find(plugname) |
63 if plugname == plugin._name: | 80 if plugin is None or plugin.find(listname) is None: |
64 for child in plugin._dir: | 81 msg = ["plugindb: no value has been stored for", listname, "in", |
65 if child._name == listname and child._attrs["type"] == "list": | 82 plugname, "so the default has been returned"] |
66 retlist = self.FetchList(child) | |
67 if verbose: print "successfully found the value" | |
68 return retlist | |
69 else: | |
70 if verbose: | |
71 print "plugindb: no value has been stored for " + listname + " in " + plugname + " so the default has been returned" | |
72 return defaultval | 83 return defaultval |
84 retlist = self.FetchList(plugin.find(listname)) | |
85 return retlist | |
73 | 86 |
74 def BuildList(self, val): | 87 def BuildList(self, val): |
75 listerine = "<list>" | 88 list_el = Element('list') |
76 for item in val: | 89 for item in val: |
77 if isinstance(item, basestring):#it's a string | 90 i = Element('lobject') |
78 listerine += "<lobject type=\"str\">" + self.safe(item) + "</lobject>" | 91 if isinstance(item, bool): |
79 elif isinstance(item, IntType):#it's an int | 92 i.set('type', 'bool') |
80 listerine += "<lobject type=\"int\">" + str(item) + "</lobject>" | 93 i.text = str(item) |
81 elif isinstance(item, FloatType):#it's a float | 94 elif isinstance(item, int):#it's an int |
82 listerine += "<lobject type=\"float\">" + str(item) + "</lobject>" | 95 i.set('type', 'int') |
83 elif isinstance(item, LongType):#it's a long | 96 i.text = str(item) |
84 listerine += "<lobject type=\"long\">" + str(item) + "</lobject>" | 97 elif isinstance(item, float):#it's a float |
85 elif isinstance(item, ListType):#it's a list | 98 i.set('type', 'float') |
86 listerine += "<lobject type=\"list\">" + self.BuildList(item) + "</lobject>" | 99 i.text = str(item) |
87 elif isinstance(item, DictType):#it's a dictionary | 100 elif isinstance(item, (list, tuple)):#it's a list |
88 listerine += "<lobject type=\"dict\">" + self.BuildDict(item) + "</lobject>" | 101 i.set('type', 'list') |
89 else: return "type unknown" | 102 i.append(self.BuildList(item)) |
90 listerine += "</list>" | 103 elif isinstance(item, dict):#it's a dictionary |
91 return listerine | 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 | |
92 | 111 |
93 def SetList(self, plugname, listname, val): | 112 def SetList(self, plugname, listname, val): |
94 listname = self.safe(listname) | 113 listname = self.safe(listname) |
95 list = xmltramp.parse(self.BuildList(val)) | 114 plugin = self.etree.find(plugname) |
96 for plugin in self.xml_dom: | 115 if plugin is None: |
97 if plugname == plugin._name: | 116 plugin = Element(plugname) |
98 plugin[listname] = list | 117 self.etree.getroot().append(plugin) |
99 plugin[listname]._attrs["type"] = "list" | 118 list_el = plugin.find(listname) |
100 self.SaveDoc() | 119 if list_el is None: |
101 return "found plugin" | 120 list_el = Element(listname) |
121 list_el.set('type', 'list') | |
122 plugin.append(list_el) | |
102 else: | 123 else: |
103 self.xml_dom[plugname] = xmltramp.parse("<" + listname + "></" + listname + ">") | 124 list_el.remove(list_el.find('list')) |
104 self.xml_dom[plugname][listname] = list | 125 list_el.append(self.BuildList(val)) |
105 self.xml_dom[plugname][listname]._attrs["type"] = "list" | 126 self.SaveDoc() |
106 self.SaveDoc() | |
107 return "added plugin" | |
108 | 127 |
109 def BuildDict(self, val): | 128 def BuildDict(self, val): |
110 dictator = "<dict>" | 129 dict_el = Element('dict') |
111 for item in val.keys(): | 130 for key, item in val.items(): |
112 if isinstance(val[item], basestring): | 131 i = Element('dobject') |
113 dictator += "<dobject name=\"" + self.safe(item) + "\" type=\"str\">" + self.safe(val[item]) + "</dobject>" | 132 if isinstance(item, bool): |
114 elif isinstance(val[item], IntType):#it's an int | 133 i.set('type', 'bool') |
115 dictator += "<dobject name=\"" + self.safe(item) + "\" type=\"int\">" + str(val[item]) + "</dobject>" | 134 i.set('name', self.safe(key)) |
116 elif isinstance(val[item], FloatType):#it's a float | 135 i.text = str(item) |
117 dictator += "<dobject name=\"" + self.safe(item) + "\" type=\"float\">" + str(val[item]) + "</dobject>" | 136 elif isinstance(item, int):#it's an int |
118 elif isinstance(val[item], LongType):#it's a long | 137 i.set('type', 'int') |
119 dictator += "<dobject name=\"" + self.safe(item) + "\" type=\"long\">" + str(val[item]) + "</dobject>" | 138 i.set('name', self.safe(key)) |
120 elif isinstance(val[item], DictType):#it's a dictionary | 139 i.text = str(item) |
121 dictator += "<dobject name=\"" + self.safe(item) + "\" type=\"dict\">" + self.BuildDict(val[item]) + "</dobject>" | 140 elif isinstance(item, float):#it's a float |
122 elif isinstance(val[item], ListType):#it's a list | 141 i.set('type', 'float') |
123 dictator += "<dobject name=\"" + self.safe(item) + "\" type=\"list\">" + self.BuildList(val[item]) + "</dobject>" | 142 i.set('name', self.safe(key)) |
124 else: return str(val[item]) + ": type unknown" | 143 i.text = str(item) |
125 dictator += "</dict>" | 144 elif isinstance(item, (list, tuple)):#it's a list |
126 return dictator | 145 i.set('type', 'list') |
127 | 146 i.set('name', self.safe(key)) |
128 def SetDict(self, plugname, dictname, val, file="plugindb.xml"): | 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 | |
158 | |
159 def SetDict(self, plugname, dictname, val): | |
129 dictname = self.safe(dictname) | 160 dictname = self.safe(dictname) |
130 dict = xmltramp.parse(self.BuildDict(val)) | 161 plugin = self.etree.find(plugname) |
131 for plugin in self.xml_dom: | 162 if plugin is None: |
132 if plugname == plugin._name: | 163 plugin = Element(plugname) |
133 plugin[dictname] = dict | 164 self.etree.getroot().append(plugin) |
134 plugin[dictname]._attrs["type"] = "dict" | 165 dict_el = plugin.find(dictname) |
135 self.SaveDoc() | 166 if dict_el is None: |
136 return "found plugin" | 167 dict_el = Element(dictname) |
168 dict_el.set('type', 'dict') | |
169 plugin.append(dict_el) | |
137 else: | 170 else: |
138 self.xml_dom[plugname] = xmltramp.parse("<" + dictname + "></" + dictname + ">") | 171 dict_el.remove(list_el.find('dict')) |
139 self.xml_dom[plugname][dictname] = dict | 172 dict_el.append(self.BuildDict(val)) |
140 self.xml_dom[plugname][dictname]._attrs["type"] = "dict" | 173 self.SaveDoc() |
141 self.SaveDoc() | |
142 return "added plugin" | |
143 | 174 |
144 def FetchDict(self, parent): | 175 def FetchDict(self, parent): |
145 retdict = {} | 176 retdict = {} |
146 if not len(parent): return {} | 177 for ditem in parent.findall('dobject'): |
147 for ditem in parent[0]._dir: | 178 key = self.normal(ditem.get('name')) |
148 if len(ditem): | 179 if ditem.get('type') == 'int': value = int(ditem.text) |
149 ditem._attrs["name"] = self.normal(ditem._attrs["name"]) | 180 elif ditem.get('type') == 'bool': value = ditem.text == 'True' |
150 if ditem._attrs["type"] == "int": retdict[ditem._attrs["name"]] = int(ditem[0]) | 181 elif ditem.get('type') == 'float': value = float(ditem.text) |
151 elif ditem._attrs["type"] == "long": retdict[ditem._attrs["name"]] = long(ditem[0]) | 182 elif ditem.get('type') == 'list': value = self.FetchList(ditem) |
152 elif ditem._attrs["type"] == "float": retdict[ditem._attrs["name"]] = float(ditem[0]) | 183 elif ditem.get('type') == 'dict': value = self.FetchDict(ditem) |
153 elif ditem._attrs["type"] == "list": retdict[ditem._attrs["name"]] = self.FetchList(ditem) | 184 else: value = str(self.normal(ditem[0])) |
154 elif ditem._attrs["type"] == "dict": retdict[ditem._attrs["name"]] = self.FetchDict(ditem) | 185 retdict[key] = value |
155 else: retdict[ditem._attrs["name"]] = str( self.normal(ditem[0]) ) | |
156 else: retdict[ditem._attrs["name"]] = "" | |
157 return retdict | 186 return retdict |
158 | 187 |
159 def GetDict(self, plugname, dictname, defaultval, verbose=0): | 188 def GetDict(self, plugname, dictname, defaultval=dict(), verbose=False): |
160 dictname = self.safe(dictname) | 189 dictname = self.safe(dictname) |
161 for plugin in self.xml_dom: | 190 plugin = self.etree.find(plugname) |
162 if plugname == plugin._name: | 191 if plugin is None or plugin.find(dictname) is None: |
163 for child in plugin._dir: | 192 msg = ["plugindb: no value has been stored for", dictname, "in", |
164 if child._name == dictname and child._attrs["type"] == "dict": return self.FetchDict(child) | 193 plugname, "so the default has been returned"] |
165 else: | |
166 if verbose: | |
167 print "plugindb: no value has been stored for " + dictname + " in " + plugname + " so the default has been returned" | |
168 return defaultval | 194 return defaultval |
195 retdict = self.FetchDict(plugin.find(dictname)) | |
196 return retdict | |
169 | 197 |
170 def safe(self, string): | 198 def safe(self, string): |
171 return string.replace("<", "$$lt$$").replace(">", "$$gt$$").replace("&","$$amp$$").replace('"',"$$quote$$") | 199 return string.replace("<", "$$lt$$").replace(">", "$$gt$$")\ |
200 .replace("&","$$amp$$").replace('"',"$$quote$$") | |
172 | 201 |
173 def normal(self, string): | 202 def normal(self, string): |
174 return string.replace("$$lt$$", "<").replace("$$gt$$", ">").replace("$$amp$$","&").replace("$$quote$$",'"') | 203 return string.replace("$$lt$$", "<").replace("$$gt$$", ">")\ |
204 .replace("$$amp$$","&").replace("$$quote$$",'"') | |
175 | 205 |
176 def SaveDoc(self): | 206 def SaveDoc(self): |
177 f = open(self.filename, "w") | 207 with open(self.filename, "w") as f: |
178 f.write(self.xml_dom.__repr__(1, 1)) | 208 self.etree.write(f) |
179 f.close() | |
180 | 209 |
181 def LoadDoc(self): | 210 def LoadDoc(self): |
182 xml_file = open(self.filename) | 211 with open(self.filename) as f: |
183 manifest = xml_file.read() | 212 self.etree.parse(f) |
184 xml_file.close() | 213 |
185 return xmltramp.parse(manifest) | 214 manifest = ManifestChanges() |