Browse Source

Merge branch 'CURA-7325_fix_config_error_on_restore_backup' of github.com:Ultimaker/Cura

Jaime van Kessel 5 years ago
parent
commit
c1de3d49bb
2 changed files with 31 additions and 15 deletions
  1. 24 14
      cura/Backups/BackupsManager.py
  2. 7 1
      cura/CuraApplication.py

+ 24 - 14
cura/Backups/BackupsManager.py

@@ -10,18 +10,23 @@ if TYPE_CHECKING:
     from cura.CuraApplication import CuraApplication
 
 
-##  The BackupsManager is responsible for managing the creating and restoring of
-#   back-ups.
-#
-#   Back-ups themselves are represented in a different class.
 class BackupsManager:
+    """
+    The BackupsManager is responsible for managing the creating and restoring of
+    back-ups.
+
+    Back-ups themselves are represented in a different class.
+    """
+
     def __init__(self, application: "CuraApplication") -> None:
         self._application = application
 
-    ##  Get a back-up of the current configuration.
-    #   \return A tuple containing a ZipFile (the actual back-up) and a dict
-    #   containing some metadata (like version).
     def createBackup(self) -> Tuple[Optional[bytes], Optional[Dict[str, str]]]:
+        """
+        Get a back-up of the current configuration.
+        :return: A tuple containing a ZipFile (the actual back-up) and a dict containing some metadata (like version).
+        """
+
         self._disableAutoSave()
         backup = Backup(self._application)
         backup.makeFromCurrent()
@@ -29,11 +34,13 @@ class BackupsManager:
         # We don't return a Backup here because we want plugins only to interact with our API and not full objects.
         return backup.zip_file, backup.meta_data
 
-    ##  Restore a back-up from a given ZipFile.
-    #   \param zip_file A bytes object containing the actual back-up.
-    #   \param meta_data A dict containing some metadata that is needed to
-    #   restore the back-up correctly.
     def restoreBackup(self, zip_file: bytes, meta_data: Dict[str, str]) -> None:
+        """
+        Restore a back-up from a given ZipFile.
+        :param zip_file: A bytes object containing the actual back-up.
+        :param meta_data: A dict containing some metadata that is needed to restore the back-up correctly.
+        """
+
         if not meta_data.get("cura_release", None):
             # If there is no "cura_release" specified in the meta data, we don't execute a backup restore.
             Logger.log("w", "Tried to restore a backup without specifying a Cura version number.")
@@ -48,9 +55,10 @@ class BackupsManager:
             # We don't want to store the data at this point as that would override the just-restored backup.
             self._application.windowClosed(save_data = False)
 
-    ##  Here we try to disable the auto-save plug-in as it might interfere with
-    #   restoring a back-up.
     def _disableAutoSave(self) -> None:
+        """Here we (try to) disable the saving as it might interfere with restoring a back-up."""
+
+        self._application.enableSave(False)
         auto_save = self._application.getAutoSave()
         # The auto save is only not created if the application has not yet started.
         if auto_save:
@@ -58,8 +66,10 @@ class BackupsManager:
         else:
             Logger.log("e", "Unable to disable the autosave as application init has not been completed")
 
-    ##  Re-enable auto-save after we're done.
     def _enableAutoSave(self) -> None:
+        """Re-enable auto-save and other saving after we're done."""
+
+        self._application.enableSave(True)
         auto_save = self._application.getAutoSave()
         # The auto save is only not created if the application has not yet started.
         if auto_save:

+ 7 - 1
cura/CuraApplication.py

@@ -242,6 +242,7 @@ class CuraApplication(QtApplication):
 
         # Backups
         self._auto_save = None  # type: Optional[AutoSave]
+        self._enable_save = True
 
         self._container_registry_class = CuraContainerRegistry
         # Redefined here in order to please the typing.
@@ -685,15 +686,20 @@ class CuraApplication(QtApplication):
             self._message_box_callback = None
             self._message_box_callback_arguments = []
 
+    def enableSave(self, enable: bool):
+        self._enable_save = enable
+
     # Cura has multiple locations where instance containers need to be saved, so we need to handle this differently.
     def saveSettings(self) -> None:
-        if not self.started:
+        if not self.started or not self._enable_save:
             # Do not do saving during application start or when data should not be saved on quit.
             return
         ContainerRegistry.getInstance().saveDirtyContainers()
         self.savePreferences()
 
     def saveStack(self, stack):
+        if not self._enable_save:
+            return
         ContainerRegistry.getInstance().saveContainer(stack)
 
     @pyqtSlot(str, result = QUrl)