-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit de373a3
Showing
8 changed files
with
914 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# OctoPrint GCode System Commands | ||
This OctoPrint plugin adds the ability to define GCode commands that execute local system commands. | ||
|
||
![GCodeSystemCommands](gcodesystemcommands_settings.png?raw=true) | ||
|
||
|
||
## Setup | ||
|
||
Install the plugin using Plugin Manager from Settings |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# coding=utf-8 | ||
from __future__ import absolute_import | ||
|
||
__author__ = "Shawn Bruce <[email protected]>" | ||
__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" | ||
|
||
import octoprint.plugin | ||
import time | ||
import os | ||
import sys | ||
|
||
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() | ||
|
||
def reload_command_definitions(self): | ||
self.command_definitions = {} | ||
|
||
command_definitions_tmp = self._settings.get(["command_definitions"]) | ||
self._logger.debug("command_definitions: %s" % command_definitions_tmp) | ||
|
||
for definition in command_definitions_tmp: | ||
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_queuing(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): | ||
if not gcode and cmd[:4].upper() == 'OCTO': | ||
cmd_id = cmd[4:].split(' ')[0] | ||
|
||
try: | ||
cmd_line = self.command_definitions[cmd_id] | ||
except: | ||
self._logger.error("No definiton found for ID %s" % cmd_id) | ||
return (None,) | ||
|
||
self._logger.debug("Command ID=%s, Command Line=%s" % (cmd_id, cmd_line)) | ||
|
||
self._logger.info("Executing command ID: %s" % cmd_id) | ||
comm_instance._log("Exec(GCodeSystemCommands): OCTO%s" % cmd_id) | ||
|
||
try: | ||
r = os.system(cmd_line) | ||
except: | ||
e = sys.exc_info()[0] | ||
self._logger.exception("Error executing command ID %s: %s" % (cmd_id, e)) | ||
return (None,) | ||
|
||
self._logger.info("Command ID %s returned: %s" % (cmd_id, r)) | ||
|
||
if r == 0: | ||
status = 'ok' | ||
else: | ||
status = 'error' | ||
|
||
comm_instance._log("Return(GCodeSystemCommands): %s" % status) | ||
|
||
return (None,) | ||
|
||
def get_settings_defaults(self): | ||
return dict( | ||
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) | ||
] | ||
|
||
def get_assets(self): | ||
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" | ||
) | ||
) | ||
|
||
__plugin_name__ = "GCODE System Commands" | ||
|
||
def __plugin_load__(): | ||
global __plugin_implementation__ | ||
__plugin_implementation__ = GCodeSystemCommands() | ||
|
||
global __plugin_hooks__ | ||
__plugin_hooks__ = { | ||
"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.hook_gcode_queuing, | ||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information | ||
} |
33 changes: 33 additions & 0 deletions
33
octoprint_gcodesystemcommands/static/js/gcodesystemcommands.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
$(function() { | ||
function GCodeSystemCommandsViewModel(parameters) { | ||
var self = this; | ||
|
||
self.global_settings = parameters[0]; | ||
|
||
self.command_definitions = ko.observableArray(); | ||
|
||
self.addCommandDefinition = function() { | ||
self.command_definitions.push({id: 0, command:""}); | ||
}; | ||
|
||
self.removeCommandDefinition = function(definition) { | ||
self.command_definitions.remove(definition); | ||
}; | ||
|
||
self.onBeforeBinding = function () { | ||
self.settings = self.global_settings.settings.plugins.gcodesystemcommands; | ||
self.command_definitions(self.settings.command_definitions.slice(0)); | ||
}; | ||
|
||
self.onSettingsBeforeSave = function () { | ||
self.global_settings.settings.plugins.gcodesystemcommands.command_definitions(self.command_definitions.slice(0)); | ||
} | ||
|
||
} | ||
|
||
ADDITIONAL_VIEWMODELS.push([ | ||
GCodeSystemCommandsViewModel, | ||
["settingsViewModel"], | ||
["#settings_plugin_gcodesystemcommands"] | ||
]); | ||
}); |
26 changes: 26 additions & 0 deletions
26
octoprint_gcodesystemcommands/templates/gcodesystemcommands_settings.jinja2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<form class="form-horizontal"> | ||
<h3>Command Defninitions</h3> | ||
<div class="row-fluid"> | ||
<div class="span3"><h4>G-Code</h4></div> | ||
<div class="span3"><h4>System</h4></div> | ||
</div> | ||
<div data-bind="foreach: command_definitions"> | ||
<div class="row-fluid" style="margin-bottom: 5px"> | ||
<div class="span3 input-prepend"> | ||
<span class="add-on">OCTO</span> | ||
<input type="number" class="input-mini text-right" data-bind="value: id"> | ||
</div> | ||
<div class="span8"> | ||
<input type="text" class="input-block-level" data-bind="value: command"> | ||
</div> | ||
<div class="span1"> | ||
<a title="Remove Command Definition" class="btn btn-danger" data-bind="click: $parent.removeCommandDefinition"><i class="icon-trash"></i></a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row-fluid"> | ||
<div class="offset11 span1"> | ||
<a title="Add Command Definition" class="btn btn-primary" data-bind="click: addCommandDefinition"><i class="icon-plus"></i></a> | ||
</div> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OctoPrint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# coding=utf-8 | ||
import setuptools | ||
|
||
######################################################################################################################## | ||
|
||
plugin_identifier = "gcodesystemcommands" | ||
plugin_package = "octoprint_%s" % plugin_identifier | ||
plugin_name = "OctoPrint-GCodeSystemCommands" | ||
plugin_version = "0.1.1" | ||
plugin_description = "Define G-Code commands that execute local system commands." | ||
plugin_author = "Shawn Bruce" | ||
plugin_author_email = "[email protected]" | ||
plugin_url = "https://github.com/kantlivelong/OctoPrint-GCodeSystemCommands" | ||
plugin_license = "AGPLv3" | ||
plugin_additional_data = [] | ||
|
||
######################################################################################################################## | ||
|
||
def package_data_dirs(source, sub_folders): | ||
import os | ||
dirs = [] | ||
|
||
for d in sub_folders: | ||
folder = os.path.join(source, d) | ||
if not os.path.exists(folder): | ||
continue | ||
|
||
for dirname, _, files in os.walk(folder): | ||
dirname = os.path.relpath(dirname, source) | ||
for f in files: | ||
dirs.append(os.path.join(dirname, f)) | ||
|
||
return dirs | ||
|
||
def params(): | ||
# Our metadata, as defined above | ||
name = plugin_name | ||
version = plugin_version | ||
description = plugin_description | ||
author = plugin_author | ||
author_email = plugin_author_email | ||
url = plugin_url | ||
license = plugin_license | ||
|
||
# we only have our plugin package to install | ||
packages = [plugin_package] | ||
|
||
# we might have additional data files in sub folders that need to be installed too | ||
package_data = {plugin_package: package_data_dirs(plugin_package, ['static', 'templates', 'translations'] + plugin_additional_data)} | ||
include_package_data = True | ||
|
||
# If you have any package data that needs to be accessible on the file system, such as templates or static assets | ||
# this plugin is not zip_safe. | ||
zip_safe = False | ||
|
||
# Read the requirements from our requirements.txt file | ||
install_requires = open("requirements.txt").read().split("\n") | ||
|
||
# Hook the plugin into the "octoprint.plugin" entry point, mapping the plugin_identifier to the plugin_package. | ||
# That way OctoPrint will be able to find the plugin and load it. | ||
entry_points = { | ||
"octoprint.plugin": ["%s = %s" % (plugin_identifier, plugin_package)] | ||
} | ||
|
||
return locals() | ||
|
||
setuptools.setup(**params()) |