Changeset 212bfc2 in sasview
- Timestamp:
- Oct 7, 2016 3:11:40 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b61bd57
- Parents:
- 60df6c1
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/CategoryInstaller.py
r50008e3 r212bfc2 11 11 import os 12 12 import sys 13 import shutil14 13 import json 15 from collections import defaultdict 14 import logging 15 from collections import defaultdict, OrderedDict 16 16 17 17 USER_FILE = 'categories.json' … … 23 23 Note - class is entirely static! 24 24 """ 25 26 25 27 26 def __init__(self): … … 43 42 import sas.sasgui.perspectives.fitting.models 44 43 return sas.sasgui.perspectives.fitting.models.get_model_python_path() 45 44 46 45 @staticmethod 47 46 def _get_default_cat_file_dir(): … … 54 53 import sas.sasview 55 54 cat_file = "default_categories.json" 56 55 57 56 possible_cat_file_paths = [ 58 57 os.path.join(os.path.split(sas.sasview.__file__)[0], cat_file), # Source … … 64 63 if os.path.isfile(path): 65 64 return os.path.dirname(path) 66 65 67 66 raise RuntimeError('CategoryInstaller: Could not find folder containing default categories') 68 67 … … 89 88 by_model_dict[model].append(category) 90 89 model_enabled_dict[model] = enabled 91 90 92 91 return (by_model_dict, model_enabled_dict) 93 94 92 95 93 @staticmethod … … 105 103 master_category_dict[category].append(\ 106 104 (model, model_enabled_dict[model])) 107 108 return master_category_dict 105 return OrderedDict(sorted(master_category_dict.items(), key=lambda t: t[0])) 109 106 110 107 @staticmethod … … 113 110 returns the user data file, eg .sasview/categories.json.json 114 111 """ 115 return os.path.join(CategoryInstaller._get_home_dir(), 116 USER_FILE) 112 return os.path.join(CategoryInstaller._get_home_dir(), USER_FILE) 117 113 118 114 @staticmethod 119 115 def get_default_file(): 120 """ 121 returns the path of the default file 122 e.g. blahblah/default_categories.json 123 """ 124 return os.path.join(\ 125 CategoryInstaller._get_default_cat_file_dir(), "default_categories.json") 126 116 logging.warning("CategoryInstaller.get_default_file is deprecated.") 117 127 118 @staticmethod 128 119 def check_install(homedir = None, model_list=None): … … 134 125 :param model_list: List of model names except customized models 135 126 """ 136 #model_list = [] 137 default_file = CategoryInstaller.get_default_file() 127 _model_dict = { model.name: model for model in model_list} 128 _model_list = _model_dict.keys() 129 138 130 serialized_file = None 139 master_category_dict = defaultdict(list)140 131 if homedir == None: 141 132 serialized_file = CategoryInstaller.get_user_file() … … 143 134 serialized_file = os.path.join(homedir, USER_FILE) 144 135 if os.path.isfile(serialized_file): 145 cat_file = open(serialized_file, 'rb') 136 with open(serialized_file, 'rb') as f: 137 master_category_dict = json.load(f) 146 138 else: 147 cat_file = open(default_file, 'rb') 148 master_category_dict = json.load(cat_file) 149 # master_category_dict = pickle.Unpickler(cat_file).load() 139 master_category_dict = defaultdict(list) 140 150 141 (by_model_dict, model_enabled_dict) = \ 151 142 CategoryInstaller._regenerate_model_dict(master_category_dict) 152 cat_file.close() 153 add_list = model_list 143 add_list = _model_list 154 144 del_name = False 155 145 for cat in master_category_dict.keys(): 156 146 for ind in range(len(master_category_dict[cat])): 157 147 model_name, enabled = master_category_dict[cat][ind] 158 if model_name not in model_list:148 if model_name not in _model_list: 159 149 del_name = True 160 150 try: … … 162 152 model_enabled_dict.pop(model_name) 163 153 except: 164 pass154 logging.error("CategoryInstaller: %s", sys.exc_value) 165 155 else: 166 156 add_list.remove(model_name) … … 168 158 for model in add_list: 169 159 model_enabled_dict[model]= True 170 by_model_dict[model].append('Uncategorized') 171 160 if _model_dict[model].category is None or len(str(_model_dict[model].category.capitalize())) == 0: 161 by_model_dict[model].append('Uncategorized') 162 else: 163 category = _model_dict[model].category 164 toks = category.split(':') 165 category = toks[-1] 166 toks = category.split('-') 167 capitalized_words = [t.capitalize() for t in toks] 168 category = ' '.join(capitalized_words) 169 170 by_model_dict[model].append(category) 171 172 172 master_category_dict = \ 173 173 CategoryInstaller._regenerate_master_dict(by_model_dict, 174 174 model_enabled_dict) 175 176 json.dump( master_category_dict, 177 open(serialized_file, 'wb') ) 175 176 json.dump(master_category_dict, open(serialized_file, 'wb')) -
src/sas/sasgui/guiframe/CategoryManager.py
r80b1df3 r212bfc2 13 13 import sys 14 14 import os 15 import logging 15 16 from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin 16 17 from collections import defaultdict … … 366 367 """ 367 368 try: 368 file = CategoryInstaller.get_user_file() 369 if os.path.isfile(file): 370 cat_file = open(file, 'rb') 371 # self.master_category_dict = pickle.load(cat_file) 372 self.master_category_dict = json.load(cat_file) 373 else: 374 cat_file = open(CategoryInstaller.get_default_file(), 'rb') 375 # self.master_category_dict = pickle.load(cat_file) 376 self.master_category_dict = json.load(cat_file) 377 cat_file.close() 369 cat_file = CategoryInstaller.get_user_file() 370 self.master_category_dict = {} 371 if os.path.isfile(cat_file): 372 with open(cat_file, 'rb') as f: 373 self.master_category_dict = json.load(f) 378 374 except IOError: 379 print 'Problem reading in category file. Please review' 380 375 logging.error('Problem reading in category file.') 381 376 382 377 self._regenerate_model_dict() -
src/sas/sasgui/guiframe/customdir.py
rd85c194 r212bfc2 1 1 # Setup and find Custom config dir 2 import sys3 2 import os.path 4 3 import shutil 5 from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller6 4 7 5 CONF_DIR = 'config' … … 12 10 Find and return user/.sasview dir 13 11 """ 14 dir = os.path.join(os.path.expanduser("~"), 15 ("." + APPLICATION_NAME)) 16 return dir 12 return os.path.join(os.path.expanduser("~"), ("." + APPLICATION_NAME)) 17 13 18 14 def _find_customconf_dir(): … … 22 18 """ 23 19 u_dir = _find_usersasview_dir() 24 dir = os.path.join(u_dir, CONF_DIR) 25 26 return dir 20 return os.path.join(u_dir, CONF_DIR) 27 21 28 22 def _setup_conf_dir(path): … … 30 24 Setup the custom config dir and cat file 31 25 """ 32 dir = _find_customconf_dir()26 conf_dir = _find_customconf_dir() 33 27 # 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." 28 if not os.path.isdir(conf_dir): 29 os.makedirs(conf_dir) 30 config_file = os.path.join(conf_dir, "custom_config.py") 49 31 50 32 # Place example user models as needed 51 33 try: 52 if not os.path.isfile( file):53 shutil.copyfile(os.path.join(path, "custom_config.py"),file)34 if not os.path.isfile(config_file): 35 shutil.copyfile(os.path.join(path, "custom_config.py"), config_file) 54 36 except: 55 37 # Check for data path next to exe/zip file. … … 63 45 temp_path = os.path.join(f_dir, "custom_config.py") 64 46 if os.path.isfile(temp_path): 65 shutil.copyfile(temp_path, file)47 shutil.copyfile(temp_path, config_file) 66 48 is_dir = True 67 49 break 68 50 if not is_dir: 69 51 raise 70 71 return dir 72 73 52 return conf_dir 53 54 74 55 class SetupCustom(object): 75 56 """ … … 81 62 def setup_dir(self, path): 82 63 return _setup_conf_dir(path) 83 84 85 86 87 -
src/sas/sasgui/perspectives/fitting/basepage.py
r4c3be25 r212bfc2 3447 3447 self.by_model_dict = defaultdict(list) 3448 3448 self.model_enabled_dict = defaultdict(bool) 3449 3450 try: 3451 categorization_file = CategoryInstaller.get_user_file() 3452 if not os.path.isfile(categorization_file): 3453 categorization_file = CategoryInstaller.get_default_file() 3454 cat_file = open(categorization_file, 'rb') 3455 self.master_category_dict = json.load(cat_file) 3456 self._regenerate_model_dict() 3457 cat_file.close() 3458 except IOError: 3459 raise 3460 print 'Problem reading in category file.' 3461 print 'We even looked for it, made sure it was there.' 3462 print 'An existential crisis if there ever was one.' 3449 categorization_file = CategoryInstaller.get_user_file() 3450 with open(categorization_file, 'rb') as f: 3451 self.master_category_dict = json.load(f) 3452 self._regenerate_model_dict() 3463 3453 3464 3454 def _regenerate_model_dict(self): -
src/sas/sasgui/perspectives/fitting/models.py
r6fb559d r212bfc2 412 412 """ 413 413 __modelmanager = ModelManagerBase() 414 cat_model_list = [ model_namefor model_name \414 cat_model_list = [__modelmanager.model_dictionary[model_name] for model_name \ 415 415 in __modelmanager.model_dictionary.keys() \ 416 416 if model_name not in __modelmanager.stored_plugins.keys()]
Note: See TracChangeset
for help on using the changeset viewer.