comparison orpg/gametree/gametree.py @ 218:b8091ede042a alpha

Traipse Alpha 'OpenRPG' {100430-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 (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 New to Update Manager, checks Repo for updates on software start New to Mini Lin 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 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
author sirebral
date Fri, 30 Apr 2010 11:37:37 -0500
parents 50af54dbd6a6
children 24769389a7ba
comparison
equal deleted inserted replaced
215:50af54dbd6a6 218:b8091ede042a
43 from orpg.orpg_windows import * 43 from orpg.orpg_windows import *
44 from orpg.orpgCore import component 44 from orpg.orpgCore import component
45 from orpg.dirpath import dir_struct 45 from orpg.dirpath import dir_struct
46 from nodehandlers import core 46 from nodehandlers import core
47 import string, urllib, time, os 47 import string, urllib, time, os
48 from shutil import copytree, copystat, copy, copyfile
48 49
49 from orpg.orpg_xml import xml 50 from orpg.orpg_xml import xml
50 from orpg.tools.validate import validate 51 from orpg.tools.validate import validate
51 from orpg.tools.orpg_log import logger, debug 52 from orpg.tools.orpg_log import logger, debug
52 from orpg.tools.orpg_settings import settings 53 from orpg.tools.orpg_settings import settings
57 from gametree_version import GAMETREE_VERSION 58 from gametree_version import GAMETREE_VERSION
58 59
59 from xml.etree.ElementTree import ElementTree, Element, parse 60 from xml.etree.ElementTree import ElementTree, Element, parse
60 from xml.etree.ElementTree import fromstring, tostring, XML, iselement 61 from xml.etree.ElementTree import fromstring, tostring, XML, iselement
61 from xml.parsers.expat import ExpatError 62 from xml.parsers.expat import ExpatError
63
64 def exists(path):
65 try:
66 os.stat(path)
67 return True
68 except: return False
62 69
63 STD_MENU_DELETE = wx.NewId() 70 STD_MENU_DELETE = wx.NewId()
64 STD_MENU_DESIGN = wx.NewId() 71 STD_MENU_DESIGN = wx.NewId()
65 STD_MENU_USE = wx.NewId() 72 STD_MENU_USE = wx.NewId()
66 STD_MENU_PP = wx.NewId() 73 STD_MENU_PP = wx.NewId()
204 elif key_code == wx.WXK_F2: 211 elif key_code == wx.WXK_F2:
205 self.rename_flag = 1 212 self.rename_flag = 1
206 self.EditLabel(curSelection) 213 self.EditLabel(curSelection)
207 evt.Skip() 214 evt.Skip()
208 215
209 def locate_valid_tree(self, error, msg): ## --Snowdog 3/05 216 def locate_valid_tree(self, error, msg, filename): ## --Snowdog 3/05
210 """prompts the user to locate a new tree file or create a new one""" 217 """prompts the user to locate a new tree file or create a new one"""
211 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) 218 response = wx.MessageBox(msg, error, wx.YES|wx.NO|wx.ICON_ERROR)
212 if response == wx.YES: 219 if response == wx.YES:
213 file = None 220 file = None
214 dlg = wx.FileDialog(self, "Locate Gametree file", dir_struct["user"], 221 dlg = wx.FileDialog(self, "Locate Gametree file", dir_struct["user"],
215 filename[ ((filename.rfind(os.sep))+len(os.sep)):], 222 filename[ ((filename.rfind(os.sep))+len(os.sep)):],
216 "Gametree (*.xml)|*.xml|All files (*.*)|*.*", 223 "Gametree (*.xml)|*.xml|All files (*.*)|*.*",
219 dlg.Destroy() 226 dlg.Destroy()
220 if not file: self.load_tree(error=1) 227 if not file: self.load_tree(error=1)
221 else: self.load_tree(file) 228 else: self.load_tree(file)
222 return 229 return
223 else: 230 else:
231 copyfile(dir_struct['template']+'default_tree.xml', filename)
224 validate.config_file("tree.xml","default_tree.xml") 232 validate.config_file("tree.xml","default_tree.xml")
225 self.load_tree(error=1) 233 self.load_tree(error=1)
226 return 234 return
227 235
228 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): 236 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0):
232 "Would you like to locate it?\n"\ 240 "Would you like to locate it?\n"\
233 "(Selecting 'No' will cause a new default gametree to be generated)" 241 "(Selecting 'No' will cause a new default gametree to be generated)"
234 self.locate_valid_tree("Gametree Error", emsg) 242 self.locate_valid_tree("Gametree Error", emsg)
235 return 243 return
236 try: 244 try:
245 self.xml_root = False
237 tree = parse(filename) 246 tree = parse(filename)
238 self.xml_root = tree.getroot() 247 self.xml_root = tree.getroot()
239 except: 248 except: self.xml_root = False
240 self.xml_root = None
241
242 if not self.xml_root: 249 if not self.xml_root:
243 os.rename(filename,filename+".corrupt") 250 count = 1
251 while exists(filename[:len(filename)-4]+'-'+str(count)+'.xml'): count += 1
252 corrupt_tree = filename[:len(filename)-4]+'-'+str(count)+'.xml'
253 copyfile(filename, corrupt_tree)
244 emsg = "Your gametree is being regenerated.\n\n"\ 254 emsg = "Your gametree is being regenerated.\n\n"\
245 "To salvage a recent version of your gametree\n"\ 255 "To salvage a recent version of your gametree\n"\
246 "exit OpenRPG and copy the lastgood.xml file in\n"\ 256 "exit OpenRPG and copy the one of the tree-# files in\n"\
247 "your myfiles directory to "+filename+ "\n"\ 257 "your myfiles directory to "+filename+ "\n"\
248 "in your myfiles directory.\n\n"\ 258 "in your myfiles directory.\n\n"\
249 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ 259 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\
250 "Would you like to select a different gametree file to use?\n"\ 260 "Would you like to select a different gametree file to use?\n"\
251 "(Selecting 'No' will cause a new default gametree to be generated)" 261 "(Selecting 'No' will cause a new default gametree to be generated)"
252 self.locate_valid_tree("Corrupt Gametree!", emsg) 262 self.locate_valid_tree("Corrupt Gametree!", emsg, filename)
253 return 263 return
254
255 if self.xml_root.tag != "gametree": 264 if self.xml_root.tag != "gametree":
256 emsg = filename+" does not appear to be a valid gametree file.\n\n"\ 265 emsg = filename+" does not appear to be a valid gametree file.\n\n"\
257 "Would you like to select a different gametree file to use?\n"\ 266 "Would you like to select a different gametree file to use?\n"\
258 "(Selecting 'No' will cause a new default gametree to be generated)" 267 "(Selecting 'No' will cause a new default gametree to be generated)"
259 self.locate_valid_tree("Invalid Gametree!", emsg) 268 self.locate_valid_tree("Invalid Gametree!", emsg)
284 outfile.write(infile.read()) 293 outfile.write(infile.read())
285 else: logger.info("Not overwriting lastgood.xml file.", True) 294 else: logger.info("Not overwriting lastgood.xml file.", True)
286 295
287 except Exception, e: 296 except Exception, e:
288 logger.exception(traceback.format_exc()) 297 logger.exception(traceback.format_exc())
289 wx.MessageBox("Corrupt Tree!\nYour game tree is being regenerated. To\nsalvage a recent version of your gametree\nexit OpenRPG and copy the lastgood.xml\nfile in your myfiles directory\nto "+filename+ "\nin your myfiles directory.\nlastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.") 298
290 os.rename(filename,filename+".corrupt") 299 count = 1
300 while exists(filename[:len(filename)-4]+'-'+str(count)+'.xml'): count += 1
301 corrupt_tree = filename[:len(filename)-4]+'-'+str(count)+'.xml'
302 copyfile(filename, corrupt_tree)
303 wx.MessageBox("Your gametree is being regenerated.\n\n"\
304 "To salvage a recent version of your gametree\n"\
305 "exit OpenRPG and copy the one of the tree-# files in\n"\
306 "your myfiles directory to "+filename+ "\n"\
307 "in your myfiles directory.\n\n"\
308 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n")
309
310 count = 1
311 while exists(filename[:len(filename)-4]+'-'+str(count)+'.xml'): count += 1
312 corrupt_tree = filename[:len(filename)-4]+'-'+str(count)+'.xml'
313 copyfile(filename, corrupt_tree)
291 validate.config_file("tree.xml","default_tree.xml") 314 validate.config_file("tree.xml","default_tree.xml")
292 self.load_tree(error=1) 315 self.load_tree(error=1)
293 316
294 def build_std_menu(self, obj=None): 317 def build_std_menu(self, obj=None):
295 # build useful menu 318 # build useful menu