source: sasview/sansguiframe/src/sans/guiframe/customdir.py @ 6d4df13

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 6d4df13 was ea5fa58, checked in by Jae Cho <jhjcho@…>, 12 years ago

category stuffs start working in interp. environment

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[493c90c]1# Setup and find Custom config dir
2import sys
3import os.path
4import shutil
[ea5fa58]5from sans.guiframe.CategoryInstaller import CategoryInstaller
[74b5523]6
[493c90c]7CONF_DIR = 'config' 
[94d6752]8APPLICATION_NAME = 'sasview'
[493c90c]9
[ea5fa58]10def _find_usersasview_dir():
11    """
12    Find and return user/.sasview dir
13    """
14    dir = os.path.join(os.path.expanduser("~"), 
15                       ("." + APPLICATION_NAME))
16    return dir
17
[493c90c]18def _find_customconf_dir():
19    """
20    Find path of the config directory.
21    The plugin directory is located in the user's home directory.
22    """
[ea5fa58]23    u_dir = _find_usersasview_dir()
24    dir = os.path.join(u_dir, CONF_DIR)
[493c90c]25   
26    return dir
27
28def _setup_conf_dir(path):
29    """
[ea5fa58]30    Setup the custom config dir and cat file
[493c90c]31    """
32    dir = _find_customconf_dir()
33    # If the plugin directory doesn't exist, create it
34    if not os.path.isdir(dir):
35        os.makedirs(dir)
[f9505c30]36    file = os.path.join(dir, "custom_config.py")
[ea5fa58]37    u_dir = _find_usersasview_dir()
38    cat_file = os.path.join(u_dir, "serialized_cat.p")
39    # Place example user models as needed
40    if not os.path.isfile(cat_file):
41        try:
42            default_cat_file = CategoryInstaller.get_default_file()
43            if os.path.isfile(default_cat_file):
44                shutil.copyfile(default_cat_file, cat_file)
45            else:
46                print "Unable to find/copy default cat file"
47        except:
48            print "Unable to copy default cat file to the user dir."
49
[493c90c]50    # Place example user models as needed
[8ab3302]51    try:
52        if not os.path.isfile(file):
53         shutil.copyfile(os.path.join(path, "custom_config.py"), file)
54    except:
55        # Check for data path next to exe/zip file.
56        #Look for maximum n_dir up of the current dir to find plugins dir
57        n_dir = 12
58        is_dir = False
59        f_dir = path
60        for i in range(n_dir):
61            if i > 1:
62                f_dir, _ = os.path.split(f_dir)
63            temp_path = os.path.join(f_dir, "custom_config.py")
64            if os.path.isfile(temp_path):
65                shutil.copyfile(temp_path, file)
66                is_dir = True
67                break
68        if not is_dir:
69            raise
[493c90c]70       
71    return dir
72 
73       
74class SetupCustom(object):
75    """
76    implement custom config dir
77    """
78    def find_dir(self):
79        return _find_customconf_dir()
80   
81    def setup_dir(self, path):
82        return _setup_conf_dir(path)
83   
84
85   
86   
87 
Note: See TracBrowser for help on using the repository browser.