Skip to content

Commit

Permalink
Make AutomaticShutdown work with OctoPi 0.18.0 + OctoPrint 1.7.2
Browse files Browse the repository at this point in the history
* Fixed identations
* Fixed `sarge.run` usage
* Updated Python compatibility
* Changed all Github references to this repo
  • Loading branch information
Adriano Cunha committed Nov 26, 2021
1 parent 9627170 commit 072c64d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ The user can enable automatic shutdown for each print by using a checkbox in the

## Setup

Install via the bundled [Plugin Manager](https://github.com/foosel/OctoPrint/wiki/Plugin:-Plugin-Manager)
or manually using this URL:
Install manually using this URL:

https://github.com/OctoPrint/OctoPrint-AutomaticShutdown/archive/master.zip
https://github.com/adrcunha/OctoPrint-AutomaticShutdown/archive/master.zip

## Configuration

Expand Down
6 changes: 3 additions & 3 deletions extras/automaticshutdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license: AGPLv3

date: 2015-08-27

homepage: https://github.com/OctoPrint/OctoPrint-AutomaticShutdown
source: https://github.com/OctoPrint/OctoPrint-AutomaticShutdown
archive: https://github.com/OctoPrint/OctoPrint-AutomaticShutdown/archive/master.zip
homepage: https://github.com/adrcunha/OctoPrint-AutomaticShutdown
source: https://github.com/adrcunha/OctoPrint-AutomaticShutdown
archive: https://github.com/adrcunha/OctoPrint-AutomaticShutdown/archive/master.zip

follow_dependency_links: false

Expand Down
75 changes: 38 additions & 37 deletions octoprint_automaticshutdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import time

class AutomaticshutdownPlugin(octoprint.plugin.TemplatePlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SettingsPlugin,
octoprint.plugin.StartupPlugin):
octoprint.plugin.AssetPlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SettingsPlugin,
octoprint.plugin.StartupPlugin):

def __init__(self):
def __init__(self):
self.abortTimeout = 0
self.rememberCheckBox = False
self.lastCheckBoxValue = False
self._automatic_shutdown_enabled = False
self._timeout_value = None
self._abort_timer = None
self._wait_for_timelapse_timer = None
self._abort_timer = None
self._wait_for_timelapse_timer = None

def initialize(self):
self.abortTimeout = self._settings.get_int(["abortTimeout"])
Expand All @@ -37,23 +37,23 @@ def initialize(self):
if self.rememberCheckBox:
self._automatic_shutdown_enabled = self.lastCheckBoxValue

def get_assets(self):
return dict(js=["js/automaticshutdown.js"])

def get_template_configs(self):
return [dict(type="sidebar",
name="Automatic Shutdown",
custom_bindings=False,
icon="power-off"),
def get_assets(self):
return dict(js=["js/automaticshutdown.js"])

def get_template_configs(self):
return [dict(type="sidebar",
name="Automatic Shutdown",
custom_bindings=False,
icon="power-off"),
dict(type="settings", custom_bindings=False)]


def get_api_commands(self):
return dict(enable=[],
disable=[],
abort=[])
def get_api_commands(self):
return dict(enable=[],
disable=[],
abort=[])

def on_api_command(self, command, data):
def on_api_command(self, command, data):
if not user_permission.can():
return make_response("Insufficient rights", 403)

Expand Down Expand Up @@ -152,15 +152,15 @@ def _timer_task(self):
self._abort_timer = None
self._shutdown_system()

def _shutdown_system(self):
shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
try:
import sarge
p = sarge.run(shutdown_command, async=True)
except Exception as e:
self._logger.exception("Error when shutting down: {error}".format(error=e))
return
def _shutdown_system(self):
shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
try:
import sarge
p = sarge.run(shutdown_command, async_=True)
except Exception as e:
self._logger.exception("Error when shutting down: {error}".format(error=e))
return

def get_settings_defaults(self):
return dict(
Expand Down Expand Up @@ -189,17 +189,18 @@ def get_update_information(self):
current=self._plugin_version,

# update method: pip w/ dependency links
pip="https://github.com/OctoPrint/OctoPrint-AutomaticShutdown/archive/{target_version}.zip"
pip="https://github.com/adrcunha/OctoPrint-AutomaticShutdown/archive/{target_version}.zip"
)
)

__plugin_name__ = "Automatic Shutdown"
__plugin_pythoncompat__ = ">=2.7,<4"

def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = AutomaticshutdownPlugin()
global __plugin_implementation__
__plugin_implementation__ = AutomaticshutdownPlugin()

global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-AutomaticShutdown"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.4"
plugin_version = "0.1.5"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand All @@ -27,7 +27,7 @@
plugin_author_email = "[email protected]"

# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
plugin_url = "https://github.com/OctoPrint/OctoPrint-AutomaticShutdown"
plugin_url = "https://github.com/adrcunha/OctoPrint-AutomaticShutdown"

# The plugin's license. Can be overwritten within OctoPrint's internal data via __plugin_license__ in the plugin module
plugin_license = "AGPLv3"
Expand Down

0 comments on commit 072c64d

Please sign in to comment.