source: sasview/src/sas/sasgui/guiframe/customdir.py @ c6bdb3b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since c6bdb3b was c6bdb3b, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

more fiddling with configs

  • Property mode set to 100644
File size: 1.7 KB
Line 
1# Setup and find Custom config dir
2from __future__ import print_function
3
4import os.path
5import logging
6import shutil
7
8from sasmodels.custom import load_module_from_path
9
10from sas.sasgui import get_custom_config_path, get_app_dir
11
12logger = logging.getLogger(__name__)
13
14_config_cache = None
15def setup_custom_config():
16    """
17    Setup the custom config dir and cat file
18    """
19    global _config_cache
20    if not _config_cache:
21        _config_cache = _setup_custom_config()
22    return _config_cache
23
24
25def _setup_custom_config():
26    path = get_custom_config_path()
27    if not os.path.isfile(path):
28        try:
29            # if the custom config file does not exist, copy the default from
30            # the app dir
31            shutil.copyfile(os.path.join(get_app_dir(), "custom_config.py"),
32                            path)
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:
40            open(config_file, "a+").write("SAS_OPENCL = \"None\"\n")
41        except Exception:
42            logger.error("Could not update custom config with SAS_OPENCL.")
43
44    custom_config = _load_config(path)
45    return custom_config
46
47
48def _load_config(path):
49    if os.path.exists(path):
50        try:
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
57    from sas.sasview import custom_config
58    logger.info("GuiManager custom_config defaults to sas.sasview.custom_config")
59    return custom_config
Note: See TracBrowser for help on using the repository browser.