diff --git a/.github/issue-validation.yml b/.github/issue-validation.yml new file mode 100644 index 000000000..763ca73a2 --- /dev/null +++ b/.github/issue-validation.yml @@ -0,0 +1,62 @@ +approve_label: approved +problem_label: incomplete +ignored_labels: + - approved + - bug + - request + - improvement + - brainstorming + - task + - rc feedback + - awaiting information + - not octoprint + - done +ignored_authors: + - "@OctoPrint" + - "sentry-io" + - "FormerLurker" + - "bzed" + +validation_comment: > + Hi @@@AUTHOR@@, + + + it looks like there is some **information missing** from your bug report that will + be needed in order to solve the problem. Read the [Contribution Guidelines](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md) + which will provide you with a template to *fully fill out* here so that your bug report + is ready to be investigated (I promise I'll go away then too!). + + + If you did not intend to report a bug but wanted to **request a feature or brain + storm** about some kind of development, please take special note of the title format + to use as described in the [Contribution Guidelines](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md). + + + **Please do not abuse the bug tracker as a support forum** - that can be found at + [community.octoprint.org](https://community.octoprint.org). Go there for any kind + of issues with network connectivity, webcam functionality, printer detection or + any other kind of such support requests or general questions. + + + Also **make sure you are at the right place** - this is the bug tracker of the official + version of OctoPrint, not the Raspberry Pi image OctoPi nor any unbundled third + party OctoPrint plugins or unofficial versions. Make sure too that you have **read + through the [Frequently Asked Questions](http://faq.octoprint.org)** and searched + the [**existing tickets**](https://github.com/OctoPrint/OctoPrint/issues) + for your problem - try multiple search terms please. + + + I'm marking this one now as needing some more information. Please understand that + if you do not provide that information within the next two weeks + I'll close this ticket so it doesn't clutter the bug tracker. This is nothing + personal, it's needed to keep this project manageable. Please just be considerate + and help the maintainers solve this problem + quickly by following the guidelines linked above. Remember, the less time the devs + have to spend running after information on tickets, the more time they have to actually + solve problems and add awesome new features. Thank you! + + + *I'm just a bot 🤖, not a human being, so don't expect any replies + from me :) Your ticket is read by humans too, I'm just not one of them.* + +keyphrase: I have read the FAQ diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 000000000..80ff4f957 --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -0,0 +1,37 @@ +name: "Cleanup issues & PRs" + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + lock: + name: 🔒 Lock issues & PRs closed over a year + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v2 + with: + github-token: ${{ github.token }} + issue-lock-comment: "" + pr-lock-comment: "" + + cleanup: + name: 🧹 Close issues marked as incomplete & older than 14 days + runs-on: ubuntu-latest + steps: + - id: date + run: | + echo "::set-output name=CUTOFF::`date --date='14 days ago' +'%Y-%m-%d'`" + - uses: OctoPrint/actions/close-by-query@main + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + query: "is:issue is:open label:incomplete created:<${{ steps.date.outputs.CUTOFF }}" + comment: > + Since apparently some of the required information is still missing, this will be + closed now, sorry. Feel free to request a reopen of this or create a new issue + once you can provide **all** + [required information](https://github.com/OctoPrint/OctoPrint/blob/master/CONTRIBUTING.md#how-to-file-a-bug-report). + + + This is nothing personal. Thank you for your collaboration. diff --git a/.github/workflows/issue_automation.yml b/.github/workflows/issue_automation.yml index f3024d73f..0ba8b6f44 100644 --- a/.github/workflows/issue_automation.yml +++ b/.github/workflows/issue_automation.yml @@ -4,7 +4,7 @@ on: types: [opened, edited, closed, reopened] jobs: - label: + issue-automation: runs-on: ubuntu-latest steps: - uses: actions/github-script@v2 @@ -62,3 +62,8 @@ jobs: labels: labels }) } + + - uses: OctoPrint/actions/issue-validation@main + if: github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'edited') + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml deleted file mode 100644 index b753d3fc0..000000000 --- a/.github/workflows/lock.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: "Lock outdated issues & PRs" - -on: - schedule: - - cron: "0 0 * * *" - -jobs: - lock: - runs-on: ubuntu-latest - steps: - - name: 🔒 Lock issues & PRs closed over a year - uses: dessant/lock-threads@v2 - with: - github-token: ${{ github.token }} - issue-lock-comment: "" - pr-lock-comment: "" diff --git a/.github/workflows/pr_automation.yml b/.github/workflows/pr_automation.yml index e770708a0..659733438 100644 --- a/.github/workflows/pr_automation.yml +++ b/.github/workflows/pr_automation.yml @@ -4,17 +4,13 @@ on: types: ["opened", "synchronize", "reopened", "edited", "labeled", "unlabeled"] jobs: - label: + pr-automation: runs-on: ubuntu-latest steps: - uses: actions/labeler@v3 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" - validate: - runs-on: ubuntu-latest - needs: label - steps: - uses: OctoPrint/actions/pr-validation@main with: - github-token: ${{ secrets.GITHUB_TOKEN }} + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.versioneer-lookup b/.versioneer-lookup index 916dedc30..6f5e25bb4 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,8 +24,10 @@ maintenance 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev fix/.* 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev improve/.* 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev -# staging/hotfix is the branch for preparation of the 1.5.3 hotfix release -staging/hotfix 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev +# staging/bugfix is the branch for preparation of the 1.5.3 hotfix release +# so are any bug/... branches +staging/bugfix 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev +bug/.* 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev # staging/maintenance is currently the branch for preparation of 1.5.0rc4 # so is regressionfix/... diff --git a/AUTHORS.md b/AUTHORS.md index f7477841b..b30ca9644 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -133,6 +133,7 @@ date of first contribution): * ["coliss86"](https://github.com/coliss86) * ["MichaIng"](https://github.com/MichaIng) * ["jasonbcox"](https://github.com/jasonbcox) + * ["shadycuz"](https://github.com/shadycuz) 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/SUPPORTERS.md b/SUPPORTERS.md index 0f64dedea..46d0e9a1d 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -6,19 +6,22 @@ thanks to everyone who contributed! ## Patrons & Sponsors + * 3DPrinterOS * Andrew Moorby * Arnljot Arntsen * Ash King * BigTreeTech * Boris Hussein * Brad Jackson + * BRANDON ROBERTSON * BuildBee * Christian Petropolis * Christian Wolf + * Creality3D * D Brian Kimmel * DeltaMaker 3D Printers * Dennis Breining - * Eric Berry + * Diana C Rodriguez * Eric Betts * Ernesto Martinez * Franziska Kunsmann @@ -26,12 +29,10 @@ thanks to everyone who contributed! * Greg Holloway * Hog Duske * Hopewell Medical Acupuncture Center - * Hugh Blemings * jean-claude migneault * Jefferson Hunt * Jeremy Cole * Joe Pasqua - * John Gregory Robinson * Joshua Wills * Justin Kaufman * Kaile Riser @@ -52,13 +53,14 @@ thanks to everyone who contributed! * Mosaic Manufacturing * Neil R. Goldberg * Patrick Glyré - * Patrick McGinnis + * Pete Barnwell * Prof Yuh Wen Chen * Raise3D * Randy C. Will * Ranjib Dey * Richard McGuire * Richard Michaud + * Richard Stocks * Rigid3D * Robert Gusek * Ronald Griehsler @@ -69,4 +71,4 @@ thanks to everyone who contributed! * Sven Mueller * Ulrich Kempken -and 2147 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)! +and 2225 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [Github Sponsors](https://github.com/users/foosel/sponsorship)! diff --git a/docs/development/branches.rst b/docs/development/branches.rst index d2fef6255..57ec18158 100644 --- a/docs/development/branches.rst +++ b/docs/development/branches.rst @@ -30,8 +30,8 @@ There are three main branches in OctoPrint: There are couple more RC and staging branches that see regular use: -``staging/hotfix`` - Any preparation for potential hotfix releases takes place here. +``staging/bugfix`` + Any preparation for potential bugfix releases takes place here. Version number follows the scheme ``..`` (e.g. ``1.5.1``) for a current release of ``..``. ``rc/maintenance`` @@ -56,8 +56,8 @@ There are couple more RC and staging branches that see regular use: Additionally, from time to time you might see other branches pop up in the repository. Those usually have one of the following prefixes: -``hotfix/...`` - Hotfixes under development that are to be merged into the ``staging/hotfix`` +``bug/...`` + Fixes under development that are to be merged into the ``staging/bugfix`` and later the ``master`` branch. ``fix/...`` Fixes under development that are to be merged into the ``maintenance`` diff --git a/docs/events/index.rst b/docs/events/index.rst index 7fa5e733e..71a55d68e 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -539,6 +539,34 @@ PrintResumed .. versionchanged:: 1.4.0 +GcodeScript${ScriptName}Running + A custom :ref:`GCODE script ` has started running. + + Payload: + + * ``name``: the file's name + * ``path``: the file's path within its storage location + * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``size``: the file's size in bytes (if available) + * ``owner``: the user who started the print job (if available) + * ``time``: the time needed for the print, in seconds (float) + + .. versionadded:: 1.6.0 + +GcodeScript${ScriptName}Finished + A custom :ref:`GCODE script ` has finished running. + + Payload: + + * ``name``: the file's name + * ``path``: the file's path within its storage location + * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``size``: the file's size in bytes (if available) + * ``owner``: the user who started the print job (if available) + * ``time``: the time needed for the print, in seconds (float) + + .. versionadded:: 1.6.0 + .. _sec-events-available_events-gcode_processing: GCODE processing diff --git a/docs/features/gcode_scripts.rst b/docs/features/gcode_scripts.rst index dbd84ef0d..d836d3fad 100644 --- a/docs/features/gcode_scripts.rst +++ b/docs/features/gcode_scripts.rst @@ -43,6 +43,15 @@ The following GCODE scripts are sent by OctoPrint automatically: Plugins may extend these scripts through :ref:`a hook `. +.. _sec-features-gcode_scripts-events: + +Events +------ + +Every GCODE script that is executed will emit two events. The event name will start with 'GcodeScript' followed by the capitalized name +of the script. When ``afterPrintDone`` has started the event will be ``GcodeScriptAfterPrintDoneRunning`` and once it has completed the last event +will be ``GcodeScriptAfterPrintDoneFinished``. You can find more details in the :ref:`Events ` documentation. + .. _sec-features-gcode_scripts-snippets: Snippets diff --git a/docs/plugins/distributing.rst b/docs/plugins/distributing.rst index f01bbf79b..35325d38f 100644 --- a/docs/plugins/distributing.rst +++ b/docs/plugins/distributing.rst @@ -60,3 +60,22 @@ that in the `Plugin Repository's help pages `_ when creating your plugin, you can find a prepared registration entry ``.md`` file in the ``extras`` folder of your plugin. + +Version management after the official plugin repository release +--------------------------------------------------------------- + +Once your plugin is available in the official plugin repository, you probably want to create and distribute new versions. +For "beta" users you can use the manual file distribution method, or a more elegant release channels (see below). +After you finalized a new plugin version, don't forget to actually update the version in the ``setup.py``, +and `submit a new release on github `_. + +After you published the new release, you can verify it on your installed octoprint, +with force checking the updates under the advanced options (in the software updates menu in the settings). +The new versions will appear to the plugin users in the next 24 hours (it depends on their cache refreshes). + +The `Software Update Plugin `_ has options to define multiple release channels, +and you can let the users decide if they want to test your pre-releases or not. +This can be achieved with defining ``stable_branch`` and ``prerelease_branches`` in the ``get_update_information`` function, +and creating github releases to the newly configured branches too. +For more information you can check the `Software Update Plugin documentation `_ +or read a more step-by-step writeup `here `_. diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index d4bf185e1..a8fb9b869 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -789,7 +789,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): list: A list of paths to additional files whose modification to track for (in)validating the cache. Ignored if ``None`` is returned. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -804,7 +804,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): list: A list of paths representing the only files whose modification to track for (in)validating the cache. Ignored if ``None`` is returned. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -817,7 +817,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: str: An alternatively calculated ETag value. Ignored if ``None`` is returned (default). - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -835,7 +835,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: (list): A list of additional fields for the ETag generation, or None - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return default_additional @@ -848,7 +848,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: int: An alternatively calculated LastModified value. Ignored if ``None`` is returned (default). - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -874,7 +874,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: dict: Additional data to persist in the preemptive cache configuration. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -892,7 +892,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): dict: Additional request data to persist in the preemptive cache configuration and to use for request environment construction. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return None @@ -908,7 +908,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): Returns: bool: Whether to suppress a record (True) or not (False, default) - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return False @@ -930,7 +930,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): and returning ``True`` to keep it and ``False`` to filter it out. If ``None`` is returned, no filtering will take place. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ return default_template_filter @@ -950,7 +950,7 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin): (list) A list of permissions which to check the current user session against. May be empty to indicate that no permission checks should be made by OctoPrint. - ..versionadded: 1.5.0 + .. versionadded: 1.5.0 """ from octoprint.access.permissions import Permissions @@ -1378,7 +1378,7 @@ class BlueprintPlugin(OctoPrintPlugin, RestartNeedingPlugin): and `the documentation for flask.Flask.errorhandler `_ for more information. - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ from collections import defaultdict @@ -1577,7 +1577,7 @@ class SettingsPlugin(OctoPrintPlugin): from flask_login import current_user - from octoprint.access.permissions import Permissions + from octoprint.access.permissions import OctoPrintPermission, Permissions data = copy.deepcopy(self._settings.get_all_data(merged=True)) if self.config_version_key in data: @@ -1629,9 +1629,15 @@ class SettingsPlugin(OctoPrintPlugin): "never": lambda: False, } - for level, condition in conditions.items(): - paths_for_level = restricted_paths.get(level, []) - for path in paths_for_level: + for level, paths in restricted_paths.items(): + if isinstance(level, OctoPrintPermission): + condition = lambda: ( + current_user is not None and current_user.has_permission(level) + ) + else: + condition = conditions.get(level, lambda: False) + + for path in paths: restrict_path_unless(data, path, condition) return data @@ -1705,12 +1711,15 @@ class SettingsPlugin(OctoPrintPlugin): Retrieves the list of paths in the plugin's settings which be restricted on the REST API. Override this in your plugin's implementation to restrict whether a path should only be returned to users with - the SETTINGS permission, any logged in users, or never on the REST API. + certain permissions, or never on the REST API. - Return a ``dict`` with the keys ``admin``, ``user``, ``never`` mapping to a list of paths (as tuples or lists of - the path elements) for which to restrict access via the REST API accordingly. Paths returned for the ``admin`` - key will only be available on the REST API when access with admin rights, ``user`` will only be available when accessed - as a logged in user. ``never`` will never be returned on the API. + Return a ``dict`` with one of the following keys, mapping to a list of paths (as tuples or lists of + the path elements) for which to restrict access via the REST API accordingly. + + * An :py:class:`~octoprint.access.permissions.OctoPrintPermission` instance: Paths will only be available on the REST API for users with the permission + * ``admin``: Paths will only be available on the REST API for users with admin rights (any user with the SETTINGS permission) + * ``user``: Paths will only be available on the REST API when accessed as a logged in user + * ``never``: Paths will never be returned on the API Example: @@ -1721,12 +1730,15 @@ class SettingsPlugin(OctoPrintPlugin): user_only=dict(path="path", bar="bar")), another=dict(admin_only=dict(path="path"), field="field"), - path=dict(to=dict(never=dict(return="return")))) + path=dict(to=dict(never=dict(return="return"))), + the=dict(webcam=dict(data="webcam"))) def get_settings_restricted_paths(self): - return dict(admin=[["some", "admin_only", "path"], ["another", "admin_only", "path"],], - user=[["some", "user_only", "path"],], - never=[["path", "to", "never", "return"],]) + from octoprint.access.permissions import Permissions + return {'admin':[["some", "admin_only", "path"], ["another", "admin_only", "path"],], + 'user':[["some", "user_only", "path"],], + 'never':[["path", "to", "never", "return"],], + Permissions.WEBCAM:[["the", "webcam", "data"],]} # this will make the plugin return settings on the REST API like this for an anonymous user # @@ -1734,15 +1746,26 @@ class SettingsPlugin(OctoPrintPlugin): # user_only=dict(path=None, bar="bar")), # another=dict(admin_only=dict(path=None), # field="field"), - # path=dict(to=dict(never=dict(return=None)))) + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data=None))) # - # like this for a logged in user + # like this for a logged in user without the webcam permission # # dict(some=dict(admin_only=dict(path=None, foo="foo"), # user_only=dict(path="path", bar="bar")), # another=dict(admin_only=dict(path=None), # field="field"), - # path=dict(to=dict(never=dict(return=None)))) + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data=None))) + # + # like this for a logged in user with the webcam permission + # + # dict(some=dict(admin_only=dict(path=None, foo="foo"), + # user_only=dict(path="path", bar="bar")), + # another=dict(admin_only=dict(path=None), + # field="field"), + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data="webcam"))) # # and like this for an admin user # @@ -1750,9 +1773,10 @@ class SettingsPlugin(OctoPrintPlugin): # user_only=dict(path="path", bar="bar")), # another=dict(admin_only=dict(path="path"), # field="field"), - # path=dict(to=dict(never=dict(return=None)))) + # path=dict(to=dict(never=dict(return=None))), + # the=dict(webcam=dict(data="webcam"))) - ..versionadded:: 1.2.17 + .. versionadded:: 1.2.17 """ return {} @@ -1790,7 +1814,7 @@ class SettingsPlugin(OctoPrintPlugin): Returns: (dict, dict): A tuple consisting of two dictionaries, the first being the plugin's preprocessors for - getters, the second the preprocessors for setters + getters, the second the preprocessors for setters """ return {}, {} @@ -1804,8 +1828,8 @@ class SettingsPlugin(OctoPrintPlugin): Returns: int or None: an int signifying the current settings format, should be incremented by plugins whenever there - are backwards incompatible changes. Returning None here disables the version tracking for the - plugin's configuration. + are backwards incompatible changes. Returning None here disables the version tracking for the + plugin's configuration. """ return None @@ -1841,7 +1865,7 @@ class SettingsPlugin(OctoPrintPlugin): the differences to the defaults (in case the current data was persisted with an older version of OctoPrint that still duplicated default data). - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ import octoprint.util from octoprint.settings import NoSuchSettingsPath @@ -1984,7 +2008,7 @@ class SlicerPlugin(OctoPrintPlugin): Returns: (dict) a dictionary containing a valid extension subtree. - ..versionadded:: 1.3.11 + .. versionadded:: 1.3.11 """ from octoprint.filemanager import ContentTypeMapping @@ -2001,7 +2025,7 @@ class SlicerPlugin(OctoPrintPlugin): Arguments: profile_path (str): The base folder where OctoPrint stores this slicer plugin's profiles - ..versionadded:: 1.3.7 + .. versionadded:: 1.3.7 """ from os import scandir @@ -2023,7 +2047,7 @@ class SlicerPlugin(OctoPrintPlugin): # noinspection PyMethodMayBeStatic def get_slicer_profiles_lastmodified(self, profile_path): """ - ..versionadded:: 1.3.0 + .. versionadded:: 1.3.0 """ import os from os import scandir diff --git a/src/octoprint/plugins/corewizard/templates/corewizard_pluginblacklist_wizard.jinja2 b/src/octoprint/plugins/corewizard/templates/corewizard_pluginblacklist_wizard.jinja2 index 744bcbc0d..8fa500e74 100644 --- a/src/octoprint/plugins/corewizard/templates/corewizard_pluginblacklist_wizard.jinja2 +++ b/src/octoprint/plugins/corewizard/templates/corewizard_pluginblacklist_wizard.jinja2 @@ -17,8 +17,12 @@ {% endtrans %}

-
+
@@ -91,7 +91,7 @@
- +
-
- -
diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index ec9e562b0..af03335fa 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -440,6 +440,15 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if name is None or not name: raise ValueError("name must be set") + # .capitalize() will lowercase all letters but the first + # this code preserves existing CamelCase + event_name = name[0].upper() + name[1:] + + event_start = "GcodeScript{}Running".format(event_name) + payload = context.get("event", None) if isinstance(context, dict) else None + + eventManager().fire(event_start, payload) + result = self._comm.sendGcodeScript( name, part_of_job=part_of_job, @@ -449,6 +458,9 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if not result and must_be_set: raise UnknownScript(name) + event_end = "GcodeScript{}Finished".format(event_name) + eventManager().fire(event_end, payload) + def jog(self, axes, relative=True, speed=None, *args, **kwargs): if isinstance(axes, str): # legacy parameter format, there should be an amount as first anonymous positional arguments too diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index c53d294af..ec023a7b3 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -307,6 +307,7 @@ def getSettings(): "allowFraming": s.getBoolean(["server", "allowFraming"]), }, "devel": {"pluginTimings": s.getBoolean(["devel", "pluginTimings"])}, + "slicing": {"defaultSlicer": s.get(["slicing", "defaultSlicer"])}, } gcode_scripts = s.listScripts("gcode") @@ -1007,6 +1008,10 @@ def _saveSettings(data): logging.getLogger("PLUGIN_TIMINGS").setLevel(logging.DEBUG) logging.getLogger("PLUGIN_TIMINGS").debug("Enabling plugin timings logging") + if "slicing" in data: + if "defaultSlicer" in data["slicing"]: + s.set(["slicing", "defaultSlicer"], data["slicing"]["defaultSlicer"]) + if "plugins" in data: for plugin in octoprint.plugin.plugin_manager().get_implementations( octoprint.plugin.SettingsPlugin diff --git a/tests/printer/test_script.py b/tests/printer/test_script.py new file mode 100644 index 000000000..b580e4ef7 --- /dev/null +++ b/tests/printer/test_script.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" +__copyright__ = "Copyright (C) 2021 The OctoPrint Project - Released under terms of the AGPLv3 License" + +import unittest + +from mock import ANY, MagicMock, call, patch + +from octoprint.printer.standard import Printer + + +class ScriptsTestCase(unittest.TestCase): + def setUp(self): + # mock comm + self.comm = MagicMock() + + # mock event manager + self.event_manager = MagicMock() + + self.event_manager_patcher = patch("octoprint.printer.standard.eventManager") + self.event_manager_getter = self.event_manager_patcher.start() + self.event_manager_getter.return_value = self.event_manager + + # mock plugin manager + self.plugin_manager = MagicMock() + self.plugin_manager.get_hooks.return_value = {} + + self.plugin_manager_patcher = patch("octoprint.printer.standard.plugin_manager") + self.plugin_manager_getter = self.plugin_manager_patcher.start() + self.plugin_manager_getter.return_value = self.plugin_manager + + # mock settings + self.settings = MagicMock() + self.settings.getInt.return_value = 1 + self.settings.getBoolean.return_value = False + + self.settings_patcher = patch("octoprint.printer.standard.settings") + self.settings_getter = self.settings_patcher.start() + self.settings_getter.return_value = self.settings + + self.printer = Printer(MagicMock(), MagicMock(), MagicMock()) + self.printer._comm = self.comm + + def tearDown(self): + self.settings_patcher.stop() + self.plugin_manager_patcher.stop() + self.event_manager_patcher.stop() + + def test_event_name(self): + self.printer.script("testEvent") + + self.event_manager.fire.assert_any_call("GcodeScriptTestEventRunning", ANY) + + def test_event_order(self): + self.printer.script("EventOrder") + + expected_order = [ + call("GcodeScriptEventOrderRunning", ANY), + call("GcodeScriptEventOrderFinished", ANY), + ] + + self.event_manager.fire.assert_has_calls(expected_order) + + def test_payload_handling(self): + expected_paylod = {"payloadKey": "payloadValue"} + context = {"event": expected_paylod} + + self.printer.script("GetPayload", context) + + self.event_manager.fire.assert_called_with(ANY, expected_paylod) + + self.printer.script("WrongPayload", []) + + self.event_manager.fire.assert_called_with(ANY, None) + + self.printer.script("WrongContext", {"noEvent": {}}) + + self.event_manager.fire.assert_called_with(ANY, None)