[Winopenrpg-developer] openrpg1/orpg/dirpath __init__.py,NONE,1.1 dirpath_tools.py,NONE,1.1
Status: Inactive
Brought to you by:
digitalxero
|
From: Digital X. <dig...@us...> - 2006-01-26 17:33:24
|
Update of /cvsroot/winopenrpg/openrpg1/orpg/dirpath In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30930/orpg/dirpath Added Files: __init__.py dirpath_tools.py Log Message: Initial commit of OpenRPG++ python --- NEW FILE: dirpath_tools.py --- import sys import os from orpg.orpg_wx import * class tmpApp(wxApp): def OnInit(self): return true #------------------------------------------------------- # void load_paths( dir_struct_reference ) # moved structure loading from dirpath.py by Snowdog 3-8-05 #------------------------------------------------------- def load_paths(dir_struct, root_dir): dir_struct["home"] = root_dir + os.sep dir_struct["core"] = dir_struct["home"] + "orpg"+ os.sep dir_struct["data"] = dir_struct["home"]+ "data"+ os.sep dir_struct["d20"] = dir_struct["data"]+"d20"+ os.sep dir_struct["dnd3e"] = dir_struct["data"]+"dnd3e"+ os.sep dir_struct["SWd20"] = dir_struct["data"]+"SWd20"+ os.sep dir_struct["icon"] = dir_struct["home"]+"images"+ os.sep dir_struct["template"] = dir_struct["core"]+"templates"+ os.sep dir_struct["user"] = dir_struct["home"]+ "myfiles"+ os.sep dir_struct["plugins"] = dir_struct["home"]+ "plugins"+ os.sep dir_struct["nodes"] = dir_struct["template"]+"nodes"+ os.sep dir_struct["logs"] = dir_struct["user"]+"logs"+ os.sep # backward compatiablity dir_struct["addon"] = dir_struct["template"]+"nodes"+ os.sep #------------------------------------------------------- # int verify_home_path( directory_name ) # added by Snowdog 3-8-05 # updated with bailout code. Snowdog 7-25-05 #------------------------------------------------------- def verify_home_path( path ): """checks for key ORPG files in the openrpg tree and askes for user intervention if their is a problem""" try: #verify that the root dir (as supplied) exists if not verify_file(path): return 0 #These checks require that 'path' have a separator at the end. #Check and temporarily add one if needed if (path[(len(path)-len(os.sep)):] != os.sep): path=path+os.sep # These files should always exist at the root orpg dir check_files=["start.py","platform.py","pyver.py"] for n in range(len(check_files)): if not verify_file(path+check_files[n]): return 0 # These directories should always exist at the root orpg dir check_dirs=["orpg","data","images"] for n in range(len(check_dirs)): if not verify_file(path+check_dirs[n]): return 0 except: # an error occured while verifying the directory structure # bail out with error signal return 0 #all files and directories exist. write_approot(path) return 1 #------------------------------------------------------- # int verify_file( absolute_path ) # added by Snowdog 3-8-05 #------------------------------------------------------- def verify_file(abs_path): """Returns true if file or directory exists""" try: os.stat(abs_path) return 1 except OSError: #this exception signifies the file or dir doesn't exist return 0 #------------------------------------------------------- # pathname get_user_help() # added by Snowdog 3-8-05 # bug fix (SF #1242456) and updated with bailout code. Snowdog 7-25-05 #------------------------------------------------------- def get_user_located_root(): """Notify the user of directory problems and show directory selection dialog """ app = tmpApp(0) app.MainLoop() dir = None try: msg = "OpenRPG cannot locate critical files.\nPlease locate the openrpg1 directory in the following window" alert= wxMessageDialog(None,msg,"Warning",wxOK|wxICON_ERROR) alert.Show() if alert.ShowModal() == wxOK: alert.Destroy() dlg = wxDirDialog(None, "Locate the openrpg1 directory:",style=wxDD_DEFAULT_STYLE) if dlg.ShowModal() == wxID_OK: dir = dlg.GetPath() dlg.Destroy() app.Destroy() return dir except Exception, e: print e print "OpenRPG encountered a problem while attempting to load file dialog to locate the OpenRPG root directory." print "please delete the files ./openrpg/orpg/dirpath/aproot.py and ./openrpg/orpg/dirpath/aproot.pyc and try again." #------------------------------------------------------- # void write_approot( orpg_root_path ) # added by snowdog 3-10-05 #------------------------------------------------------- def write_approot( orpg_root_path): try: #if a trailing path separator is on the path string remove it. if (orpg_root_path[(len(orpg_root_path)-len(os.sep)):] == os.sep): orpg_root_path = orpg_root_path[:(len(orpg_root_path)-len(os.sep))] fn = orpg_root_path+os.sep+"orpg"+os.sep+"dirpath"+os.sep+"approot.py" f = open( fn, "w") #trim off the appended os.sep character(s) to avoid duplicating them on re-loading of path code="basedir = \""+orpg_root_path+"\"\n" #fix path string for windows boxes that lamely use an escape character for a path separator code = str.replace(code,'\\','\\\\') f.write(code) f.close() except IOError: print "[WARNING] Could not create approot file." print "[WARNING] Automatic directory resolution not configured." return --- NEW FILE: __init__.py --- # Old dirpath.py replaced with new dirpath 'package/module' to allow dynamic # checking on directory structure at dirpath import without requiring alteration # of almost every openrpg1 python file # # This module is functionally identical to the dirpath.py file it replaces. # All directory locations are now handled by the load_paths() function # in the dirpath_tools.py file -- Snowdog 3-8-05 # CHANGE LOG # ----------------------------- # * Reworked path verification process to attempt to fall back on the # current working directory if approot fails to verify before # asking the user to locate the root directory -- Snowdog 12-20-05 import sys import os from dirpath_tools import * root_dir = None try: import approot root_dir = approot.basedir except: #attempt to load default path root_dir = os.getcwd() #default ORPG root dir dir_struct = {} if not verify_home_path(root_dir): root_dir = os.getcwd() if not verify_home_path(root_dir): root_dir = get_user_located_root() while not verify_home_path(root_dir): root_dir = get_user_located_root() #switch backslashes to forward slashes just for display on screen only (avoids issues with escaped characters) clean = str(root_dir) clean = str.replace(clean,'\\','/') print "Rooting OpenRPG at: "+clean load_paths(dir_struct, root_dir) |