Index: sansguiframe/src/sans/guiframe/CategoryInstaller.py
===================================================================
--- sansguiframe/src/sans/guiframe/CategoryInstaller.py	(revision dad7cefa5ce1c68624b46df57bcb5b00ade2d254)
+++ sansguiframe/src/sans/guiframe/CategoryInstaller.py	(revision 657e52c6e801e630d2fc6f1722a752b701d20771)
@@ -123,6 +123,5 @@
         
     @staticmethod
-    def check_install(homedir = None, defaultfile = None,
-                      modelsdir = None, installed_models_dir = None):
+    def check_install(homedir = None, model_list=None):
         """
         the main method of this class
@@ -130,92 +129,52 @@
         compile it and install
         :param homefile: Override the default home directory
-        :param defaultfile: Override the default file location
-        :param modelsfile: The file where models.py lives. This
-        MUST be overwritten in setup.py
-        :param installed_models_dir: Where installed_models.txt is to go:
+        :param model_list: List of model names except customized models
         """
-        model_list = []
+        #model_list = []
+        default_file = CategoryInstaller.get_default_file()
         serialized_file = None
+        master_category_dict = defaultdict(list)
         if homedir == None:
             serialized_file = CategoryInstaller.get_user_file()
         else:
             serialized_file = os.path.join(homedir, USER_FILE)
-
-        if os.path.exists(serialized_file):
-            return
-
-        if installed_models_dir == None:
-            installed_models_dir = \
-                CategoryInstaller._get_installed_model_dir() 
+        if os.path.isfile(serialized_file):
+            cat_file = open(serialized_file, 'rb')
+        else:
+            cat_file = open(default_file, 'rb')
+        master_category_dict = pickle.Unpickler(cat_file).load()
+        (by_model_dict, model_enabled_dict) = \
+                CategoryInstaller._regenerate_model_dict(master_category_dict)
+        cat_file.close()
+        add_list = model_list
+        del_name = False
+        for cat in master_category_dict.keys():
+            for ind in range(len(master_category_dict[cat])):
+                model_name, enabled = master_category_dict[cat][ind]
+                if model_name not in model_list:
+                    del_name = True 
+                    try:
+                        by_model_dict.pop(model_name)
+                        model_enabled_dict.pop(model_name)
+                    except:
+                        pass
+                else:
+                    add_list.remove(model_name)
+        if del_name or (len(add_list) > 0):
+            for model in add_list:
+                model_enabled_dict[model]= True
+                by_model_dict[model].append('Uncategorized')
+    
+            master_category_dict = \
+                CategoryInstaller._regenerate_master_dict(by_model_dict,
+                                                          model_enabled_dict)
+            
+            pickle.dump( master_category_dict,
+                         open(serialized_file, 'wb') )
+            
+            try:
+                #It happens only in source environment
+                shutil.copyfile(serialized_file, default_file)
+            except:
+                pass
         
-        installed_model_file = open(
-            os.path.join(installed_models_dir,
-                         "installed_models.txt"), 'w')
-
-        if modelsdir == None:
-            modelsdir = CategoryInstaller._get_models_py_dir()
-        python_model_file = open(os.path.join(modelsdir, 
-                                              "models.py"),
-                                 'r')
-
-        python_models = python_model_file.read()
-        
-        # we remove models that appear in the installed
-        # model folder but not in models.py . the excess
-        # hard coded ones on the end come from them being
-        # present in models.py but not actual models, eg
-        # TwoLorenzianModel contains the string 'Lorenzian'
-        # but we don't actually want to include Lorenzian
-        model_list = [mod for mod in model_list if \
-                          mod in python_models and \
-                          not 'init' in mod and \
-                          not 'BaseComponent' in mod \
-                          and not 'MultiplicationModel' in mod \
-                          and not 'pluginmodel' in mod \
-                          and mod != 'PowerLawModel' \
-                          and mod != 'Lorentzian']
-
-        
-        for mod in model_list:
-            installed_model_file.write(mod + '\n')
-        
-        installed_model_file.close()
-
-        # start sorting category stuff
-        default_file = None
-        if defaultfile == None:
-            default_file = CategoryInstaller.get_default_file()
-        else:
-            default_file = defaultfile
-
-        master_category_dict = pickle.load(open(default_file, 'rb'))
-        
-        (by_model_dict, model_enabled_dict) = \
-            CategoryInstaller._regenerate_model_dict(master_category_dict)
-            
-            
-        for found_model in model_list:
-            if not found_model in by_model_dict:
-                print found_model + ' : ' + str(by_model_dict[found_model]) 
-                by_model_dict[found_model].append("Uncategorized")
-                model_enabled_dict[found_model] = True
-
-                # remove any stray models from categorization 
-                # that aren't stored anymore
-
-        models_to_delete = []
-        for model in by_model_dict:
-            if not model in model_list:
-                models_to_delete.append(model)
-
-        for model in models_to_delete:
-            by_model_dict.pop(model)
-
-        master_category_dict = \
-            CategoryInstaller._regenerate_master_dict(by_model_dict,
-                                                      model_enabled_dict)
-        
-        pickle.dump( master_category_dict,
-                     open(default_file, 'wb') )
-
-        #shutil.copyfile(default_file, serialized_file)
