Ignore:
Timestamp:
May 2, 2017 10:03:50 PM (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:
a67ec83
Parents:
7c105e8
Message:

more fiddling with configs

File:
1 edited

Legend:

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

    r914ba0a rc6bdb3b  
    11# Setup and find Custom config dir 
     2from __future__ import print_function 
     3 
    24import os.path 
    35import logging 
    46import shutil 
    5 import imp 
    67 
    7 from sas.sasgui import get_custom_config_path 
     8from sasmodels.custom import load_module_from_path 
     9 
     10from sas.sasgui import get_custom_config_path, get_app_dir 
    811 
    912logger = logging.getLogger(__name__) 
     
    2225def _setup_custom_config(): 
    2326    path = get_custom_config_path() 
    24     try: 
    25         if not os.path.isfile(path): 
     27    if not os.path.isfile(path): 
     28        try: 
    2629            # if the custom config file does not exist, copy the default from 
    2730            # the app dir 
    2831            shutil.copyfile(os.path.join(get_app_dir(), "custom_config.py"), 
    2932                            path) 
    30         #Adding SAS_OPENCL if it doesn't exist in the config file 
    31         # - to support backcompability 
    32         if not "SAS_OPENCL" in open(path).read(): 
     33        except Exception: 
     34            logger.error("Could not copy default custom config.") 
     35 
     36    #Adding SAS_OPENCL if it doesn't exist in the config file 
     37    # - to support backcompability 
     38    if not "SAS_OPENCL" in open(path).read(): 
     39        try: 
    3340            open(config_file, "a+").write("SAS_OPENCL = \"None\"\n") 
    34     except Exception: 
    35         #import traceback; logging.error(traceback.format_exc()) 
    36         logger.error("Could not copy default custom config.") 
     41        except Exception: 
     42            logger.error("Could not update custom config with SAS_OPENCL.") 
    3743 
    3844    custom_config = _load_config(path) 
    3945    return custom_config 
    4046 
     47 
    4148def _load_config(path): 
    4249    if os.path.exists(path): 
    4350        try: 
    44             fObj = None 
    45             fObj, config_path, descr = imp.find_module('custom_config', [os.path.dirname(path)]) 
    46             custom_config = imp.load_module('custom_config', fObj, config_path, descr) 
    47             logger.info("GuiManager loaded %s" % config_path) 
    48             return custom_config 
    49         except Exception: 
    50             logger.error("Error loading %s: %s" % (path, sys.exc_value)) 
    51         finally: 
    52             if fObj is not None: 
    53                 fObj.close() 
     51            module = load_module_from_path('sas.sasview.custom_config', path) 
     52            logger.info("GuiManager loaded %s", path) 
     53            return module 
     54        except Exception as exc: 
     55            logger.error("Error loading %s: %s", path, exc) 
     56 
    5457    from sas.sasview import custom_config 
    55     logging.info("GuiManager custom_config defaults to sas.sasview.custom_config") 
     58    logger.info("GuiManager custom_config defaults to sas.sasview.custom_config") 
    5659    return custom_config 
Note: See TracChangeset for help on using the changeset viewer.