mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 21:27:50 -06:00
Fix imports in Backup
This commit is contained in:
parent
dd150bbab9
commit
6e46772170
1 changed files with 10 additions and 9 deletions
|
@ -4,18 +4,18 @@
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from typing import Dict, Optional
|
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED, BadZipfile
|
from zipfile import ZipFile, ZIP_DEFLATED, BadZipfile
|
||||||
|
from typing import Dict, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from UM import i18nCatalog
|
from UM import i18nCatalog
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
from UM.Platform import Platform
|
from UM.Platform import Platform
|
||||||
from UM.Resources import Resources
|
from UM.Resources import Resources
|
||||||
from cura.CuraApplication import CuraApplication
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
|
||||||
|
|
||||||
## The back-up class holds all data about a back-up.
|
## The back-up class holds all data about a back-up.
|
||||||
|
@ -29,7 +29,8 @@ class Backup:
|
||||||
# Re-use translation catalog.
|
# Re-use translation catalog.
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
def __init__(self, zip_file: bytes = None, meta_data: Dict[str, str] = None) -> None:
|
def __init__(self, application: "CuraApplication", zip_file: bytes = None, meta_data: Dict[str, str] = None) -> None:
|
||||||
|
self.application = application
|
||||||
self.zip_file = zip_file # type: Optional[bytes]
|
self.zip_file = zip_file # type: Optional[bytes]
|
||||||
self.meta_data = meta_data # type: Optional[Dict[str, str]]
|
self.meta_data = meta_data # type: Optional[Dict[str, str]]
|
||||||
|
|
||||||
|
@ -41,12 +42,12 @@ class Backup:
|
||||||
Logger.log("d", "Creating backup for Cura %s, using folder %s", cura_release, version_data_dir)
|
Logger.log("d", "Creating backup for Cura %s, using folder %s", cura_release, version_data_dir)
|
||||||
|
|
||||||
# Ensure all current settings are saved.
|
# Ensure all current settings are saved.
|
||||||
CuraApplication.getInstance().saveSettings()
|
self.application.saveSettings()
|
||||||
|
|
||||||
# We copy the preferences file to the user data directory in Linux as it's in a different location there.
|
# We copy the preferences file to the user data directory in Linux as it's in a different location there.
|
||||||
# When restoring a backup on Linux, we move it back.
|
# When restoring a backup on Linux, we move it back.
|
||||||
if Platform.isLinux():
|
if Platform.isLinux():
|
||||||
preferences_file_name = CuraApplication.getInstance().getApplicationName()
|
preferences_file_name = self.application.getApplicationName()
|
||||||
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
|
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
|
||||||
backup_preferences_file = os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))
|
backup_preferences_file = os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))
|
||||||
Logger.log("d", "Copying preferences file from %s to %s", preferences_file, backup_preferences_file)
|
Logger.log("d", "Copying preferences file from %s to %s", preferences_file, backup_preferences_file)
|
||||||
|
@ -112,7 +113,7 @@ class Backup:
|
||||||
"Tried to restore a Cura backup without having proper data or meta data."))
|
"Tried to restore a Cura backup without having proper data or meta data."))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
current_version = CuraApplication.getInstance().getVersion()
|
current_version = self.application.getVersion()
|
||||||
version_to_restore = self.meta_data.get("cura_release", "master")
|
version_to_restore = self.meta_data.get("cura_release", "master")
|
||||||
if current_version != version_to_restore:
|
if current_version != version_to_restore:
|
||||||
# Cannot restore version older or newer than current because settings might have changed.
|
# Cannot restore version older or newer than current because settings might have changed.
|
||||||
|
@ -128,7 +129,7 @@ class Backup:
|
||||||
|
|
||||||
# Under Linux, preferences are stored elsewhere, so we copy the file to there.
|
# Under Linux, preferences are stored elsewhere, so we copy the file to there.
|
||||||
if Platform.isLinux():
|
if Platform.isLinux():
|
||||||
preferences_file_name = CuraApplication.getInstance().getApplicationName()
|
preferences_file_name = self.application.getApplicationName()
|
||||||
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
|
preferences_file = Resources.getPath(Resources.Preferences, "{}.cfg".format(preferences_file_name))
|
||||||
backup_preferences_file = os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))
|
backup_preferences_file = os.path.join(version_data_dir, "{}.cfg".format(preferences_file_name))
|
||||||
Logger.log("d", "Moving preferences file from %s to %s", backup_preferences_file, preferences_file)
|
Logger.log("d", "Moving preferences file from %s to %s", backup_preferences_file, preferences_file)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue