source: sasview/sansguiframe/src/sans/guiframe/customdir.py @ 2365c0b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2365c0b was 8ab3302, checked in by Jae Cho <jhjcho@…>, 13 years ago

fixed a little bit the setting of .sansview folder

  • Property mode set to 100644
File size: 1.7 KB
Line 
1# Setup and find Custom config dir
2import sys
3import os.path
4import shutil
5
6CONF_DIR = 'config' 
7APPLICATION_NAME = 'sansview'
8
9def _find_customconf_dir():
10    """
11    Find path of the config directory.
12    The plugin directory is located in the user's home directory.
13    """
14    dir = os.path.join(os.path.expanduser("~"), 
15                       ("." + APPLICATION_NAME), CONF_DIR)
16   
17    return dir
18
19def _setup_conf_dir(path):
20    """
21    Setup the custom config dir
22    """
23    dir = _find_customconf_dir()
24    # If the plugin directory doesn't exist, create it
25    if not os.path.isdir(dir):
26        os.makedirs(dir)
27    file = os.path.join(dir, "custom_config.py")
28    # Place example user models as needed
29    try:
30        if not os.path.isfile(file):
31         shutil.copyfile(os.path.join(path, "custom_config.py"), file)
32    except:
33        # Check for data path next to exe/zip file.
34        #Look for maximum n_dir up of the current dir to find plugins dir
35        n_dir = 12
36        is_dir = False
37        f_dir = path
38        for i in range(n_dir):
39            if i > 1:
40                f_dir, _ = os.path.split(f_dir)
41            temp_path = os.path.join(f_dir, "custom_config.py")
42            if os.path.isfile(temp_path):
43                shutil.copyfile(temp_path, file)
44                is_dir = True
45                break
46        if not is_dir:
47            raise
48       
49    return dir
50 
51       
52class SetupCustom(object):
53    """
54    implement custom config dir
55    """
56    def find_dir(self):
57        return _find_customconf_dir()
58   
59    def setup_dir(self, path):
60        return _setup_conf_dir(path)
61   
62
63   
64   
65 
Note: See TracBrowser for help on using the repository browser.