Backups.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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
  4. from cura.Backups.BackupsManager import BackupsManager
  5. if TYPE_CHECKING:
  6. from cura.CuraApplication import CuraApplication
  7. ## The back-ups API provides a version-proof bridge between Cura's
  8. # BackupManager and plug-ins that hook into it.
  9. #
  10. # Usage:
  11. # ``from cura.API import CuraAPI
  12. # api = CuraAPI()
  13. # api.backups.createBackup()
  14. # api.backups.restoreBackup(my_zip_file, {"cura_release": "3.1"})``
  15. class Backups:
  16. def __init__(self, application: "CuraApplication") -> None:
  17. self.manager = BackupsManager(application)
  18. ## Create a new back-up using the BackupsManager.
  19. # \return Tuple containing a ZIP file with the back-up data and a dict
  20. # with metadata about the back-up.
  21. def createBackup(self) -> Tuple[Optional[bytes], Optional[dict]]:
  22. return self.manager.createBackup()
  23. ## Restore a back-up using the BackupsManager.
  24. # \param zip_file A ZIP file containing the actual back-up data.
  25. # \param meta_data Some metadata needed for restoring a back-up, like the
  26. # Cura version number.
  27. def restoreBackup(self, zip_file: bytes, meta_data: dict) -> None:
  28. return self.manager.restoreBackup(zip_file, meta_data)