248
|
1 import sys, os, errno
|
156
|
2
|
|
3 #-------------------------------------------------------
|
|
4 # void load_paths( dir_struct_reference )
|
|
5 # moved structure loading from dirpath.py by Snowdog 3-8-05
|
|
6 #-------------------------------------------------------
|
|
7 def load_paths(dir_struct, root_dir):
|
|
8 dir_struct["home"] = root_dir + os.sep
|
|
9 dir_struct["core"] = dir_struct["home"] + "orpg"+ os.sep
|
|
10 dir_struct["data"] = dir_struct["home"] + "data"+ os.sep
|
|
11 dir_struct["d20"] = dir_struct["data"] + "d20" + os.sep
|
|
12 dir_struct["dnd3e"] = dir_struct["data"] + "dnd3e" + os.sep
|
|
13 dir_struct["dnd35"] = dir_struct["data"] + "dnd35" + os.sep
|
|
14 dir_struct["SWd20"] = dir_struct["data"] + "SWd20" + os.sep
|
|
15 dir_struct["icon"] = dir_struct["home"] + "images" + os.sep
|
|
16 dir_struct["template"] = dir_struct["core"] + "templates" + os.sep
|
|
17 dir_struct["plugins"] = dir_struct["home"] + "plugins" + os.sep
|
|
18 dir_struct["nodes"] = dir_struct["template"] + "nodes" + os.sep
|
|
19 dir_struct["rollers"] = dir_struct["core"] + "dieroller" + os.sep + "rollers" + os.sep
|
|
20
|
|
21 _userbase_dir = dir_struct["home"]
|
|
22 _user_dir = dir_struct["home"] + "myfiles" + os.sep
|
|
23
|
|
24 try:
|
|
25 os.makedirs(_user_dir)
|
|
26 os.makedirs(_user_dir + "runlogs" + os.sep);
|
|
27 os.makedirs(_user_dir + "logs" + os.sep);
|
|
28 os.makedirs(_user_dir + "webfiles" + os.sep);
|
|
29 except OSError, e:
|
|
30 if e.errno != errno.EEXIST: raise
|
|
31
|
|
32 dir_struct["user"] = _user_dir
|
|
33 dir_struct["logs"] = dir_struct["user"] + "logs" + os.sep
|
|
34
|
|
35 #-------------------------------------------------------
|
|
36 # int verify_home_path( directory_name )
|
|
37 # added by Snowdog 3-8-05
|
|
38 # updated with bailout code. Snowdog 7-25-05
|
|
39 #-------------------------------------------------------
|
|
40 def verify_home_path( path ):
|
|
41 """checks for key ORPG files in the openrpg tree
|
|
42 and askes for user intervention if their is a problem"""
|
|
43 try:
|
|
44 #verify that the root dir (as supplied) exists
|
|
45 if not verify_file(path): return 0
|
65
|
46
|
156
|
47 #These checks require that 'path' have a separator at the end.
|
|
48 #Check and temporarily add one if needed
|
|
49 if (path[(len(path)-len(os.sep)):] != os.sep):
|
|
50 path = path + os.sep
|
|
51 # These files should always exist at the root orpg dir
|
|
52 check_files = ["orpg","data","images"]
|
|
53 for n in range(len(check_files)):
|
|
54 if not verify_file(path + check_files[n]): return 0
|
|
55 except:
|
|
56 # an error occured while verifying the directory structure
|
|
57 # bail out with error signal
|
|
58 return 0
|
|
59
|
|
60 #all files and directories exist.
|
|
61 return 1
|
|
62
|
|
63 #-------------------------------------------------------
|
|
64 # int verify_file( absolute_path )
|
|
65 # added by Snowdog 3-8-05
|
|
66 #-------------------------------------------------------
|
|
67 def verify_file(abs_path):
|
|
68 """Returns True if file or directory exists"""
|
|
69 try:
|
|
70 os.stat(abs_path)
|
|
71 return 1
|
|
72 except OSError:
|
|
73 #this exception signifies the file or dir doesn't exist
|
|
74 return 0
|
|
75
|
|
76
|
65
|
77 #-------------------------------------------------------
|
156
|
78 # pathname get_user_help()
|
|
79 # added by Snowdog 3-8-05
|
|
80 # bug fix (SF #1242456) and updated with bailout code. Snowdog 7-25-05
|
|
81 #-------------------------------------------------------
|
|
82 ## This can be removed in the future. TaS '09
|
|
83 def get_user_located_root():
|
|
84 """Notify the user of directory problems
|
|
85 and show directory selection dialog """
|
|
86
|
248
|
87 #from orpg.orpg_wx import *
|
|
88
|
156
|
89 if WXLOADED:
|
|
90 app = tmpApp(0)
|
|
91 app.MainLoop()
|
65
|
92
|
156
|
93 dir = None
|
|
94 try:
|
|
95 msg = "OpenRPG cannot locate critical files.\nPlease locate the /System/ directory in the following window"
|
|
96 alert= wx.MessageDialog(None,msg,"Warning",wx.OK|wx.ICON_ERROR)
|
|
97 alert.Show()
|
|
98 if alert.ShowModal() == wx.OK:
|
|
99 alert.Destroy()
|
|
100 dlg = wx.DirDialog(None, "Locate the System directory:",style=wx.DD_DEFAULT_STYLE)
|
|
101 if dlg.ShowModal() == wx.ID_OK:
|
|
102 dir = dlg.GetPath()
|
|
103 dlg.Destroy()
|
|
104 app.Destroy()
|
|
105 return dir
|
|
106 except Exception, e:
|
|
107 print e
|
|
108 print "OpenRPG encountered a problem while attempting to load file dialog to locate the OpenRPG root directory."
|
|
109 print "please delete the files ./openrpg/orpg/dirpath/aproot.py and ./openrpg/orpg/dirpath/aproot.pyc and try again."
|
|
110 else:
|
|
111 dir = raw_input("Enter the full path to your openrpg folder: ")
|
|
112 return dir
|
14
|
113
|