Bladeren bron

- fixed issues with detecting older Preferences files

Marius Stanciu 5 jaren geleden
bovenliggende
commit
8a95580f15
5 gewijzigde bestanden met toevoegingen van 39 en 26 verwijderingen
  1. 1 0
      CHANGELOG.md
  2. 4 4
      appDatabase.py
  3. 1 1
      appTools/ToolDrilling.py
  4. 5 5
      app_Main.py
  5. 28 16
      defaults.py

+ 1 - 0
CHANGELOG.md

@@ -18,6 +18,7 @@ CHANGELOG for FlatCAM beta
 - Excellon UI: added a column which will color each row/tool of that column in the color used when checking Multicolor checkbox
 - Excellon UI: made sure that when the Multicolor checkbox is unchecked, the color is updated in the Color column of the tools table
 - made sure that the Preferences files are deleted on new version install, while the application is in Beta status
+- fixed issues with detecting older Preferences files
 
 20.07.2020
 

+ 4 - 4
appDatabase.py

@@ -296,7 +296,7 @@ class ToolsDB(QtWidgets.QWidget):
               "A position on Z plane to move immediately after job stop."))
 
     def setup_db_ui(self):
-        filename = self.app.data_path + '/geo_tools_db.FlatDB'
+        filename = self.app.data_path + '/tools_db.FlatDB'
 
         # load the database tools from the file
         try:
@@ -733,7 +733,7 @@ class ToolsDB(QtWidgets.QWidget):
     def on_save_tools_db(self, silent=False):
         self.app.log.debug("ToolsDB.on_save_button() --> Saving Tools Database to file.")
 
-        filename = self.app.data_path + "/geo_tools_db.FlatDB"
+        filename = self.app.data_path + "/tools_db.FlatDB"
 
         # Preferences save, update the color of the Tools DB Tab text
         for idx in range(self.app_ui.plot_tab_area.count()):
@@ -2450,7 +2450,7 @@ class ToolsDB2(QtWidgets.QWidget):
         self.ui_connect()
 
     def setup_db_ui(self):
-        filename = self.app.data_path + '\\geo_tools_db.FlatDB'
+        filename = self.app.data_path + '\\tools_db.FlatDB'
 
         # load the database tools from the file
         try:
@@ -2859,7 +2859,7 @@ class ToolsDB2(QtWidgets.QWidget):
     def on_save_tools_db(self, silent=False):
         self.app.log.debug("ToolsDB.on_save_button() --> Saving Tools Database to file.")
 
-        filename = self.app.data_path + "/geo_tools_db.FlatDB"
+        filename = self.app.data_path + "/tools_db.FlatDB"
 
         # Preferences save, update the color of the Tools DB Tab text
         for idx in range(self.app_ui.plot_tab_area.count()):

+ 1 - 1
appTools/ToolDrilling.py

@@ -811,7 +811,7 @@ class ToolDrilling(AppTool, Excellon):
 
     def on_tool_db_load(self):
 
-        filename = self.app.data_path + '\\geo_tools_db.FlatDB'
+        filename = self.app.data_path + '\\tools_db.FlatDB'
 
         # load the database tools from the file
         try:

+ 5 - 5
app_Main.py

@@ -361,13 +361,13 @@ class App(QtCore.QObject):
             os.makedirs(self.preprocessorpaths)
             App.log.debug('Created preprocessors folder: ' + self.preprocessorpaths)
 
-        # create geo_tools_db.FlatDB file if there is none
+        # create tools_db.FlatDB file if there is none
         try:
-            f = open(self.data_path + '/geo_tools_db.FlatDB')
+            f = open(self.data_path + '/tools_db.FlatDB')
             f.close()
         except IOError:
-            App.log.debug('Creating empty geo_tool_db.FlatDB')
-            f = open(self.data_path + '/geo_tools_db.FlatDB', 'w')
+            App.log.debug('Creating empty tools_db.FlatDB')
+            f = open(self.data_path + '/tools_db.FlatDB', 'w')
             json.dump({}, f)
             f.close()
 
@@ -420,7 +420,7 @@ class App(QtCore.QObject):
         # ############################################################################################################
         # ################################# DEFAULTS - PREFERENCES STORAGE ###########################################
         # ############################################################################################################
-        self.defaults = FlatCAMDefaults(beta=self.beta)
+        self.defaults = FlatCAMDefaults(beta=self.beta, version=self.version)
 
         self.defaults["root_folder_path"] = self.app_home
 

+ 28 - 16
defaults.py

@@ -16,7 +16,8 @@ from appParsers.ParseGerber import Gerber
 fcTranslate.apply_language('strings')
 if '_' not in builtins.__dict__:
     _ = gettext.gettext
-log = logging.getLogger('FlatCAMDefaults')
+# log = logging.getLogger('FlatCAMDefaults')
+log = logging.getLogger('base')
 
 
 class FlatCAMDefaults:
@@ -88,7 +89,6 @@ class FlatCAMDefaults:
         "global_portable": False,
         "global_language": 'English',
 
-
         "global_systray_icon": True,
         "global_shell_at_startup": False,  # Show the shell at startup.
         "global_project_at_startup": False,
@@ -741,19 +741,22 @@ class FlatCAMDefaults:
     }
 
     @classmethod
-    def save_factory_defaults(cls, file_path: str, version: float):
+    def save_factory_defaults(cls, file_path: str, version: (float, str)):
         """Writes the factory defaults to a file at the given path, overwriting any existing file."""
-        # Delete any existing factory defaults file
+        # If the file exists
         if os.path.isfile(file_path):
-            # check if it has content other than an empty dict, because if it does we don't need it to be updated
-            # each time the app starts
+            # tst if it is empty
             with open(file_path, "r") as file:
                 f_defaults = simplejson.loads(file.read())
-                if f_defaults:
-                    return
 
-            os.chmod(file_path, stat.S_IRWXO | stat.S_IWRITE | stat.S_IWGRP)
-            os.remove(file_path)
+                # if the file is not empty
+                if f_defaults:
+                    # if it has the same version do nothing
+                    if str(f_defaults['version']) == str(version):
+                        return
+                    # if the versions differ then remove the file
+                    os.chmod(file_path, stat.S_IRWXO | stat.S_IWRITE | stat.S_IWGRP)
+                    os.remove(file_path)
 
         cls.factory_defaults['version'] = version
 
@@ -770,18 +773,22 @@ class FlatCAMDefaults:
         except Exception as e:
             log.error("save_factory_defaults() -> %s" % str(e))
 
-    def __init__(self, callback=lambda x: None, beta=True):
+    def __init__(self, callback=lambda x: None, beta=True, version=8.9):
         """
 
         :param callback:    A method called each time that one of the values are changed in the self.defaults LouDict
         """
         self.defaults = LoudDict()
+
+        self.beta = beta
+        self.version = version
+        self.factory_defaults['version'] = self.version
+
         self.defaults.update(self.factory_defaults)
         self.current_defaults = {}  # copy used for restoring after cancelled prefs changes
         self.current_defaults.update(self.factory_defaults)
         self.old_defaults_found = False
 
-        self.beta = beta
         self.defaults.set_change_callback(callback)
 
     # #### Pass-through to the defaults LoudDict #####
@@ -844,16 +851,21 @@ class FlatCAMDefaults:
 
             # while the app is in Beta status, delete the older Preferences files
             if self.beta is False:
+                log.debug("Found old preferences files. Migrating.")
                 defaults = self.__migrate_old_defaults(defaults=defaults)
+                # Save the resulting defaults
+                self.defaults.update(defaults)
+                self.current_defaults.update(self.defaults)
             else:
+                log.debug("Found old preferences files. Resetting the files.")
                 # wipeout the old defaults
-                self.reset_to_factory_defaults(defaults=defaults)
+                self.reset_to_factory_defaults()
         else:
             self.old_defaults_found = False
 
-        # Save the resulting defaults
-        self.defaults.update(defaults)
-        self.current_defaults.update(self.defaults)
+            # Save the resulting defaults
+            self.defaults.update(defaults)
+            self.current_defaults.update(self.defaults)
 
         log.debug("FlatCAM defaults loaded from: %s" % filename)