Ignore:
Timestamp:
Jun 25, 2016 4:07:33 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
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)
Message:

move sasview to src/sas/sasview and refactor bundled apps for easier debugging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/gui_manager.py

    rc8a641e8 refe730d  
    2323warnings.simplefilter("ignore") 
    2424import logging 
    25 import httplib 
    2625import traceback 
    2726import urllib 
    28 import urllib2 
    2927import json 
    3028 
     29from matplotlib import _pylab_helpers 
     30 
     31from sas.sasgui import get_local_config, get_app_dir, get_user_dir 
    3132from sas.sasgui.guiframe.events import EVT_CATEGORY 
    3233from sas.sasgui.guiframe.events import EVT_STATUS 
     
    4748from sas.sascalc.dataloader.loader import Loader 
    4849from 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) 
     50from sas.sasgui.guiframe.customdir import setup_custom_config 
     51 
     52config = get_local_config() 
     53custom_config = setup_custom_config() 
    14254 
    14355#read some constants from config 
     
    17284        DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 
    17385    else: 
    174         DEFAULT_OPEN_FOLDER = PATH_APP 
     86        DEFAULT_OPEN_FOLDER = get_app_dir() 
    17587except: 
    17688    DATALOADER_SHOW = True 
     
    18698    DEFAULT_PERSPECTIVE = None 
    18799    CLEANUP_PLOT = False 
    188     DEFAULT_OPEN_FOLDER = PATH_APP 
     100    DEFAULT_OPEN_FOLDER = get_app_dir() 
    189101 
    190102DEFAULT_STYLE = config.DEFAULT_STYLE 
     
    254166                if os.path.isfile(ico_file): 
    255167                    self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) 
    256         self.path = PATH_APP 
     168        self.path = get_app_dir() 
    257169        self.application_name = APPLICATION_NAME 
    258170        ## Application manager 
     
    525437        try: 
    526438            fd = open(file_name, 'w') 
    527         except: 
     439        except Exception: 
    528440            # On Permission denied: IOError 
    529             temp_dir = get_user_directory() 
     441            temp_dir = get_user_dir() 
    530442            temp_file_name = os.path.join(temp_dir, name) 
    531443            fd = open(temp_file_name, 'w') 
     
    20611973         
    20621974         
    2063 #          
     1975#         import urllib2 
    20641976#         try: 
    20651977#             req = urllib2.Request(config.__update_URL__) 
     
    32533165                if basename.lower() in [app_py, app_exe, app_app, app_base]: 
    32543166                    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(), 
    32563168                                                               data_base)) 
    32573169        if input_file is None: 
     
    32683180        # do it only the first time app loaded 
    32693181        # delete unused model folder 
    3270         model_folder = os.path.join(PATH_APP, path) 
     3182        model_folder = os.path.join(get_app_dir(), path) 
    32713183        if os.path.exists(model_folder) and os.path.isdir(model_folder): 
    32723184            if len(os.listdir(model_folder)) > 0: 
Note: See TracChangeset for help on using the changeset viewer.