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

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since c807957 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 2.5 KB
Line 
1# Setup and find Custom config dir
2import sys
3import os.path
4import shutil
5from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller
6
7CONF_DIR = 'config' 
8APPLICATION_NAME = 'sasview'
9
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
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    """
23    u_dir = _find_usersasview_dir()
24    dir = os.path.join(u_dir, CONF_DIR)
25   
26    return dir
27
28def _setup_conf_dir(path):
29    """
30    Setup the custom config dir and cat file
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)
36    file = os.path.join(dir, "custom_config.py")
37    cat_file = CategoryInstaller.get_user_file()
38    # If the user category file doesn't exist copy the default to
39    # the user directory
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
50    # Place example user models as needed
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
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.