mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-22 13:49:39 +08:00
Convert doxygen to rst for CuraProfileReader/Writer
This commit is contained in:
parent
176919eee0
commit
54d2fe95d1
@ -13,23 +13,30 @@ from cura.ReaderWriters.ProfileReader import ProfileReader
|
|||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
## A plugin that reads profile data from Cura profile files.
|
|
||||||
#
|
|
||||||
# It reads a profile from a .curaprofile file, and returns it as a profile
|
|
||||||
# instance.
|
|
||||||
class CuraProfileReader(ProfileReader):
|
class CuraProfileReader(ProfileReader):
|
||||||
## Initialises the cura profile reader.
|
"""A plugin that reads profile data from Cura profile files.
|
||||||
# This does nothing since the only other function is basically stateless.
|
|
||||||
|
It reads a profile from a .curaprofile file, and returns it as a profile
|
||||||
|
instance.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
"""Initialises the cura profile reader.
|
||||||
|
|
||||||
|
This does nothing since the only other function is basically stateless.
|
||||||
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
## Reads a cura profile from a file and returns it.
|
|
||||||
#
|
|
||||||
# \param file_name The file to read the cura profile from.
|
|
||||||
# \return The cura profiles that were in the file, if any. If the file
|
|
||||||
# could not be read or didn't contain a valid profile, ``None`` is
|
|
||||||
# returned.
|
|
||||||
def read(self, file_name: str) -> List[Optional[InstanceContainer]]:
|
def read(self, file_name: str) -> List[Optional[InstanceContainer]]:
|
||||||
|
"""Reads a cura profile from a file and returns it.
|
||||||
|
|
||||||
|
:param file_name: The file to read the cura profile from.
|
||||||
|
:return: The cura profiles that were in the file, if any. If the file
|
||||||
|
could not be read or didn't contain a valid profile, ``None`` is
|
||||||
|
returned.
|
||||||
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(file_name, "r") as archive:
|
with zipfile.ZipFile(file_name, "r") as archive:
|
||||||
results = [] # type: List[Optional[InstanceContainer]]
|
results = [] # type: List[Optional[InstanceContainer]]
|
||||||
@ -50,13 +57,14 @@ class CuraProfileReader(ProfileReader):
|
|||||||
serialized_bytes = fhandle.read()
|
serialized_bytes = fhandle.read()
|
||||||
return [self._loadProfile(serialized, profile_id) for serialized, profile_id in self._upgradeProfile(serialized_bytes, file_name)]
|
return [self._loadProfile(serialized, profile_id) for serialized, profile_id in self._upgradeProfile(serialized_bytes, file_name)]
|
||||||
|
|
||||||
## Convert a profile from an old Cura to this Cura if needed.
|
|
||||||
#
|
|
||||||
# \param serialized The profile data to convert in the serialized on-disk
|
|
||||||
# format.
|
|
||||||
# \param profile_id The name of the profile.
|
|
||||||
# \return List of serialized profile strings and matching profile names.
|
|
||||||
def _upgradeProfile(self, serialized: str, profile_id: str) -> List[Tuple[str, str]]:
|
def _upgradeProfile(self, serialized: str, profile_id: str) -> List[Tuple[str, str]]:
|
||||||
|
"""Convert a profile from an old Cura to this Cura if needed.
|
||||||
|
|
||||||
|
:param serialized: The profile data to convert in the serialized on-disk format.
|
||||||
|
:param profile_id: The name of the profile.
|
||||||
|
:return: List of serialized profile strings and matching profile names.
|
||||||
|
"""
|
||||||
|
|
||||||
parser = configparser.ConfigParser(interpolation = None)
|
parser = configparser.ConfigParser(interpolation = None)
|
||||||
parser.read_string(serialized)
|
parser.read_string(serialized)
|
||||||
|
|
||||||
@ -75,12 +83,14 @@ class CuraProfileReader(ProfileReader):
|
|||||||
else:
|
else:
|
||||||
return [(serialized, profile_id)]
|
return [(serialized, profile_id)]
|
||||||
|
|
||||||
## Load a profile from a serialized string.
|
|
||||||
#
|
|
||||||
# \param serialized The profile data to read.
|
|
||||||
# \param profile_id The name of the profile.
|
|
||||||
# \return The profile that was stored in the string.
|
|
||||||
def _loadProfile(self, serialized: str, profile_id: str) -> Optional[InstanceContainer]:
|
def _loadProfile(self, serialized: str, profile_id: str) -> Optional[InstanceContainer]:
|
||||||
|
"""Load a profile from a serialized string.
|
||||||
|
|
||||||
|
:param serialized: The profile data to read.
|
||||||
|
:param profile_id: The name of the profile.
|
||||||
|
:return: The profile that was stored in the string.
|
||||||
|
"""
|
||||||
|
|
||||||
# Create an empty profile.
|
# Create an empty profile.
|
||||||
profile = InstanceContainer(profile_id)
|
profile = InstanceContainer(profile_id)
|
||||||
profile.setMetaDataEntry("type", "quality_changes")
|
profile.setMetaDataEntry("type", "quality_changes")
|
||||||
@ -102,13 +112,15 @@ class CuraProfileReader(ProfileReader):
|
|||||||
profile.setMetaDataEntry("definition", active_quality_definition)
|
profile.setMetaDataEntry("definition", active_quality_definition)
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
## Upgrade a serialized profile to the current profile format.
|
|
||||||
#
|
|
||||||
# \param serialized The profile data to convert.
|
|
||||||
# \param profile_id The name of the profile.
|
|
||||||
# \param source_version The profile version of 'serialized'.
|
|
||||||
# \return List of serialized profile strings and matching profile names.
|
|
||||||
def _upgradeProfileVersion(self, serialized: str, profile_id: str, main_version: int, setting_version: int) -> List[Tuple[str, str]]:
|
def _upgradeProfileVersion(self, serialized: str, profile_id: str, main_version: int, setting_version: int) -> List[Tuple[str, str]]:
|
||||||
|
"""Upgrade a serialized profile to the current profile format.
|
||||||
|
|
||||||
|
:param serialized: The profile data to convert.
|
||||||
|
:param profile_id: The name of the profile.
|
||||||
|
:param source_version: The profile version of 'serialized'.
|
||||||
|
:return: List of serialized profile strings and matching profile names.
|
||||||
|
"""
|
||||||
|
|
||||||
source_version = main_version * 1000000 + setting_version
|
source_version = main_version * 1000000 + setting_version
|
||||||
|
|
||||||
from UM.VersionUpgradeManager import VersionUpgradeManager
|
from UM.VersionUpgradeManager import VersionUpgradeManager
|
||||||
|
@ -6,15 +6,18 @@ from UM.Logger import Logger
|
|||||||
from cura.ReaderWriters.ProfileWriter import ProfileWriter
|
from cura.ReaderWriters.ProfileWriter import ProfileWriter
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
## Writes profiles to Cura's own profile format with config files.
|
|
||||||
class CuraProfileWriter(ProfileWriter):
|
class CuraProfileWriter(ProfileWriter):
|
||||||
## Writes a profile to the specified file path.
|
"""Writes profiles to Cura's own profile format with config files."""
|
||||||
#
|
|
||||||
# \param path \type{string} The file to output to.
|
|
||||||
# \param profiles \type{Profile} \type{List} The profile(s) to write to that file.
|
|
||||||
# \return \code True \endcode if the writing was successful, or \code
|
|
||||||
# False \endcode if it wasn't.
|
|
||||||
def write(self, path, profiles):
|
def write(self, path, profiles):
|
||||||
|
"""Writes a profile to the specified file path.
|
||||||
|
|
||||||
|
:param path: :type{string} The file to output to.
|
||||||
|
:param profiles: :type{Profile} :type{List} The profile(s) to write to that file.
|
||||||
|
:return: True if the writing was successful, or
|
||||||
|
False if it wasn't.
|
||||||
|
"""
|
||||||
|
|
||||||
if type(profiles) != list:
|
if type(profiles) != list:
|
||||||
profiles = [profiles]
|
profiles = [profiles]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user