def _setup_conf_dir(path): """ Setup the custom config dir and cat file """ dir = _find_customconf_dir() # If the plugin directory doesn't exist, create it if not os.path.isdir(dir): os.makedirs(dir) file = os.path.join(dir, "custom_config.py") cat_file = CategoryInstaller.get_user_file() # If the user category file doesn't exist copy the default to # the user directory if not os.path.isfile(cat_file): try: default_cat_file = CategoryInstaller.get_default_file() if os.path.isfile(default_cat_file): shutil.copyfile(default_cat_file, cat_file) else: print "Unable to find/copy default cat file" except: print "Unable to copy default cat file to the user dir." # Place example user models as needed try: if not os.path.isfile(file): shutil.copyfile(os.path.join(path, "custom_config.py"), file) except: # Check for data path next to exe/zip file. # Look for maximum n_dir up of the current dir to find plugins dir n_dir = 12 is_dir = False f_dir = path for i in range(n_dir): if i > 1: f_dir, _ = os.path.split(f_dir) temp_path = os.path.join(f_dir, "custom_config.py") if os.path.isfile(temp_path): shutil.copyfile(temp_path, file) is_dir = True break if not is_dir: raise return dir
def _setup_conf_dir(path): """ Setup the custom config dir and cat file """ dir = _find_customconf_dir() # If the plugin directory doesn't exist, create it if not os.path.isdir(dir): os.makedirs(dir) file = os.path.join(dir, "custom_config.py") cat_file = CategoryInstaller.get_user_file() # If the user category file doesn't exist copy the default to # the user directory if not os.path.isfile(cat_file): try: default_cat_file = CategoryInstaller.get_default_file() if os.path.isfile(default_cat_file): shutil.copyfile(default_cat_file, cat_file) else: print "Unable to find/copy default cat file" except: print "Unable to copy default cat file to the user dir." # Place example user models as needed try: if not os.path.isfile(file): shutil.copyfile(os.path.join(path, "custom_config.py"), file) except: # Check for data path next to exe/zip file. #Look for maximum n_dir up of the current dir to find plugins dir n_dir = 12 is_dir = False f_dir = path for i in range(n_dir): if i > 1: f_dir, _ = os.path.split(f_dir) temp_path = os.path.join(f_dir, "custom_config.py") if os.path.isfile(temp_path): shutil.copyfile(temp_path, file) is_dir = True break if not is_dir: raise return dir
def _read_category_info(self): """ Read in categorization info from file """ try: file = CategoryInstaller.get_user_file() if os.path.isfile(file): cat_file = open(file, 'rb') # self.master_category_dict = pickle.load(cat_file) self.master_category_dict = json.load(cat_file) else: cat_file = open(CategoryInstaller.get_default_file(), 'rb') # self.master_category_dict = pickle.load(cat_file) self.master_category_dict = json.load(cat_file) cat_file.close() except IOError: print 'Problem reading in category file. Please review' self._regenerate_model_dict()