Changeset d81008e in sasview for sansguiframe/src


Ignore:
Timestamp:
Aug 10, 2011 9:15:56 AM (13 years ago)
Author:
Gervaise Alina <gervyh@…>
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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
51db68f
Parents:
ff06528
Message:

refactore import config code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansguiframe/src/sans/guiframe/gui_manager.py

    rc642155 rd81008e  
    1616import sys 
    1717import xml 
    18  
    19  
     18import py_compile 
    2019# Try to find a local config 
    2120import imp 
    22 DATAPATH = os.getcwd() 
    23 tem_path = sys.path[0] 
    24 if os.path.isfile(tem_path): 
    25     tem_path = os.path.dirname(tem_path) 
    26 os.chdir(tem_path) 
    27 PATH_APP = os.getcwd() 
    28 if(os.path.isfile("%s/%s.py" % (PATH_APP, 'local_config'))) or \ 
    29     (os.path.isfile("%s/%s.pyc" % (PATH_APP, 'local_config'))): 
    30     fObj, path_config, descr = imp.find_module('local_config', [PATH_APP]) 
    31     try: 
    32         config = imp.load_module('local_config', fObj, path_config, descr)  
    33     except: 
    34         # Didn't find local config, load the default  
    35         import config 
    36     finally: 
    37         if fObj: 
    38             fObj.close() 
    39 else: 
    40     # Try simply importing local_config 
    41     import local_config as config 
    42  
    43 #import compileall 
    44 import py_compile 
    45  
    46 c_name = os.path.join(PATH_APP, 'custom_config.py') 
    47 if(os.path.isfile("%s/%s.py" % (PATH_APP, 'custom_config'))): 
    48     py_compile.compile(file=c_name) 
    49     #compileall.compile_dir(dir=path, force=True, quiet=0) 
    50     cfObj, path_cconfig, descr = imp.find_module('custom_config', [PATH_APP])  
    51 try: 
    52     custom_config = imp.load_module('custom_config', cfObj, PATH_APP, descr) 
    53 except: 
    54     custom_config = None 
    55 finally: 
    56     if custom_config != None: 
    57         cfObj.close() 
    58  
    59      
    6021import warnings 
    6122warnings.simplefilter("ignore") 
    62  
    6323import logging 
    6424 
     
    7939from sans.dataloader.loader import Loader 
    8040 
     41DATAPATH = os.getcwd() 
     42tem_path = sys.path[0] 
     43if os.path.isfile(tem_path): 
     44    tem_path = os.path.dirname(tem_path) 
     45os.chdir(tem_path) 
     46PATH_APP = os.getcwd() 
     47 
     48def _find_local_config(file, path): 
     49    """ 
     50    Find configuration file for the current application 
     51    """ 
     52     
     53    file_path = os.path.abspath(os.path.join(path, "%s.py" % file)) 
     54    if(os.path.isfile(file_path)): 
     55        py_compile.compile(file=file_path) 
     56        fObj, path_config, descr = imp.find_module(file, [path]) 
     57        try: 
     58            return imp.load_module(file, fObj, path_config, descr)  
     59        except: 
     60            raise 
     61        finally: 
     62            if fObj: 
     63                fObj.close() 
     64         
     65               
     66try: 
     67    path = PATH_APP 
     68    config = _find_local_config('local_config', path) 
     69    if config is None: 
     70        path, _ = os.path.split(PATH_APP) 
     71        config = _find_local_config('local_config', path) 
     72except: 
     73    # Didn't find local config, load the default  
     74    import sans.guiframe.config as config 
     75try: 
     76    path = PATH_APP 
     77    custom_config = _find_local_config('custom_config', path) 
     78    if custom_config is None: 
     79        path, _ = os.path.split(PATH_APP) 
     80        custom_config = _find_local_config('custom_config', path) 
     81except: 
     82    msg = "Custom_config file was not imported" 
     83    logging.info(msg) 
     84     
    8185 
    8286#read some constants from config 
Note: See TracChangeset for help on using the changeset viewer.