annotate orpg/dirpath/dirpath_tools.py @ 220:9611ba80cf99 alpha

Traipse Alpha 'OpenRPG' {100501-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) Moving to Beta!! 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 Updates: Update to White Board layer, uses a pencil image for color button Update to Grid Layer, uses a grid image for color button Update to Chat Window, size of drop down menus Update to default lobby message Update to template Text node Update to 4e PC Sheet node 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 Fix to Update Manager, checks for internet connection Fix to Update Manager, Auto Update corrections
author sirebral
date Sat, 01 May 2010 03:21:26 -0500
parents bf799efe7a8a
children 1df5912db00c
rev   line source
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
1 import sys
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
2 import os
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
3 import errno
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
4 from orpg.orpg_wx import *
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
5
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
6 if WXLOADED:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
7 class tmpApp(wx.App):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
8 def OnInit(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
9 return True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
10
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
11 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
12 # void load_paths( dir_struct_reference )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
13 # moved structure loading from dirpath.py by Snowdog 3-8-05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
14 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
15 def load_paths(dir_struct, root_dir):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
16 dir_struct["home"] = root_dir + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
17 dir_struct["core"] = dir_struct["home"] + "orpg"+ os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
18 dir_struct["data"] = dir_struct["home"] + "data"+ os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
19 dir_struct["d20"] = dir_struct["data"] + "d20" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
20 dir_struct["dnd3e"] = dir_struct["data"] + "dnd3e" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
21 dir_struct["dnd35"] = dir_struct["data"] + "dnd35" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
22 dir_struct["SWd20"] = dir_struct["data"] + "SWd20" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
23 dir_struct["icon"] = dir_struct["home"] + "images" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
24 dir_struct["template"] = dir_struct["core"] + "templates" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
25 dir_struct["plugins"] = dir_struct["home"] + "plugins" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
26 dir_struct["nodes"] = dir_struct["template"] + "nodes" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
27 dir_struct["rollers"] = dir_struct["core"] + "dieroller" + os.sep + "rollers" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
28
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
29 _userbase_dir = dir_struct["home"]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
30 _user_dir = dir_struct["home"] + "myfiles" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
31
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
32 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
33 os.makedirs(_user_dir)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
34 os.makedirs(_user_dir + "runlogs" + os.sep);
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
35 os.makedirs(_user_dir + "logs" + os.sep);
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
36 os.makedirs(_user_dir + "webfiles" + os.sep);
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
37 except OSError, e:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
38 if e.errno != errno.EEXIST: raise
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
39
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
40 dir_struct["user"] = _user_dir
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
41 dir_struct["logs"] = dir_struct["user"] + "logs" + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
42
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
43 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
44 # int verify_home_path( directory_name )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
45 # added by Snowdog 3-8-05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
46 # updated with bailout code. Snowdog 7-25-05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
47 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
48 def verify_home_path( path ):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
49 """checks for key ORPG files in the openrpg tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
50 and askes for user intervention if their is a problem"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
51 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
52 #verify that the root dir (as supplied) exists
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
53 if not verify_file(path): return 0
65
4840657c23c5 Traipse Dev 'OpenRPG' {090817-02}
sirebral
parents: 14
diff changeset
54
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
55 #These checks require that 'path' have a separator at the end.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
56 #Check and temporarily add one if needed
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
57 if (path[(len(path)-len(os.sep)):] != os.sep):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
58 path = path + os.sep
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
59 # These files should always exist at the root orpg dir
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
60 check_files = ["orpg","data","images"]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
61 for n in range(len(check_files)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
62 if not verify_file(path + check_files[n]): return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
63 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
64 # an error occured while verifying the directory structure
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
65 # bail out with error signal
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
66 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
67
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
68 #all files and directories exist.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
69 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
70
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
71 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
72 # int verify_file( absolute_path )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
73 # added by Snowdog 3-8-05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
74 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
75 def verify_file(abs_path):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
76 """Returns True if file or directory exists"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
77 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
78 os.stat(abs_path)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
79 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
80 except OSError:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
81 #this exception signifies the file or dir doesn't exist
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
82 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
83
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
84
65
4840657c23c5 Traipse Dev 'OpenRPG' {090817-02}
sirebral
parents: 14
diff changeset
85 #-------------------------------------------------------
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
86 # pathname get_user_help()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
87 # added by Snowdog 3-8-05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
88 # bug fix (SF #1242456) and updated with bailout code. Snowdog 7-25-05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
89 #-------------------------------------------------------
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
90 ## This can be removed in the future. TaS '09
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
91 def get_user_located_root():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
92 """Notify the user of directory problems
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
93 and show directory selection dialog """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
94
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
95 if WXLOADED:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
96 app = tmpApp(0)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
97 app.MainLoop()
65
4840657c23c5 Traipse Dev 'OpenRPG' {090817-02}
sirebral
parents: 14
diff changeset
98
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
99 dir = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
100 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
101 msg = "OpenRPG cannot locate critical files.\nPlease locate the /System/ directory in the following window"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
102 alert= wx.MessageDialog(None,msg,"Warning",wx.OK|wx.ICON_ERROR)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
103 alert.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
104 if alert.ShowModal() == wx.OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
105 alert.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
106 dlg = wx.DirDialog(None, "Locate the System directory:",style=wx.DD_DEFAULT_STYLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
107 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
108 dir = dlg.GetPath()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
109 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
110 app.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
111 return dir
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
112 except Exception, e:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
113 print e
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
114 print "OpenRPG encountered a problem while attempting to load file dialog to locate the OpenRPG root directory."
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
115 print "please delete the files ./openrpg/orpg/dirpath/aproot.py and ./openrpg/orpg/dirpath/aproot.pyc and try again."
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
116 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
117 dir = raw_input("Enter the full path to your openrpg folder: ")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
118 return dir
14
0b8b7e3ed78d Adding fixes from OpenRPG 1.8.0
sirebral
parents: 0
diff changeset
119