Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/__init__.py

    rd7bb526 refe730d  
     1import os 
     2 
     3# Set up config directories 
     4def 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 
     10def 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 
     23USER_FOLDER = make_user_folder() 
     24APP_FOLDER = find_app_folder() 
     25 
     26 
     27 
     28def get_app_dir(): 
     29    if APP_FOLDER is None: 
     30        raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") 
     31    return APP_FOLDER 
     32 
     33def 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 
     39def get_local_config(): 
     40    global _config_cache 
     41    if not _config_cache: 
     42        _config_cache = _load_config() 
     43    return _config_cache 
     44 
     45def _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.