annotate orpg/dirpath/dirpath_tools.py @ 155:bf799efe7a8a alpha

Traipse Alpha 'OpenRPG' {091125-02} 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 (Cleaning up for 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 Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 12:32:34 -0600
parents 4840657c23c5
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