Changeset efe730d in sasview for src/sas/sasgui/__init__.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/__init__.py
rd7bb526 refe730d 1 import os 2 3 # Set up config directories 4 def make_user_folder(): 5 path = os.path.join(os.path.expanduser("~"),'.sasview') 6 if not os.path.exists(path): 7 os.mkdir(path) 8 return path 9 10 def find_app_folder(): 11 # If the directory containing sasview.py exists, then we are not running 12 # frozen and the current path is the app path. 13 root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 14 path = os.path.join(root, 'sasview') 15 if os.path.exists(path): 16 return path 17 18 # If we are running frozen, then skip from: 19 # library.zip/sas/sasview 20 path = os.path.dirname(os.path.dirname(root)) 21 return path 22 23 USER_FOLDER = make_user_folder() 24 APP_FOLDER = find_app_folder() 25 26 27 28 def get_app_dir(): 29 if APP_FOLDER is None: 30 raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 31 return APP_FOLDER 32 33 def get_user_dir(): 34 if USER_FOLDER is None: 35 raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 36 return USER_FOLDER 37 38 _config_cache = None 39 def get_local_config(): 40 global _config_cache 41 if not _config_cache: 42 _config_cache = _load_config() 43 return _config_cache 44 45 def _load_config(): 46 import os 47 import sys 48 import imp 49 import logging 50 51 dirname = get_app_dir() 52 filename = 'local_config.py' 53 path = os.path.join(dirname, filename) 54 if os.path.exists(path): 55 try: 56 fObj = None 57 fObj, config_path, descr = imp.find_module('local_config', [APP_FOLDER]) 58 config = imp.load_module('local_config', fObj, config_path, descr) 59 logging.info("GuiManager loaded %s" % config_path) 60 return config 61 except Exception: 62 import traceback; logging.error(traceback.format_exc()) 63 logging.error("Error loading %s: %s" % (path, sys.exc_value)) 64 finally: 65 if fObj is not None: 66 fObj.close() 67 from sas.sasgui.guiframe import config 68 logging.info("GuiManager config defaults to sas.sasgui.guiframe") 69 return config
Note: See TracChangeset
for help on using the changeset viewer.