diff --git a/cura/Api/Backups.py b/cura/Api/Backups.py new file mode 100644 index 0000000000..a05c3c3e64 --- /dev/null +++ b/cura/Api/Backups.py @@ -0,0 +1,27 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. +from zipfile import ZipFile + +from cura.Backups.BackupsManager import BackupsManager + + +class Backups: + """ + The backups API provides a version-proof bridge between Cura's BackupManager and plugins that hook into it. + + Usage: + cura.Api.backups.createBackup() + cura.Api.backups.restoreBackup(my_zip_file, {"cura_release": "3.1"}) + """ + + manager = BackupsManager() # Re-used instance of the backups manager. + + def createBackup(self) -> ("ZipFile", dict): + """ + Create a new backup using the BackupsManager. + :return: + """ + return self.manager.createBackup() + + def restoreBackup(self, zip_file: "ZipFile", meta_data: dict) -> None: + return self.manager.restoreBackup(zip_file, meta_data) diff --git a/cura/Api/__init__.py b/cura/Api/__init__.py new file mode 100644 index 0000000000..675e31cf2b --- /dev/null +++ b/cura/Api/__init__.py @@ -0,0 +1,15 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. +from cura.Api.Backups import Backups + + +class CuraApi: + """ + The official Cura API that plugins can use to interact with Cura. + Python does not technically prevent talking to other classes as well, + but this API provides a version-safe interface with proper deprecation warning etc. + Usage of any other methods than the ones provided in this API can cause plugins to be unstable. + """ + + # Backups API. + backups = Backups() diff --git a/cura/Backups/Backup.py b/cura/Backups/Backup.py new file mode 100644 index 0000000000..f16dadbfb9 --- /dev/null +++ b/cura/Backups/Backup.py @@ -0,0 +1,29 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + + +class Backup: + """ + The backup class holds all data about a backup. + It is also responsible for reading and writing the zip file to the user data folder. + """ + + def __init__(self): + self.generated = False # type: bool + self.backup_id = None # type: str + self.target_cura_version = None # type: str + self.zip_file = None + self.meta_data = None # type: dict + + def getZipFile(self): + pass + + def getMetaData(self): + pass + + def create(self): + self.generated = True + pass + + def restore(self): + pass diff --git a/cura/Backups/BackupsManager.py b/cura/Backups/BackupsManager.py new file mode 100644 index 0000000000..f98e0e4d36 --- /dev/null +++ b/cura/Backups/BackupsManager.py @@ -0,0 +1,28 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. +from zipfile import ZipFile + + +class BackupsManager: + """ + The BackupsManager is responsible for managing the creating and restoring of backups. + Backups themselves are represented in a different class. + """ + + def __init__(self): + pass + + def createBackup(self) -> ("ZipFile", dict): + """ + Get a backup of the current configuration. + :return: A Tuple containing a ZipFile (the actual backup) and a dict containing some meta data (like version). + """ + pass + + def restoreBackup(self, zip_file: "ZipFile", meta_data: dict) -> None: + """ + Restore a backup from a given ZipFile. + :param zip_file: A ZipFile containing the actual backup. + :param meta_data: A dict containing some meta data that is needed to restore the backup correctly. + """ + pass