From 467e7d6c9ce48bcd57ec7c8f2f9729b2ac0cf7f2 Mon Sep 17 00:00:00 2001 From: Jacopo Tediosi Date: Mon, 4 May 2026 19:33:22 +0200 Subject: [PATCH 1/4] Remove use of current_user.is_admin It no longer exists in OctoPrint 2.0.0 and caused the plugin installation to fail. It was needed only as a failsafe on very old OctoPrint versions that virtually no one uses anymore, so we can just safely remove the entire on_settings_load() function. --- octoprint_gcodesystemcommands/__init__.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/octoprint_gcodesystemcommands/__init__.py b/octoprint_gcodesystemcommands/__init__.py index 07766fe..7a2a51a 100644 --- a/octoprint_gcodesystemcommands/__init__.py +++ b/octoprint_gcodesystemcommands/__init__.py @@ -95,17 +95,6 @@ def get_settings_defaults(self): def get_settings_restricted_paths(self): return dict(admin=[["command_definitions"]]) - - def on_settings_load(self): - data = octoprint.plugin.SettingsPlugin.on_settings_load(self) - - # only return our restricted settings to admin users - this is only needed for OctoPrint <= 1.2.16 - restricted = ("command_definitions") - for r in restricted: - if r in data and (current_user is None or current_user.is_anonymous() or not current_user.is_admin()): - data[r] = None - - return data def on_settings_save(self, data): octoprint.plugin.SettingsPlugin.on_settings_save(self, data) From 048c5535c717c2c9f9cc60cdd882f7400d142c81 Mon Sep 17 00:00:00 2001 From: Jacopo Tediosi Date: Mon, 4 May 2026 19:33:36 +0200 Subject: [PATCH 2/4] Remove unused imports --- octoprint_gcodesystemcommands/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/octoprint_gcodesystemcommands/__init__.py b/octoprint_gcodesystemcommands/__init__.py index 7a2a51a..fc14af3 100644 --- a/octoprint_gcodesystemcommands/__init__.py +++ b/octoprint_gcodesystemcommands/__init__.py @@ -6,8 +6,6 @@ __copyright__ = "Copyright (C) 2017 Shawn Bruce - Released under terms of the AGPLv3 License" import octoprint.plugin -import time -import os import sys import subprocess import re From 5b5619912f55e3ddedb4bf17f795cef154897a07 Mon Sep 17 00:00:00 2001 From: Jacopo Tediosi Date: Mon, 4 May 2026 19:35:03 +0200 Subject: [PATCH 3/4] Ruff refactor --- octoprint_gcodesystemcommands/__init__.py | 87 ++++++++++++----------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/octoprint_gcodesystemcommands/__init__.py b/octoprint_gcodesystemcommands/__init__.py index fc14af3..d5250fd 100644 --- a/octoprint_gcodesystemcommands/__init__.py +++ b/octoprint_gcodesystemcommands/__init__.py @@ -3,22 +3,25 @@ __author__ = "Shawn Bruce " __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" -__copyright__ = "Copyright (C) 2017 Shawn Bruce - Released under terms of the AGPLv3 License" +__copyright__ = ( + "Copyright (C) 2017 Shawn Bruce - Released under terms of the AGPLv3 License" +) import octoprint.plugin import sys import subprocess import re -class GCodeSystemCommands(octoprint.plugin.StartupPlugin, - octoprint.plugin.TemplatePlugin, - octoprint.plugin.AssetPlugin, - octoprint.plugin.SettingsPlugin): +class GCodeSystemCommands( + octoprint.plugin.StartupPlugin, + octoprint.plugin.TemplatePlugin, + octoprint.plugin.AssetPlugin, + octoprint.plugin.SettingsPlugin, +): def __init__(self): self.command_definitions = {} - def on_settings_initialized(self): self.reload_command_definitions() @@ -29,19 +32,21 @@ def reload_command_definitions(self): self._logger.debug("command_definitions: %s" % command_definitions_tmp) for definition in command_definitions_tmp: - cmd_id = definition['id'] - cmd_line = definition['command'] + cmd_id = definition["id"] + cmd_line = definition["command"] self.command_definitions[cmd_id] = cmd_line self._logger.info("Add command definition OCTO%s = %s" % (cmd_id, cmd_line)) - def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): + def hook_gcode_sending( + self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs + ): if gcode: return - if cmd[:4] != 'OCTO': + if cmd[:4] != "OCTO": return - match = re.search(r'^(OCTO[0-9]+)(?:\s(.*))?$', cmd) + match = re.search(r"^(OCTO[0-9]+)(?:\s(.*))?$", cmd) if match is None: return @@ -55,18 +60,26 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, comm_instance._log("Return(GCodeSystemCommands): undefined") return (None,) - self._logger.debug("Command ID=%s, Line=%s, Args=%s" % (cmd_id, cmd_line, cmd_args)) + self._logger.debug( + "Command ID=%s, Line=%s, Args=%s" % (cmd_id, cmd_line, cmd_args) + ) self._logger.info("Executing command ID: %s" % cmd_id) comm_instance._log("Exec(GCodeSystemCommands): OCTO%s" % cmd_id) cmd_env = {} - cmd_env['OCTOPRINT_GCODESYSTEMCOMMAND_ID'] = str(cmd_id) - cmd_env['OCTOPRINT_GCODESYSTEMCOMMAND_ARGS'] = str(cmd_args) if cmd_args else '' - cmd_env['OCTOPRINT_GCODESYSTEMCOMMAND_LINE'] = str(cmd) + cmd_env["OCTOPRINT_GCODESYSTEMCOMMAND_ID"] = str(cmd_id) + cmd_env["OCTOPRINT_GCODESYSTEMCOMMAND_ARGS"] = str(cmd_args) if cmd_args else "" + cmd_env["OCTOPRINT_GCODESYSTEMCOMMAND_LINE"] = str(cmd) try: - p = subprocess.Popen(cmd_line, env=cmd_env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) + p = subprocess.Popen( + cmd_line, + env=cmd_env, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + shell=True, + ) output = p.communicate()[0] r = p.returncode except: @@ -74,66 +87,56 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, self._logger.exception("Error executing command ID %s: %s" % (cmd_id, e)) return (None,) - self._logger.debug("Command ID %s returned: %s, output=%s" % (cmd_id, r, output)) + self._logger.debug( + "Command ID %s returned: %s, output=%s" % (cmd_id, r, output) + ) self._logger.info("Command ID %s returned: %s" % (cmd_id, r)) if r == 0: - status = 'ok' + status = "ok" else: - status = 'error' + status = "error" comm_instance._log("Return(GCodeSystemCommands): %s" % status) return (None,) def get_settings_defaults(self): - return dict( - command_definitions = [] - ) + return dict(command_definitions=[]) def get_settings_restricted_paths(self): return dict(admin=[["command_definitions"]]) - + def on_settings_save(self, data): octoprint.plugin.SettingsPlugin.on_settings_save(self, data) self.reload_command_definitions() def get_template_configs(self): - return [ - dict(type="settings", custom_bindings=True) - ] + return [dict(type="settings", custom_bindings=True)] def get_assets(self): - return { - "js": ["js/gcodesystemcommands.js"] - } + return {"js": ["js/gcodesystemcommands.js"]} def get_update_information(self): return dict( gcodesystemcommands=dict( displayName="GCode System Commands", displayVersion=self._plugin_version, - # version check: github repository type="github_release", user="kantlivelong", repo="OctoPrint-GCodeSystemCommands", current=self._plugin_version, - # update method: pip w/ dependency links - pip="https://github.com/kantlivelong/OctoPrint-GCodeSystemCommands/archive/{target_version}.zip" + pip="https://github.com/kantlivelong/OctoPrint-GCodeSystemCommands/archive/{target_version}.zip", ) ) + __plugin_name__ = "GCODE System Commands" __plugin_pythoncompat__ = ">=2.7,<4" - -def __plugin_load__(): - global __plugin_implementation__ - __plugin_implementation__ = GCodeSystemCommands() - - global __plugin_hooks__ - __plugin_hooks__ = { - "octoprint.comm.protocol.gcode.sending": __plugin_implementation__.hook_gcode_sending, - "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information - } +__plugin_implementation__ = GCodeSystemCommands() +__plugin_hooks__ = { + "octoprint.comm.protocol.gcode.sending": __plugin_implementation__.hook_gcode_sending, + "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information, +} From e37cf1789cc5c17798db132aeb0ec3f94d27b91b Mon Sep 17 00:00:00 2001 From: Jacopo Tediosi Date: Mon, 4 May 2026 19:36:42 +0200 Subject: [PATCH 4/4] Implement is_template_autoescaped Ref: https://docs.octoprint.org/en/dev/plugins/mixins.html#octoprint.plugin.TemplatePlugin.is_template_autoescaped --- octoprint_gcodesystemcommands/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/octoprint_gcodesystemcommands/__init__.py b/octoprint_gcodesystemcommands/__init__.py index d5250fd..22825cc 100644 --- a/octoprint_gcodesystemcommands/__init__.py +++ b/octoprint_gcodesystemcommands/__init__.py @@ -116,6 +116,9 @@ def get_template_configs(self): def get_assets(self): return {"js": ["js/gcodesystemcommands.js"]} + + def is_template_autoescaped(self): + True def get_update_information(self): return dict(