From b252da477cd102ce502b615b0496908412b3bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 22 Nov 2017 12:49:58 +0100 Subject: [PATCH 01/16] Virtual printer: allow empty/None prepared oks --- src/octoprint/plugins/virtual_printer/virtual.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 66fc05d01..dac7457fc 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -424,7 +424,9 @@ class VirtualPrinter(object): def _gcode_M114(self, data): output = "X:{} Y:{} Z:{} E:{} Count: A:{} B:{} C:{}".format(self._lastX, self._lastY, self._lastZ, self._lastE, int(self._lastX*100), int(self._lastY*100), int(self._lastZ*100)) if not self._okBeforeCommandOutput: - output = "{} {}".format(self._ok(), output) + ok = self._ok() + if ok: + output = "{} {}".format(self._ok(), output) self._send(output) return True @@ -555,7 +557,7 @@ class VirtualPrinter(object): def request_resend(): self._send("Resend:%d" % expected) - self._send(self._ok()) + self._sendOk() if settings().getBoolean(["devel", "virtualPrinter", "repetierStyleResends"]): request_resend() @@ -772,7 +774,9 @@ class VirtualPrinter(object): output = self._generateTemperatureOutput() if includeOk: - output = "{} {}".format(self._ok(), output) + ok = self._ok() + if ok: + output = "{} {}".format(ok, output) self._send(output) def _parseHotendCommand(self, line, wait=False, support_r=False): @@ -1156,7 +1160,9 @@ class VirtualPrinter(object): def _sendOk(self): if self.outgoing is None: return - self._send(self._ok()) + ok = self._ok() + if ok: + self._send(ok) def _sendWaitAfterTimeout(self, timeout=5): time.sleep(timeout) @@ -1171,6 +1177,8 @@ class VirtualPrinter(object): ok = self._okFormatString if self._prepared_oks: ok = self._prepared_oks.pop(0) + if ok is None: + return ok return ok.format(ok, lastN=self.lastN, buffer=self.buffered.maxsize - self.buffered.qsize()) From 622117564955b0fecd97d2fea10d0e9664f23c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 22 Nov 2017 13:00:17 +0100 Subject: [PATCH 02/16] Add note about how to run test suite --- CONTRIBUTING.md | 15 ++++++++++- docs/development/environment.rst | 43 +++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b8ba81c03..66f936c58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -263,6 +263,8 @@ See [How to open the Javascript Console in different browsers](https://webmaster ## Setting up a development environment See [the corresponding chapter in the documentation](http://docs.octoprint.org/en/master/development/index.html#setting-up-a-development-environment). +This also includes information on how to run the test suite and how to build +the documentation. ## Pull requests @@ -303,7 +305,17 @@ See [the corresponding chapter in the documentation](http://docs.octoprint.org/e * Make sure you do not add dead code (e.g. commented out left-overs from experiments). 8. Ensure your changes **pass the existing unit tests**. PRs that break - those cannot be accepted. + those cannot be accepted. You can run the unit tests locally (after + [initial development environment setup with "develop" dependencies](http://docs.octoprint.org/en/master/development/index.html#setting-up-a-development-environment)) + by running + + ``` + nosetests --with-doctest + ``` + + in the OctoPrint checkout folder. A [travis build](https://travis-ci.org/foosel/OctoPrint) + is also setup so that if the tests should fail, your PR will be marked + accordingly. 9. **Test your changes thoroughly**. That also means testing with usage scenarios you don't normally use, e.g. if you only use access control, test without and vice versa. If you only test with your printer, test with the @@ -432,6 +444,7 @@ the local version identifier to allow for an exact determination of the active c * 2017-03-10: Reproduce bugs in safe mode to make sure they are really caused by OctoPrint itself and not a misbehaving plugin. * 2017-03-27: Added safe mode section to ticket template. + * 2017-11-22: Added note on how to run the unit tests ## Footnotes * [1] - If you are wondering why, the problem is that anything that you add diff --git a/docs/development/environment.rst b/docs/development/environment.rst index 253956c7f..a9e18bb30 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -17,13 +17,21 @@ below. * `Git `_ * Checkout the OctoPrint sources from their Git repository: ``git clone https://github.com/foosel/OctoPrint.git`` - * Create a virtual environment in the checkout folder to use for installing and running OctoPrint and its + * Enter the checked out source folder: ``cd OctoPrint`` + * Create a virtual environment in the checked out source folder to use for installing and running OctoPrint and its dependencies (this avoids potential versioning issues for the dependencies with system wide installed instances): ``virtualenv venv`` - * Activate the virtual environment: ``source venv/bin/activate`` (might differ per your platform/OS) + * Activate the virtual environment: ``source venv/bin/activate`` (Linux, MacOS) or + ``source venv/Scripts/activate`` (Git Bash under Windows, see below) * Update ``pip`` in the virtual environment: ``pip install --upgrade pip`` * Install OctoPrint in `"editable" mode `_, - including its regular *and* development dependencies: ``pip install -e .[develop]`` + including its regular *and* development and plugin development dependencies: ``pip install -e .[develop,plugins]`` + +When the virtual environment is activated you can then: + + * run the OctoPrint server via ``octoprint serve`` + * run the test suite from the checked out source folder via ``nosetests --with-doctest`` + * build the documentation from the ``docs`` sub folder of the checked out sources via ``sphinx-build -b html . _build`` .. _sec-development-environment-source-linux: @@ -93,9 +101,6 @@ Open the Git Bash you just installed and in that: pip install --upgrade pip pip install -e .[develop,plugins] -You can then start OctoPrint via ``/c/Devel/OctoPrint/venv/Scripts/octoprint`` or just ``octoprint`` if you activated the virtual -environment. - .. _sec-development-environment-mac: Mac OS X @@ -139,9 +144,6 @@ You'll need a user account with administrator privileges. pip install --upgrade pip pip install -e .[develop,plugins] -You can then start OctoPrint via ``~/devel/OctoPrint/venv/bin/octoprint`` or just ``octoprint`` if you activated the virtual -environment. - .. _sec-development-environment-ides: IDE Setup @@ -177,6 +179,29 @@ PyCharm * Parameters: ``install -e .[develop,plugins]`` * Working directory: ``$ProjectFileDir$`` + - Add Run/Debug Configuration, select "Python tests" and therein "Nosetests": + + * Name: OctoPrint nosetests + * Target: Path, ``.`` + * Project: ``OctoPrint`` + * Python interpreter: the ``venv`` local virtual environment + * Working directory: the OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) + * Just like with the run configuration for the server you can also have the dependencies auto-update on run of + the tests, see above on how to set this up. + + - Add Run/Debug Configuration, select "Python docs" and therein "Sphinx task" + + * Name: OctoPrint docs + * Command: ``html`` + * Input: the ``docs`` folder in the OctoPrint checkout folder (e.g. ``~/devel/OctoPrint/docs`` or + ``C:\Devel\OctoPrint\docs``) + * Output: the ``docs/_build`` folder in the OctoPrint checkout folder (e.g. ``~/devel/OctoPrint/docs/_build`` or + ``C:\Devel\OctoPrint\docs\_build``) + * Project: ``OctoPrint`` + * Python interpreter: the ``venv`` local virtual environment + * Just like with the run configuration for the server you can also have the dependencies auto-update when building + the documentation, see above on how to set this up. + .. note:: Make sure you are running a PyCharm version of 2016.1 or later, or manually fix From 8bc99f928ced28eb072d609459a202d4e5747512 Mon Sep 17 00:00:00 2001 From: caikn Date: Wed, 22 Nov 2017 12:52:48 +0000 Subject: [PATCH 03/16] add installation doc for SLES --- docs/development/index.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/development/index.rst b/docs/development/index.rst index 7d24a843e..90fbe93f5 100644 --- a/docs/development/index.rst +++ b/docs/development/index.rst @@ -56,6 +56,12 @@ installed: Using a Linux distribution that doesn't use ``apt``? Please send a `Pull Request `_ to get the necessary steps into this guide! + * On zypper based distributions (example below for SLES 12 SP2): + + sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/python/SLE_12_SP2/ pyhton_devel + sudo zypper ref + sudo zypper in python python-pip python-devel python-setuptools python-virtualenv git libyaml-devel + sudo zypper in -t pattern Basis-Devel Then: From e32f469de40a7ea4aabc1fac4d1406cfde97d2c9 Mon Sep 17 00:00:00 2001 From: caikn Date: Wed, 22 Nov 2017 14:04:32 +0000 Subject: [PATCH 04/16] fix typo --- docs/development/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/index.rst b/docs/development/index.rst index 90fbe93f5..7c8c73118 100644 --- a/docs/development/index.rst +++ b/docs/development/index.rst @@ -58,7 +58,7 @@ installed: steps into this guide! * On zypper based distributions (example below for SLES 12 SP2): - sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/python/SLE_12_SP2/ pyhton_devel + sudo zypper ar https://download.opensuse.org/repositories/devel:/languages:/python/SLE_12_SP2/ python_devel sudo zypper ref sudo zypper in python python-pip python-devel python-setuptools python-virtualenv git libyaml-devel sudo zypper in -t pattern Basis-Devel From f4eb60dc6aa48c8475bcbf114d3d474ebd1ebc3a Mon Sep 17 00:00:00 2001 From: alex-gh Date: Thu, 23 Nov 2017 13:53:01 +0100 Subject: [PATCH 05/16] Improved the checksumming speed by a factor of 1.4-3.4 --- AUTHORS.md | 1 + src/octoprint/util/comm.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 4fb77ffbf..a08602296 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -85,6 +85,7 @@ date of first contribution): * [Luke McKechnie](https://github.com/galamdring) * [Peter Backx](https://github.com/pbackx) * [Josh Major](https://github.com/astateofblank) + * ["alex-gh"](https://github.com/alex-gh) 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 diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 394f9cc9b..44a6605af 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2472,8 +2472,8 @@ class MachineCom(object): def _do_send_with_checksum(self, command, linenumber): command_to_send = "N" + str(linenumber) + " " + command checksum = 0 - for c in command_to_send: - checksum ^= ord(c) + for c in bytearray(command_to_send): + checksum ^= c command_to_send = command_to_send + "*" + str(checksum) self._do_send_without_checksum(command_to_send) From 4a5308b4abc0511542b17e0e182917e0ccf4adf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 10:51:14 +0100 Subject: [PATCH 06/16] Fix plugin detection only finding one plugin We actually should iterate over ALL of the generator, not just its first entry m) --- src/octoprint/plugin/core.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 04b000c8a..9d16a2aee 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -639,13 +639,12 @@ class PluginManager(object): def wrapped(gen): # to protect against some issues in installed packages that make iteration over entry points # fall on its face - e.g. https://groups.google.com/forum/#!msg/octoprint/DyXdqhR0U7c/kKMUsMmIBgAJ - try: - yield next(gen) - except StopIteration: - raise - except: - self.logger.exception("Something went wrong while processing the entry points of a package in the " - "Python environment - broken entry_points.txt in some package?") + for entry in gen: + try: + yield entry + except: + self.logger.exception("Something went wrong while processing the entry points of a package in the " + "Python environment - broken entry_points.txt in some package?") for group in groups: for entry_point in wrapped(working_set.iter_entry_points(group=group, name=None)): From 26789a2bb7c6fae8d756b4ca8236d1cfb5491be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 11:26:27 +0100 Subject: [PATCH 07/16] CPU frequency might be reported as None Don't die when that's the case. --- src/octoprint/environment.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/octoprint/environment.py b/src/octoprint/environment.py index 2da7bcc42..13c513ffd 100644 --- a/src/octoprint/environment.py +++ b/src/octoprint/environment.py @@ -75,9 +75,18 @@ class EnvironmentDetector(object): return result def _detect_hardware(self): - return dict(cores=psutil.cpu_count(), - freq=psutil.cpu_freq().max, - ram=get_formatted_size(psutil.virtual_memory().total)) + cores = psutil.cpu_count() + cpu_freq = psutil.cpu_freq() + ram = psutil.virtual_memory() + + result = dict() + if cores: + result["cores"] = cores + if cpu_freq and hasattr(cpu_freq, "max"): + result["freq"] = cpu_freq.max + if ram and hasattr(ram, "total"): + result["ram"] = ram.total + return result def _detect_from_plugins(self): result = dict() From b002e41a005f69af855f53ef25d35983a9869429 Mon Sep 17 00:00:00 2001 From: Gregers Gram Rygg Date: Wed, 22 Nov 2017 11:53:30 +0100 Subject: [PATCH 08/16] Respond with 411 Length Required when missing --- src/octoprint/server/util/tornado.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index e21a4dfdb..b7610b07b 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -207,7 +207,7 @@ class UploadStorageFallbackHandler(RequestlessExceptionLoggingMixin): if self.is_multipart(): if not self._bytes_left: # we don't support requests without a content-length - raise tornado.web.HTTPError(400, log_message="No Content-Length supplied") + raise tornado.web.HTTPError(411, log_message="No Content-Length supplied") # extract the multipart boundary fields = self._content_type.split(";") From 364d692db2de650e6b9603d4803639b75edc1188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 13:07:16 +0100 Subject: [PATCH 09/16] Support leaf merging for file extension tree This allows us to add new extensions to existing entries (e.g. a new extension for gcode files) --- src/octoprint/filemanager/__init__.py | 44 +++++++++++++++++++++++++-- src/octoprint/util/__init__.py | 31 +++++++++++++++++-- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index 513e91e88..2cacb459e 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -28,7 +28,12 @@ ContentTypeDetector = namedtuple("ContentTypeDetector", "extensions, detector") extensions = dict( ) -def full_extension_tree(): +_cached_tree = None +def full_extension_tree(force=False): + global _cached_tree + if _cached_tree is not None and not force: + return _cached_tree + result = dict( # extensions for 3d model files model=dict( @@ -40,16 +45,51 @@ def full_extension_tree(): ) ) + def leaf_merger(a, b): + supported_leaf_types = (ContentTypeMapping, ContentTypeDetector, list) + if not isinstance(a, supported_leaf_types) or not isinstance(b, supported_leaf_types): + raise ValueError() + + if isinstance(a, ContentTypeDetector) and isinstance(b, ContentTypeMapping): + raise ValueError() + + if isinstance(a, ContentTypeMapping) and isinstance(b, ContentTypeDetector): + raise ValueError() + + a_list = a if isinstance(a, list) else a.extensions + b_list = b if isinstance(b, list) else b.extensions + merged = a_list + b_list + + content_type = None + if isinstance(b, ContentTypeMapping): + content_type = b.content_type + elif isinstance(a, ContentTypeMapping): + content_type = a.content_type + + detector = None + if isinstance(b, ContentTypeDetector): + detector = b.detector + elif isinstance(a, ContentTypeDetector): + detector = a.detector + + if content_type is not None: + return ContentTypeMapping(merged, content_type) + elif detector is not None: + return ContentTypeDetector(merged, detector) + else: + return merged + extension_tree_hooks = octoprint.plugin.plugin_manager().get_hooks("octoprint.filemanager.extension_tree") for name, hook in extension_tree_hooks.items(): try: hook_result = hook() if hook_result is None or not isinstance(hook_result, dict): continue - result = octoprint.util.dict_merge(result, hook_result) + result = octoprint.util.dict_merge(result, hook_result, leaf_merger=leaf_merger) except: logging.getLogger(__name__).exception("Exception while retrieving additional extension tree entries from hook {name}".format(name=name)) + _cached_tree = result return result def get_extensions(type, subtree=None): diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index a06dffcc6..e4b7932cb 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -459,7 +459,7 @@ def is_running_from_source(): return os.path.isdir(os.path.join(root, "src")) and os.path.isfile(os.path.join(root, "setup.py")) -def dict_merge(a, b): +def dict_merge(a, b, leaf_merger=None): """ Recursively deep-merges two dictionaries. @@ -478,10 +478,24 @@ def dict_merge(a, b): True >>> dict_merge(None, None) == dict() True + >>> def leaf_merger(a, b): + ... if isinstance(a, list) and isinstance(b, list): + ... return a + b + ... raise ValueError() + >>> result = dict_merge(dict(l1=[3, 4], l2=[1], a="a"), dict(l1=[1, 2], l2="foo", b="b"), leaf_merger=leaf_merger) + >>> result.get("l1") == [3, 4, 1, 2] + True + >>> result.get("l2") == "foo" + True + >>> result.get("a") == "a" + True + >>> result.get("b") == "b" + True Arguments: a (dict): The dictionary to merge ``b`` into b (dict): The dictionary to merge into ``a`` + leaf_merger (callable): An optional callable to use to merge leaves (non-dict values) Returns: dict: ``b`` deep-merged into ``a`` @@ -499,9 +513,20 @@ def dict_merge(a, b): result = deepcopy(a) for k, v in b.items(): if k in result and isinstance(result[k], dict): - result[k] = dict_merge(result[k], v) + result[k] = dict_merge(result[k], v, leaf_merger=leaf_merger) else: - result[k] = deepcopy(v) + merged = None + if k in result and callable(leaf_merger): + try: + merged = leaf_merger(result[k], v) + except ValueError: + # can't be merged by leaf merger + pass + + if merged is None: + merged = deepcopy(v) + + result[k] = merged return result From 9b3c1947d9b5e33cd80cbdae01f7ccd085ae77af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 13:08:10 +0100 Subject: [PATCH 10/16] Limit SD transfers to broader machinecode type See jneilliii/OctoPrint-SmoothiewareConfig#1 --- src/octoprint/server/api/files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 5cd9dede5..4ba185f40 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -324,7 +324,7 @@ def uploadGcodeFile(target): Depending on the file's destination triggers either streaming to SD card or directly calls selectAndOrPrint. """ - if destination == FileDestinations.SDCARD and octoprint.filemanager.valid_file_type(filename, "gcode"): + if destination == FileDestinations.SDCARD and octoprint.filemanager.valid_file_type(filename, "machinecode"): return filename, printer.add_sd_file(filename, absFilename, selectAndOrPrint) else: selectAndOrPrint(filename, absFilename, destination) From 0de0e4ea9bd5fec2abea17f9dc86b6c3700d9ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 13:11:23 +0100 Subject: [PATCH 11/16] Handling of non gcode SD file transfers No guarantees however that transporting anything BUT gcode via the usual M28/M29 interface will even remotely work. Note that it most likely won't work if the transferred file contains an M29 (= end transfer), just like with transferred GCODE files. Also note that stuff like config files or some such that might be transferred might contain lines that are too large to fit into the buffer of the printer. This is really just to enable plugins to maybe do some nifty stuff, no official support of streaming arbitrary files to the printer's SD (for that we'd need WAY more firmware support first). See jneilliii/OctoPrint-SmoothiewareConfig#1 --- src/octoprint/printer/standard.py | 14 +++++++++----- src/octoprint/util/comm.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 1976b750d..7a619c45c 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -595,12 +595,16 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self.refresh_sd_files(blocking=True) existingSdFiles = map(lambda x: x[0], self._comm.getSdFiles()) - remoteName = util.get_dos_filename(filename, - existing_filenames=existingSdFiles, - extension="gco", - whitelisted_extensions=["gco", "g"]) + if valid_file_type(filename, "gcode"): + remoteName = util.get_dos_filename(filename, + existing_filenames=existingSdFiles, + extension="gco", + whitelisted_extensions=["gco", "g"]) + else: + # probably something else added through a plugin, use it's basename as-is + remoteName = os.path.basename(filename) self._timeEstimationData = TimeEstimationHelper() - self._comm.startFileTransfer(absolutePath, filename, "/" + remoteName) + self._comm.startFileTransfer(absolutePath, filename, "/" + remoteName, special=not valid_file_type(filename, "gcode")) return remoteName diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 44a6605af..425b54d8c 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -877,7 +877,7 @@ class MachineCom(object): self._changeState(self.STATE_ERROR) eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - def startFileTransfer(self, filename, localFilename, remoteFilename): + def startFileTransfer(self, filename, localFilename, remoteFilename, special=False): if not self.isOperational() or self.isBusy(): self._logger.info("Printer is not operational or busy") return @@ -885,7 +885,10 @@ class MachineCom(object): with self._jobLock: self.resetLineNumbers() - self._currentFile = StreamingGcodeFileInformation(filename, localFilename, remoteFilename) + if special: + self._currentFile = SpecialStreamingGcodeFileInformation(filename, localFilename, remoteFilename) + else: + self._currentFile = StreamingGcodeFileInformation(filename, localFilename, remoteFilename) self._currentFile.start() self.sendCommand("M28 %s" % remoteFilename) @@ -2356,7 +2359,7 @@ class MachineCom(object): # now comes the part where we increase line numbers and send stuff - no turning back now command_requiring_checksum = gcode is not None and gcode in self._checksum_requiring_commands command_allowing_checksum = gcode is not None or self._sendChecksumWithUnknownCommands - checksum_enabled = not self._neverSendChecksum and (self.isPrinting() or + checksum_enabled = not self._neverSendChecksum and ((self.isPrinting() and self._currentFile and self._currentFile.checksum) or self._alwaysSendChecksum or not self._firmware_info_received) @@ -2825,6 +2828,8 @@ class PrintingFileInformation(object): value between 0 and 1. """ + checksum = True + def __init__(self, filename): self._logger = logging.getLogger(__name__) self._filename = filename @@ -2879,6 +2884,8 @@ class PrintingSdFileInformation(PrintingFileInformation): Encapsulates information regarding an ongoing print from SD. """ + checksum = False + def __init__(self, filename, size): PrintingFileInformation.__init__(self, filename) self._size = size @@ -3025,6 +3032,23 @@ class StreamingGcodeFileInformation(PrintingGcodeFileInformation): self._logger.info("Finished in {duration:.3f} s. Approx. transfer rate of {rate:.3f} lines/s or {time_per_line:.3f} ms per line".format(**stats)) +class SpecialStreamingGcodeFileInformation(StreamingGcodeFileInformation): + """ + For streaming files to the printer that aren't GCODE. + + Difference to regular StreamingGcodeFileInformation: no checksum requirement, only rudimentary line processing + (stripping of whitespace from the end and ignoring of empty lines) + """ + + checksum = False + + def _process(self, line, offsets, current_tool): + line = line.rstrip() + if not len(line): + return None + return line + + class SendQueue(PrependableQueue): def __init__(self, maxsize=0): From 991dab58d5c4346237792aa874d3ffede253f194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 13:20:50 +0100 Subject: [PATCH 12/16] Remove experimental extension tree caching --- src/octoprint/filemanager/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index 2cacb459e..794a7f72a 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -28,12 +28,7 @@ ContentTypeDetector = namedtuple("ContentTypeDetector", "extensions, detector") extensions = dict( ) -_cached_tree = None -def full_extension_tree(force=False): - global _cached_tree - if _cached_tree is not None and not force: - return _cached_tree - +def full_extension_tree(): result = dict( # extensions for 3d model files model=dict( @@ -89,7 +84,6 @@ def full_extension_tree(force=False): except: logging.getLogger(__name__).exception("Exception while retrieving additional extension tree entries from hook {name}".format(name=name)) - _cached_tree = result return result def get_extensions(type, subtree=None): From 6d4f8266cd5957fdb736ecfdd3a0378379fd84da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Nov 2017 13:46:38 +0100 Subject: [PATCH 13/16] Fix message for synchronous system commands We managed to swap those m( --- src/octoprint/static/js/app/viewmodels/system.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/system.js b/src/octoprint/static/js/app/viewmodels/system.js index 5021aa82b..af1dbb87c 100644 --- a/src/octoprint/static/js/app/viewmodels/system.js +++ b/src/octoprint/static/js/app/viewmodels/system.js @@ -49,9 +49,9 @@ $(function() { .done(function() { var text; if (commandSpec.async) { - text = gettext("The command \"%(command)s\" executed successfully"); - } else { text = gettext("The command \"%(command)s\" was triggered asynchronously"); + } else { + text = gettext("The command \"%(command)s\" executed successfully"); } new PNotify({ From cf25291dee6b928bfe52c639728f46a2cc840360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Nov 2017 12:23:20 +0100 Subject: [PATCH 14/16] Mark readonly fields readonly instead of disabled Further fix for FF issues with disabled input fields as tracked in #2056 and #2196. --- src/octoprint/templates/dialogs/settings/accesscontrol.jinja2 | 2 +- src/octoprint/templates/dialogs/settings/api.jinja2 | 2 +- src/octoprint/templates/dialogs/usersettings/access.jinja2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octoprint/templates/dialogs/settings/accesscontrol.jinja2 b/src/octoprint/templates/dialogs/settings/accesscontrol.jinja2 index c6eb07475..023ef40a9 100644 --- a/src/octoprint/templates/dialogs/settings/accesscontrol.jinja2 +++ b/src/octoprint/templates/dialogs/settings/accesscontrol.jinja2 @@ -137,7 +137,7 @@
- + diff --git a/src/octoprint/templates/dialogs/settings/api.jinja2 b/src/octoprint/templates/dialogs/settings/api.jinja2 index 77df62960..ea893d372 100644 --- a/src/octoprint/templates/dialogs/settings/api.jinja2 +++ b/src/octoprint/templates/dialogs/settings/api.jinja2 @@ -17,7 +17,7 @@
- +
diff --git a/src/octoprint/templates/dialogs/usersettings/access.jinja2 b/src/octoprint/templates/dialogs/usersettings/access.jinja2 index 9b17779c2..3a1b07a3a 100644 --- a/src/octoprint/templates/dialogs/usersettings/access.jinja2 +++ b/src/octoprint/templates/dialogs/usersettings/access.jinja2 @@ -24,7 +24,7 @@
- + From a2d38016ece6cf39f8865b51bb682686a52bb8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Nov 2017 12:38:13 +0100 Subject: [PATCH 15/16] Fix some corner cases of print time formatting Closes #2242 --- src/octoprint/static/js/app/helpers.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index 471a1edd6..ae91ade7a 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -416,7 +416,7 @@ function formatFuzzyPrintTime(totalSeconds) { var seconds = d.seconds(); var minutes = d.minutes(); var hours = d.hours(); - var days = d.asDays(); + var days = d.days(); var replacements = { days: days, @@ -432,11 +432,16 @@ function formatFuzzyPrintTime(totalSeconds) { // days if (hours >= 16) { replacements.days += 1; - text = gettext("%(days)d days"); + + if (replacements.days === 1) { + text = gettext("%(days)d day"); + } else { + text = gettext("%(days)d days"); + } } else if (hours >= 8 && hours < 16) { text = gettext("%(days)d.5 days"); } else { - if (days == 1) { + if (days === 1) { text = gettext("%(days)d day"); } else { text = gettext("%(days)d days"); @@ -447,7 +452,7 @@ function formatFuzzyPrintTime(totalSeconds) { if (hours < 12) { if (minutes < 15) { // less than .15 => .0 - if (hours == 1) { + if (hours === 1) { text = gettext("%(hours)d hour"); } else { text = gettext("%(hours)d hours"); @@ -458,10 +463,15 @@ function formatFuzzyPrintTime(totalSeconds) { } else { // over .75 => hours + 1 replacements.hours += 1; - text = gettext("%(hours)d hours"); + + if (replacements.hours === 1) { + text = gettext("%(hours)d hour"); + } else { + text = gettext("%(hours)d hours"); + } } } else { - if (hours == 23 && minutes > 30) { + if (hours === 23 && minutes > 30) { // over 23.5 hours => 1 day text = gettext("1 day"); } else { From d174d7ab8094b49afd660689a274349043747eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Nov 2017 17:24:40 +0100 Subject: [PATCH 16/16] Temporary fix for #2246 until #2200 is solved --- src/octoprint/server/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index a6cc60b12..29ea347b7 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -1255,7 +1255,7 @@ class Server(object): # JS js_filters = ["sourcemap_remove", "js_delimiter_bundler"] - js_plugin_filters = ["sourcemap_remove", "js_plugin_delimiter_bundler"] + js_plugin_filters = ["sourcemap_remove", "js_delimiter_bundler"] # TODO: replace with IIFE wrapper again, see #2200 js_libs_bundle = Bundle(*js_libs, output="webassets/packed_libs.js", filters=",".join(js_filters))