Merge branch 'maintenance' into devel

This commit is contained in:
Gina Häußge committed 2017-03-09 18:44:54 +01:00
commit 8107d65504
8 files changed
+129 -52

No files matched your search

+1
View File
@@ -79,6 +79,7 @@ date of first contribution):
* [Eyal Soha](https://github.com/eyal0)
* [Greg Hulands](https://github.com/ghulands)
* [Andreas Werner](https://github.com/gallore)
* [Shawn Bruce](https://github.com/kantlivelong)
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
[Daid Braam](https://github.com/daid). Parts of its communication layer and
+5 -2
View File
@@ -308,9 +308,12 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue):
def _do_analysis(self, high_priority=False):
try:
throttle = settings().getFloat(["gcodeAnalysis", "throttle_highprio"]) if high_priority else settings().getFloat(["gcodeAnalysis", "throttle_normalprio"])
throttle_lines = settings().getInt(["gcodeAnalysis", "throttle_lines"])
if throttle > 0:
def throttle_callback():
time.sleep(throttle)
def throttle_callback(filePos, readBytes):
if filePos % throttle_lines == 0:
# only apply throttle every 100 lines
time.sleep(throttle)
else:
throttle_callback = None
@@ -25,7 +25,8 @@ class VirtualPrinter(object):
sleep_after_regex = re.compile("sleep_after ([GMTF]\d+) (\d+)")
sleep_after_next_regex = re.compile("sleep_after_next ([GMTF]\d+) (\d+)")
custom_action_regex = re.compile("action_custom ([a-zA-Z0-9_]+)(\s+.*)?")
prepare_ok_regex = re.compile("prepare_ok (.*)?")
prepare_ok_regex = re.compile("prepare_ok (.*)")
send_regex = re.compile("send (.*)")
def __init__(self, seriallog_handler=None, read_timeout=5.0, write_timeout=10.0):
import logging
@@ -560,6 +561,11 @@ class VirtualPrinter(object):
| Sleeps <seconds> s after each execution of <command>
sleep_after_next <str:command> <int:seconds>
| Sleeps <seconds> s after execution of next <command>
# Misc
send <str:message>
| Sends back <message>
"""
for line in usage.split("\n"):
self._send("echo: {}".format(line.strip()))
@@ -589,6 +595,7 @@ class VirtualPrinter(object):
sleep_after_next_match = VirtualPrinter.sleep_after_next_regex.match(data)
custom_action_match = VirtualPrinter.custom_action_regex.match(data)
prepare_ok_match = VirtualPrinter.prepare_ok_regex.match(data)
send_match = VirtualPrinter.send_regex.match(data)
if sleep_match is not None:
interval = int(sleep_match.group(1))
@@ -612,6 +619,8 @@ class VirtualPrinter(object):
elif prepare_ok_match is not None:
ok = prepare_ok_match.group(1)
self._prepared_oks.append(ok)
elif send_match is not None:
self._send(send_match.group(1))
except:
pass
+2 -1
View File
@@ -179,7 +179,8 @@ default_settings = {
"gcodeAnalysis": {
"maxExtruders": 10,
"throttle_normalprio": 0.01,
"throttle_highprio": 0.0
"throttle_highprio": 0.0,
"throttle_lines": 100
},
"feature": {
"temperatureGraph": True,
+34 -7
View File
@@ -127,6 +127,9 @@ Groups will be as follows:
regex_firmware_splitter = re.compile("\s*([A-Z0-9_]+):")
"""Regex to use for splitting M115 responses."""
regex_resend_linenumber = re.compile("(N|N:)?(?P<n>%s)" % regex_int_pattern)
"""Regex to use for request line numbers in resend requests"""
def serialList():
baselist=[]
if os.name=="nt":
@@ -1393,6 +1396,18 @@ class MachineCom(object):
self._log("There was a timeout while trying to connect to the printer")
self.close(wait=False)
### Operational (idle or busy)
elif self._state in (self.STATE_OPERATIONAL,
self.STATE_PRINTING,
self.STATE_PAUSED,
self.STATE_TRANSFERING_FILE):
if line == "start": # exact match, to be on the safe side
message = "Printer sent 'start' while already operational. External reset? " \
"Resetting line numbers to be on the safe side"
self._log(message)
self._logger.warn(message)
self.resetLineNumbers()
except:
self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:")
@@ -1851,13 +1866,7 @@ class MachineCom(object):
def _handleResendRequest(self, line):
try:
lineToResend = None
try:
lineToResend = int(line.replace("N:", " ").replace("N", " ").replace(":", " ").split()[-1])
except:
if "rs" in line:
lineToResend = int(line.split()[1])
lineToResend = parse_resend_line(line)
if lineToResend is None:
return False
@@ -3003,6 +3012,24 @@ def parse_firmware_line(line):
result[key] = value
return result
def parse_resend_line(line):
"""
Parses the provided resend line and returns requested line number.
Args:
line (str): the line to parse
Returns:
int or None: the extracted line number to resend, or None if no number could be extracted
"""
match = regex_resend_linenumber.search(line)
if match is not None:
return int(match.group("n"))
return None
def gcode_command_for_cmd(cmd):
"""
Tries to parse the provided ``cmd`` and extract the GCODE command identifier from it (e.g. "G0" for "G0 X10.0").
+5 -5
View File
@@ -221,7 +221,7 @@ class gcode(object):
self._reenqueue = reenqueue
def _load(self, gcodeFile, printer_profile, throttle=None):
filePos = 0
lineNo = 0
readBytes = 0
pos = Vector3D(0.0, 0.0, 0.0)
posOffset = Vector3D(0.0, 0.0, 0.0)
@@ -245,18 +245,18 @@ class gcode(object):
for line in gcodeFile:
if self._abort:
raise AnalysisAborted(reenqueue=self._reenqueue)
filePos += 1
lineNo += 1
readBytes += len(line)
if isinstance(gcodeFile, (file)):
percentage = float(readBytes) / float(self._fileSize)
elif isinstance(gcodeFile, (list)):
percentage = float(filePos) / float(len(gcodeFile))
percentage = float(lineNo) / float(len(gcodeFile))
else:
percentage = None
try:
if self.progressCallback is not None and (filePos % 1000 == 0) and percentage is not None:
if self.progressCallback is not None and (lineNo % 1000 == 0) and percentage is not None:
self.progressCallback(percentage)
except:
pass
@@ -444,7 +444,7 @@ class gcode(object):
totalExtrusion.append(0.0)
if throttle is not None:
throttle()
throttle(lineNo, readBytes)
if self.progressCallback is not None:
self.progressCallback(100.0)
+48 -36
View File
@@ -10,6 +10,7 @@ import shutil
import glob
from setuptools import Command
from distutils.command.clean import clean as _clean
def package_data_dirs(source, sub_folders):
@@ -50,64 +51,75 @@ def recursively_handle_files(directory, file_matcher, folder_matcher=None, folde
return applied_handler
class CleanCommand(Command):
description = "clean build artifacts"
user_options = []
boolean_options = []
class CleanCommand(_clean):
user_options = _clean.user_options + [("orig", None, "behave like original clean command"),
("noeggs", None, "don't clean up eggs"),
("nopyc", None, "don't clean up pyc files")]
boolean_options = _clean.boolean_options + ["orig", "noeggs", "nopyc"]
build_folder = "build"
source_folder = "src"
eggs = []
eggs =None
@classmethod
def for_options(cls, build_folder="build", source_folder="src", eggs=None):
def for_options(cls, source_folder="src", eggs=None):
if eggs is None:
eggs = []
return type(cls)(cls.__name__, (cls,), dict(
build_folder=build_folder,
source_folder=source_folder,
eggs=eggs
))
def initialize_options(self):
pass
_clean.initialize_options(self)
self.orig = None
self.noeggs = None
self.nopyc = None
def finalize_options(self):
pass
_clean.finalize_options(self)
if not self.orig:
self.all = True
def run(self):
# build folder
if os.path.exists(self.__class__.build_folder):
print("Deleting build directory")
shutil.rmtree(self.__class__.build_folder)
_clean.run(self)
if self.orig:
return
# eggs
for egg in self.__class__.eggs:
globbed_eggs = glob.glob(egg)
for globbed_egg in globbed_eggs:
print("Deleting %s directory" % globbed_egg)
shutil.rmtree(globbed_egg)
if not self.noeggs:
for egg in self.eggs:
globbed_eggs = glob.glob(egg)
for globbed_egg in globbed_eggs:
print("deleting '%s' egg" % globbed_egg)
if not self.dry_run:
shutil.rmtree(globbed_egg)
# pyc files
def delete_folder_if_empty(path, applied_handler):
if not applied_handler:
return
if len(os.listdir(path)) == 0:
shutil.rmtree(path)
print("Deleted %s since it was empty" % path)
if not self.nopyc:
def delete_folder_if_empty(path, applied_handler):
if not applied_handler:
return
if len(os.listdir(path)) == 0:
if not self.dry_run:
shutil.rmtree(path)
print("removed %s since it was empty" % path[len(self.source_folder):])
def delete_file(path):
os.remove(path)
print("Deleted %s" % path)
def delete_file(path):
print("removing '%s'" % path[len(self.source_folder):])
if not self.dry_run:
os.remove(path)
import fnmatch
recursively_handle_files(
os.path.abspath(self.__class__.source_folder),
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
folder_matcher=lambda dir, name, path: name != ".git",
folder_handler=delete_folder_if_empty,
file_handler=delete_file
)
import fnmatch
print("recursively removing *.pyc from '%s'" % self.source_folder)
recursively_handle_files(
os.path.abspath(self.source_folder),
lambda name: fnmatch.fnmatch(name.lower(), "*.pyc"),
folder_matcher=lambda dir, name, path: name != ".git",
folder_handler=delete_folder_if_empty,
file_handler=delete_file
)
class NewTranslation(Command):
+24
View File
@@ -237,3 +237,27 @@ class TestCommHelpers(unittest.TestCase):
result = canonicalize_temperatures(parsed, current)
self.assertDictEqual(expected, result)
@data(
("KEY1:Value 1 FIRMWARE_NAME:Some Firmware With Spaces KEY2:Value 2",
dict(KEY1="Value 1", KEY2="Value 2", FIRMWARE_NAME="Some Firmware With Spaces"))
)
@unpack
def test_parse_firmware_line(self, line, expected):
from octoprint.util.comm import parse_firmware_line
result = parse_firmware_line(line)
self.assertDictEqual(expected, result)
@data(
("Resend:23", 23),
("Resend: N23", 23),
("Resend: N:23", 23),
("rs 23", 23),
("rs N23", 23),
("rs N:23", 23),
("rs N23 expected checksum 109", 23) # teacup, see #300
)
@unpack
def test_parse_resend_line(self, line, expected):
from octoprint.util.comm import parse_resend_line
result = parse_resend_line(line)
self.assertEqual(expected, result)