Changeset efe730d in sasview for src/sas/sasgui/guiframe/gui_manager.py
- Timestamp:
- Jun 25, 2016 4:07:33 AM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 899e084
- Parents:
- 9501661
- git-author:
- Paul Kienzle <pkienzle@…> (06/25/16 02:23:59)
- git-committer:
- Paul Kienzle <pkienzle@…> (06/25/16 04:07:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/gui_manager.py
rc8a641e8 refe730d 23 23 warnings.simplefilter("ignore") 24 24 import logging 25 import httplib26 25 import traceback 27 26 import urllib 28 import urllib229 27 import json 30 28 29 from matplotlib import _pylab_helpers 30 31 from sas.sasgui import get_local_config, get_app_dir, get_user_dir 31 32 from sas.sasgui.guiframe.events import EVT_CATEGORY 32 33 from sas.sasgui.guiframe.events import EVT_STATUS … … 47 48 from sas.sascalc.dataloader.loader import Loader 48 49 from sas.sasgui.guiframe.proxy import Connection 49 from matplotlib import _pylab_helpers 50 51 52 def get_app_dir(): 53 """ 54 The application directory is the one where the default custom_config.py 55 file resides. 56 57 :returns: app_path - the path to the applicatin directory 58 """ 59 # First, try the directory of the executable we are running 60 app_path = sys.path[0] 61 if os.path.isfile(app_path): 62 app_path = os.path.dirname(app_path) 63 if os.path.isfile(os.path.join(app_path, "custom_config.py")): 64 app_path = os.path.abspath(app_path) 65 logging.info("Using application path: %s", app_path) 66 return app_path 67 68 # Next, try the current working directory 69 if os.path.isfile(os.path.join(os.getcwd(), "custom_config.py")): 70 logging.info("Using application path: %s", os.getcwd()) 71 return os.path.abspath(os.getcwd()) 72 73 # Finally, try the directory of the sasview module 74 # TODO: gui_manager will have to know about sasview until we 75 # clean all these module variables and put them into a config class 76 # that can be passed by sasview.py. 77 logging.info(sys.executable) 78 logging.info(str(sys.argv)) 79 from sas import sasview as sasview 80 app_path = os.path.dirname(sasview.__file__) 81 logging.info("Using application path: %s", app_path) 82 return app_path 83 84 def get_user_directory(): 85 """ 86 Returns the user's home directory 87 """ 88 userdir = os.path.join(os.path.expanduser("~"), ".sasview") 89 if not os.path.isdir(userdir): 90 os.makedirs(userdir) 91 return userdir 92 93 def _find_local_config(file, path): 94 """ 95 Find configuration file for the current application 96 """ 97 config_module = None 98 fObj = None 99 try: 100 fObj, path_config, descr = imp.find_module(file, [path]) 101 config_module = imp.load_module(file, fObj, path_config, descr) 102 except: 103 logging.error("Error loading %s/%s: %s" % (path, file, sys.exc_value)) 104 finally: 105 if fObj is not None: 106 fObj.close() 107 logging.info("GuiManager loaded %s/%s" % (path, file)) 108 return config_module 109 110 # Get APP folder 111 PATH_APP = get_app_dir() 112 DATAPATH = PATH_APP 113 114 # GUI always starts from the App folder 115 #os.chdir(PATH_APP) 116 # Read in the local config, which can either be with the main 117 # application or in the installation directory 118 config = _find_local_config('local_config', PATH_APP) 119 if config is None: 120 config = _find_local_config('local_config', os.getcwd()) 121 if config is None: 122 # Didn't find local config, load the default 123 import sas.sasgui.guiframe.config as config 124 logging.info("using default local_config") 125 else: 126 logging.info("found local_config in %s" % os.getcwd()) 127 else: 128 logging.info("found local_config in %s" % PATH_APP) 129 130 from sas.sasgui.guiframe.customdir import SetupCustom 131 c_conf_dir = SetupCustom().setup_dir(PATH_APP) 132 custom_config = _find_local_config('custom_config', c_conf_dir) 133 if custom_config is None: 134 custom_config = _find_local_config('custom_config', os.getcwd()) 135 if custom_config is None: 136 msgConfig = "Custom_config file was not imported" 137 logging.info(msgConfig) 138 else: 139 logging.info("using custom_config in %s" % os.getcwd()) 140 else: 141 logging.info("using custom_config from %s" % c_conf_dir) 50 from sas.sasgui.guiframe.customdir import setup_custom_config 51 52 config = get_local_config() 53 custom_config = setup_custom_config() 142 54 143 55 #read some constants from config … … 172 84 DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 173 85 else: 174 DEFAULT_OPEN_FOLDER = PATH_APP86 DEFAULT_OPEN_FOLDER = get_app_dir() 175 87 except: 176 88 DATALOADER_SHOW = True … … 186 98 DEFAULT_PERSPECTIVE = None 187 99 CLEANUP_PLOT = False 188 DEFAULT_OPEN_FOLDER = PATH_APP100 DEFAULT_OPEN_FOLDER = get_app_dir() 189 101 190 102 DEFAULT_STYLE = config.DEFAULT_STYLE … … 254 166 if os.path.isfile(ico_file): 255 167 self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 256 self.path = PATH_APP168 self.path = get_app_dir() 257 169 self.application_name = APPLICATION_NAME 258 170 ## Application manager … … 525 437 try: 526 438 fd = open(file_name, 'w') 527 except :439 except Exception: 528 440 # On Permission denied: IOError 529 temp_dir = get_user_dir ectory()441 temp_dir = get_user_dir() 530 442 temp_file_name = os.path.join(temp_dir, name) 531 443 fd = open(temp_file_name, 'w') … … 2061 1973 2062 1974 2063 # 1975 # import urllib2 2064 1976 # try: 2065 1977 # req = urllib2.Request(config.__update_URL__) … … 3253 3165 if basename.lower() in [app_py, app_exe, app_app, app_base]: 3254 3166 data_base = sys.argv[1] 3255 input_file = os.path.normpath(os.path.join( DATAPATH,3167 input_file = os.path.normpath(os.path.join(get_app_dir(), 3256 3168 data_base)) 3257 3169 if input_file is None: … … 3268 3180 # do it only the first time app loaded 3269 3181 # delete unused model folder 3270 model_folder = os.path.join( PATH_APP, path)3182 model_folder = os.path.join(get_app_dir(), path) 3271 3183 if os.path.exists(model_folder) and os.path.isdir(model_folder): 3272 3184 if len(os.listdir(model_folder)) > 0:
Note: See TracChangeset
for help on using the changeset viewer.