Updated comments in Backup

Converted doxygen style comments to reStructuredText style in the files
 found in Cura/cura/Backup directory recursively  using the script
dox_2_rst.py (provided in the Uranium repo). Comments were manually
 checked and changed if needed.
This commit is contained in:
Jelle Spijker 2020-05-08 15:39:16 +02:00 committed by Jelle Spijker
parent 176919eee0
commit d69bf84424
No known key found for this signature in database
GPG Key ID: 6662DC033BE6B99A
2 changed files with 31 additions and 18 deletions

View File

@ -18,24 +18,26 @@ if TYPE_CHECKING:
from cura.CuraApplication import CuraApplication
## The back-up class holds all data about a back-up.
#
# It is also responsible for reading and writing the zip file to the user data
# folder.
class Backup:
# These files should be ignored when making a backup.
IGNORED_FILES = [r"cura\.log", r"plugins\.json", r"cache", r"__pycache__", r"\.qmlc", r"\.pyc"]
"""The back-up class holds all data about a back-up.
It is also responsible for reading and writing the zip file to the user data folder.
"""
IGNORED_FILES = [r"cura\.log", r"plugins\.json", r"cache", r"__pycache__", r"\.qmlc", r"\.pyc"]
"""These files should be ignored when making a backup."""
# Re-use translation catalog.
catalog = i18nCatalog("cura")
"""Re-use translation catalog"""
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.meta_data = meta_data # type: Optional[Dict[str, str]]
## Create a back-up from the current user config folder.
def makeFromCurrent(self) -> None:
"""Create a back-up from the current user config folder."""
cura_release = self._application.getVersion()
version_data_dir = Resources.getDataStoragePath()
@ -77,10 +79,13 @@ class Backup:
"plugin_count": str(plugin_count)
}
## Make a full archive from the given root path with the given name.
# \param root_path The root directory to archive recursively.
# \return The archive as bytes.
def _makeArchive(self, buffer: "io.BytesIO", root_path: str) -> Optional[ZipFile]:
"""Make a full archive from the given root path with the given name.
:param root_path: The root directory to archive recursively.
:return: The archive as bytes.
"""
ignore_string = re.compile("|".join(self.IGNORED_FILES))
try:
archive = ZipFile(buffer, "w", ZIP_DEFLATED)
@ -99,13 +104,17 @@ class Backup:
"Could not create archive from user data directory: {}".format(error)))
return None
## Show a UI message.
def _showMessage(self, message: str) -> None:
"""Show a UI message."""
Message(message, title=self.catalog.i18nc("@info:title", "Backup"), lifetime=30).show()
## Restore this back-up.
# \return Whether we had success or not.
def restore(self) -> bool:
"""Restore this back-up.
:return: Whether we had success or not.
"""
if not self.zip_file or not self.meta_data or not self.meta_data.get("cura_release", None):
# We can restore without the minimum required information.
Logger.log("w", "Tried to restore a Cura backup without having proper data or meta data.")
@ -139,12 +148,14 @@ class Backup:
return extracted
## Extract the whole archive to the given target path.
# \param archive The archive as ZipFile.
# \param target_path The target path.
# \return Whether we had success or not.
@staticmethod
def _extractArchive(archive: "ZipFile", target_path: str) -> bool:
"""Extract the whole archive to the given target path.
:param archive: The archive as ZipFile.
:param target_path: The target path.
:return: Whether we had success or not.
"""
# Implement security recommendations: Sanity check on zip files will make it harder to spoof.
from cura.CuraApplication import CuraApplication

View File

@ -24,6 +24,7 @@ class BackupsManager:
def createBackup(self) -> Tuple[Optional[bytes], Optional[Dict[str, str]]]:
"""
Get a back-up of the current configuration.
:return: A tuple containing a ZipFile (the actual back-up) and a dict containing some metadata (like version).
"""
@ -37,6 +38,7 @@ class BackupsManager:
def restoreBackup(self, zip_file: bytes, meta_data: Dict[str, str]) -> None:
"""
Restore a back-up from a given ZipFile.
:param zip_file: A bytes object containing the actual back-up.
:param meta_data: A dict containing some metadata that is needed to restore the back-up correctly.
"""