Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime van Kessel <nallath@gmail.com>2016-04-28 17:01:54 +0300
committerJaime van Kessel <nallath@gmail.com>2016-04-28 17:01:54 +0300
commit9009fb9d3de9e0223d500702f603d2145e6b0f1f (patch)
treeb40d26d696f5071d2085da8b7d8c9d957e72679d
parentefd14421cc4cf72ac7ac453b257fc794851c768f (diff)
Codestyle & documentation
CURA-537
-rw-r--r--plugins/CuraProfileReader/CuraProfileReader.py10
-rw-r--r--plugins/CuraProfileWriter/CuraProfileWriter.py3
-rw-r--r--plugins/GCodeProfileReader/GCodeProfileReader.py22
-rw-r--r--plugins/GCodeWriter/GCodeWriter.py24
4 files changed, 36 insertions, 23 deletions
diff --git a/plugins/CuraProfileReader/CuraProfileReader.py b/plugins/CuraProfileReader/CuraProfileReader.py
index e3001da6ae..1d27649498 100644
--- a/plugins/CuraProfileReader/CuraProfileReader.py
+++ b/plugins/CuraProfileReader/CuraProfileReader.py
@@ -6,13 +6,13 @@ from UM.Logger import Logger
from UM.Settings.Profile import Profile
from UM.Settings.ProfileReader import ProfileReader
+
## 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):
## Initialises the cura profile reader.
- #
# This does nothing since the only other function is basically stateless.
def __init__(self):
super().__init__()
@@ -24,10 +24,11 @@ class CuraProfileReader(ProfileReader):
# not be read or didn't contain a valid profile, \code None \endcode is
# returned.
def read(self, file_name):
- profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile.
+ # Create an empty profile.
+ profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False)
serialised = ""
try:
- with open(file_name) as f: #Open file for reading.
+ with open(file_name) as f: # Open file for reading.
serialised = f.read()
except IOError as e:
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
@@ -35,6 +36,7 @@ class CuraProfileReader(ProfileReader):
try:
profile.unserialise(serialised)
- except Exception as e: #Parsing error. This is not a (valid) Cura profile then.
+ except Exception as e: # Parsing error. This is not a (valid) Cura profile then.
+ Logger.log("e", "Error while trying to parse profile: %s", str(e))
return None
return profile \ No newline at end of file
diff --git a/plugins/CuraProfileWriter/CuraProfileWriter.py b/plugins/CuraProfileWriter/CuraProfileWriter.py
index 1ac206e54a..82df446b8a 100644
--- a/plugins/CuraProfileWriter/CuraProfileWriter.py
+++ b/plugins/CuraProfileWriter/CuraProfileWriter.py
@@ -6,6 +6,7 @@ from UM.Logger import Logger
from UM.SaveFile import SaveFile
from UM.Settings.ProfileWriter import ProfileWriter
+
## Writes profiles to Cura's own profile format with config files.
class CuraProfileWriter(ProfileWriter):
## Writes a profile to the specified file path.
@@ -17,7 +18,7 @@ class CuraProfileWriter(ProfileWriter):
def write(self, path, profile):
serialised = profile.serialise()
try:
- with SaveFile(path, "wt", -1, "utf-8") as f: #Open the specified file.
+ with SaveFile(path, "wt", -1, "utf-8") as f: # Open the specified file.
f.write(serialised)
except Exception as e:
Logger.log("e", "Failed to write profile to %s: %s", path, str(e))
diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py
index 50048d831b..11cc249657 100644
--- a/plugins/GCodeProfileReader/GCodeProfileReader.py
+++ b/plugins/GCodeProfileReader/GCodeProfileReader.py
@@ -7,6 +7,7 @@ from UM.Settings.ProfileReader import ProfileReader
from UM.Logger import Logger
import re #Regular expressions for parsing escape characters in the settings.
+
## A class that reads profile data from g-code files.
#
# It reads the profile data from g-code files and stores it in a new profile.
@@ -47,29 +48,34 @@ class GCodeProfileReader(ProfileReader):
prefix = ";SETTING_" + str(GCodeProfileReader.version) + " "
prefix_length = len(prefix)
- #Loading all settings from the file. They are all at the end, but Python has no reverse seek any more since Python3. TODO: Consider moving settings to the start?
- serialised = "" #Will be filled with the serialised profile.
+ # Loading all settings from the file.
+ # They are all at the end, but Python has no reverse seek any more since Python3.
+ # TODO: Consider moving settings to the start?
+ serialised = "" # Will be filled with the serialised profile.
try:
with open(file_name) as f:
for line in f:
if line.startswith(prefix):
- serialised += line[prefix_length : -1] #Remove the prefix and the newline from the line, and add it to the rest.
+ # Remove the prefix and the newline from the line and add it to the rest.
+ serialised += line[prefix_length : -1]
except IOError as e:
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
return None
- #Unescape the serialised profile.
+ # Un-escape the serialised profile.
pattern = re.compile("|".join(GCodeProfileReader.escape_characters.keys()))
- serialised = pattern.sub(lambda m: GCodeProfileReader.escape_characters[re.escape(m.group(0))], serialised) #Perform the replacement with a regular expression.
- #Apply the changes to the current profile.
+ # Perform the replacement with a regular expression.
+ serialised = pattern.sub(lambda m: GCodeProfileReader.escape_characters[re.escape(m.group(0))], serialised)
+
+ # Apply the changes to the current profile.
profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False)
try:
profile.unserialise(serialised)
- profile.setType(None) #Force type to none so it's correctly added.
+ profile.setType(None) # Force type to none so it's correctly added.
profile.setReadOnly(False)
profile.setDirty(True)
- except Exception as e: #Not a valid g-code file.
+ except Exception as e: # Not a valid g-code file.
Logger.log("e", "Unable to serialise the profile: %s", str(e))
return None
return profile \ No newline at end of file
diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py
index e481e4c187..ee766ef221 100644
--- a/plugins/GCodeWriter/GCodeWriter.py
+++ b/plugins/GCodeWriter/GCodeWriter.py
@@ -22,9 +22,9 @@ class GCodeWriter(MeshWriter):
# Note that the keys of this dictionary are regex strings. The values are
# not.
escape_characters = {
- re.escape("\\"): "\\\\", #The escape character.
- re.escape("\n"): "\\n", #Newlines. They break off the comment.
- re.escape("\r"): "\\r" #Carriage return. Windows users may need this for visualisation in their editors.
+ re.escape("\\"): "\\\\", # The escape character.
+ re.escape("\n"): "\\n", # Newlines. They break off the comment.
+ re.escape("\r"): "\\r" # Carriage return. Windows users may need this for visualisation in their editors.
}
def __init__(self):
@@ -40,7 +40,8 @@ class GCodeWriter(MeshWriter):
if gcode_list:
for gcode in gcode_list:
stream.write(gcode)
- profile = self._serialiseProfile(Application.getInstance().getMachineManager().getWorkingProfile()) #Serialise the profile and put them at the end of the file.
+ # Serialise the profile and put them at the end of the file.
+ profile = self._serialiseProfile(Application.getInstance().getMachineManager().getWorkingProfile())
stream.write(profile)
return True
@@ -54,19 +55,22 @@ class GCodeWriter(MeshWriter):
# \param profile The profile to serialise.
# \return A serialised string of the profile.
def _serialiseProfile(self, profile):
- prefix = ";SETTING_" + str(GCodeWriter.version) + " " #The prefix to put before each line.
+ prefix = ";SETTING_" + str(GCodeWriter.version) + " " # The prefix to put before each line.
prefix_length = len(prefix)
- #Serialise a deepcopy to remove the defaults from the profile
+ # Serialise a deepcopy to remove the defaults from the profile
serialised = copy.deepcopy(profile).serialise()
- #Escape characters that have a special meaning in g-code comments.
+ # Escape characters that have a special meaning in g-code comments.
pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))
- serialised = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialised) #Perform the replacement with a regular expression.
+ # Perform the replacement with a regular expression.
+ serialised = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialised)
- #Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix.
+ # Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix.
result = ""
- for pos in range(0, len(serialised), 80 - prefix_length): #Lines have 80 characters, so the payload of each line is 80 - prefix.
+
+ # Lines have 80 characters, so the payload of each line is 80 - prefix.
+ for pos in range(0, len(serialised), 80 - prefix_length):
result += prefix + serialised[pos : pos + 80 - prefix_length] + "\n"
serialised = result