annotate orpg/dirpath/dirpath_tools.py @ 248:1df5912db00c beta tip

Traipse Beta 'OpenRPG' {101205-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 (Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log New Earthdawn Dieroller New IronClaw roller, sheet, and image New ShapeShifter PC Sheet Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner Update to Dieroller. Cleaner, more effecient expression system Update to Hidden Die plugin, allows for non standard dice rolls Update to location.py, allows for more portable references when starting Traipse Update to the Features node Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to Server, removing wxPython dependencies where not needed Fix to metaservers.xml file not being created Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug Fix to Gametree for XSLT Sheets Fix to Gametree for locating gametree files Fix to Send to Chat from Gametree Fix to Gametree, renaming and remapping operates correctly Fix to aliaslib, prevents error caused when SafeHTML is sent None
author sirebral
date Sun, 05 Dec 2010 10:53:30 -0600
parents 3b6888bb53b5
children
rev   line source
248
1df5912db00c Traipse Beta 'OpenRPG' {101205-00}
sirebral
parents: 156
diff changeset
1 import sys, os, errno
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
2
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
3 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
4 # void load_paths( dir_struct_reference )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
5 # moved structure loading from dirpath.py by Snowdog 3-8-05
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
6 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
7 def load_paths(dir_struct, root_dir):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
8 dir_struct["home"] = root_dir + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
9 dir_struct["core"] = dir_struct["home"] + "orpg"+ os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
10 dir_struct["data"] = dir_struct["home"] + "data"+ os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
11 dir_struct["d20"] = dir_struct["data"] + "d20" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
12 dir_struct["dnd3e"] = dir_struct["data"] + "dnd3e" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
13 dir_struct["dnd35"] = dir_struct["data"] + "dnd35" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
14 dir_struct["SWd20"] = dir_struct["data"] + "SWd20" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
15 dir_struct["icon"] = dir_struct["home"] + "images" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
16 dir_struct["template"] = dir_struct["core"] + "templates" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
17 dir_struct["plugins"] = dir_struct["home"] + "plugins" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
18 dir_struct["nodes"] = dir_struct["template"] + "nodes" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
19 dir_struct["rollers"] = dir_struct["core"] + "dieroller" + os.sep + "rollers" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
20
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
21 _userbase_dir = dir_struct["home"]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
22 _user_dir = dir_struct["home"] + "myfiles" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
23
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
24 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
25 os.makedirs(_user_dir)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
26 os.makedirs(_user_dir + "runlogs" + os.sep);
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
27 os.makedirs(_user_dir + "logs" + os.sep);
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
28 os.makedirs(_user_dir + "webfiles" + os.sep);
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
29 except OSError, e:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
30 if e.errno != errno.EEXIST: raise
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
31
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
32 dir_struct["user"] = _user_dir
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
33 dir_struct["logs"] = dir_struct["user"] + "logs" + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
34
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
35 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
36 # int verify_home_path( directory_name )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
37 # added by Snowdog 3-8-05
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
38 # updated with bailout code. Snowdog 7-25-05
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
39 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
40 def verify_home_path( path ):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
41 """checks for key ORPG files in the openrpg tree
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
42 and askes for user intervention if their is a problem"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
43 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
44 #verify that the root dir (as supplied) exists
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
45 if not verify_file(path): return 0
65
4840657c23c5 Traipse Dev 'OpenRPG' {090817-02}
sirebral
parents: 14
diff changeset
46
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
47 #These checks require that 'path' have a separator at the end.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
48 #Check and temporarily add one if needed
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
49 if (path[(len(path)-len(os.sep)):] != os.sep):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
50 path = path + os.sep
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
51 # These files should always exist at the root orpg dir
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
52 check_files = ["orpg","data","images"]
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
53 for n in range(len(check_files)):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
54 if not verify_file(path + check_files[n]): return 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
55 except:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
56 # an error occured while verifying the directory structure
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
57 # bail out with error signal
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
58 return 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
59
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
60 #all files and directories exist.
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
61 return 1
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
62
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
63 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
64 # int verify_file( absolute_path )
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
65 # added by Snowdog 3-8-05
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
66 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
67 def verify_file(abs_path):
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
68 """Returns True if file or directory exists"""
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
69 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
70 os.stat(abs_path)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
71 return 1
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
72 except OSError:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
73 #this exception signifies the file or dir doesn't exist
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
74 return 0
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
75
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
76
65
4840657c23c5 Traipse Dev 'OpenRPG' {090817-02}
sirebral
parents: 14
diff changeset
77 #-------------------------------------------------------
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
78 # pathname get_user_help()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
79 # added by Snowdog 3-8-05
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
80 # bug fix (SF #1242456) and updated with bailout code. Snowdog 7-25-05
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
81 #-------------------------------------------------------
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
82 ## This can be removed in the future. TaS '09
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
83 def get_user_located_root():
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
84 """Notify the user of directory problems
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
85 and show directory selection dialog """
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
86
248
1df5912db00c Traipse Beta 'OpenRPG' {101205-00}
sirebral
parents: 156
diff changeset
87 #from orpg.orpg_wx import *
1df5912db00c Traipse Beta 'OpenRPG' {101205-00}
sirebral
parents: 156
diff changeset
88
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
89 if WXLOADED:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
90 app = tmpApp(0)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
91 app.MainLoop()
65
4840657c23c5 Traipse Dev 'OpenRPG' {090817-02}
sirebral
parents: 14
diff changeset
92
156
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
93 dir = None
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
94 try:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
95 msg = "OpenRPG cannot locate critical files.\nPlease locate the /System/ directory in the following window"
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
96 alert= wx.MessageDialog(None,msg,"Warning",wx.OK|wx.ICON_ERROR)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
97 alert.Show()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
98 if alert.ShowModal() == wx.OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
99 alert.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
100 dlg = wx.DirDialog(None, "Locate the System directory:",style=wx.DD_DEFAULT_STYLE)
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
101 if dlg.ShowModal() == wx.ID_OK:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
102 dir = dlg.GetPath()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
103 dlg.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
104 app.Destroy()
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
105 return dir
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
106 except Exception, e:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
107 print e
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
108 print "OpenRPG encountered a problem while attempting to load file dialog to locate the OpenRPG root directory."
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
109 print "please delete the files ./openrpg/orpg/dirpath/aproot.py and ./openrpg/orpg/dirpath/aproot.pyc and try again."
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
110 else:
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
111 dir = raw_input("Enter the full path to your openrpg folder: ")
3b6888bb53b5 Traipse Beta 'OpenRPG' {091125-02}
sirebral
parents: 65
diff changeset
112 return dir
14
0b8b7e3ed78d Adding fixes from OpenRPG 1.8.0
sirebral
parents: 0
diff changeset
113