Start class layouts for backups and plugins API

This commit is contained in:
ChrisTerBeke 2018-05-07 10:55:24 +02:00
parent 58289a7b45
commit 32e2723c26
4 changed files with 99 additions and 0 deletions

27
cura/Api/Backups.py Normal file
View file

@ -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)

15
cura/Api/__init__.py Normal file
View file

@ -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()

29
cura/Backups/Backup.py Normal file
View file

@ -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

View file

@ -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