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 899e084 was
efe730d,
checked in by Paul Kienzle <pkienzle@…>, 9 years ago
|
move sasview to src/sas/sasview and refactor bundled apps for easier debugging
|
-
Property mode set to
100644
|
File size:
2.0 KB
|
Line | |
---|
1 | import os |
---|
2 | |
---|
3 | # Set up config directories |
---|
4 | def 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 | |
---|
10 | def 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 | |
---|
23 | USER_FOLDER = make_user_folder() |
---|
24 | APP_FOLDER = find_app_folder() |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | def get_app_dir(): |
---|
29 | if APP_FOLDER is None: |
---|
30 | raise RuntimeError("Need to initialize sas.sasgui.USER_FOLDER") |
---|
31 | return APP_FOLDER |
---|
32 | |
---|
33 | def 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 |
---|
39 | def get_local_config(): |
---|
40 | global _config_cache |
---|
41 | if not _config_cache: |
---|
42 | _config_cache = _load_config() |
---|
43 | return _config_cache |
---|
44 | |
---|
45 | def _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
TracBrowser
for help on using the repository browser.