Backups.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Tuple, Optional, TYPE_CHECKING, Dict, Any
  4. from cura.Backups.BackupsManager import BackupsManager
  5. if TYPE_CHECKING:
  6. from cura.CuraApplication import CuraApplication
  7. class Backups:
  8. """The back-ups API provides a version-proof bridge between Cura's
  9. BackupManager and plug-ins that hook into it.
  10. Usage:
  11. .. code-block:: python
  12. from cura.API import CuraAPI
  13. api = CuraAPI()
  14. api.backups.createBackup()
  15. api.backups.restoreBackup(my_zip_file, {"cura_release": "3.1"})
  16. """
  17. def __init__(self, application: "CuraApplication") -> None:
  18. self.manager = BackupsManager(application)
  19. def createBackup(self) -> Tuple[Optional[bytes], Optional[Dict[str, Any]]]:
  20. """Create a new back-up using the BackupsManager.
  21. :return: Tuple containing a ZIP file with the back-up data and a dict with metadata about the back-up.
  22. """
  23. return self.manager.createBackup()
  24. def restoreBackup(self, zip_file: bytes, meta_data: Dict[str, Any]) -> None:
  25. """Restore a back-up using the BackupsManager.
  26. :param zip_file: A ZIP file containing the actual back-up data.
  27. :param meta_data: Some metadata needed for restoring a back-up, like the Cura version number.
  28. """
  29. return self.manager.restoreBackup(zip_file, meta_data)