Skip to content

Commit

Permalink
Merge pull request #153 from smartin015/rc
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
smartin015 committed Dec 31, 2022
2 parents 36d9a80 + 1e6e83b commit 2cb0dae
Show file tree
Hide file tree
Showing 49 changed files with 3,186 additions and 522 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/coverage.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ jobs:
install:
- pip install setuptools==60.9.0 # https://github.com/pypa/setuptools/issues/3293
- pip install OctoPrint # Need OctoPrint to satisfy req's of `__init__.py`
- pip install coverage coveralls
- pip install -r requirements.txt
script:
- python3 -m unittest discover -p "*_test.py"
- coverage run -m unittest discover -p "*_test.py"
after_success:
- coveralls
notifications:
email:
- smartin015@gmail.com
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Continuous Print Queue for Octoprint

![build status](https://img.shields.io/travis/smartin015/continuousprint/master?style=plastic)
![code coverage](https://img.shields.io/codecov/c/github/smartin015/continuousprint/master)
[![Coverage Status](https://coveralls.io/repos/github/smartin015/continuousprint/badge.svg?branch=master)](https://coveralls.io/github/smartin015/continuousprint?branch=master)

This plugin automates your 3D printing!

Expand Down
12 changes: 10 additions & 2 deletions continuousprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def on_startup(self, host=None, port=None):
self._logger,
self._identifier,
self._basefolder,
self._event_bus.fire,
# Events are of type CustomEvents and need to be unpacked:w
lambda e: self._event_bus.fire(e.event),
)

def on_after_startup(self):
Expand Down Expand Up @@ -96,10 +97,17 @@ def get_settings_defaults(self):

# ---------------------- Begin TemplatePlugin -------------------
def get_template_vars(self):
try:
local_ip = self._plugin.get_local_addr().split(":")[0]
except Exception:
# Local IP details are used for display only
local_ip = "<ip_address>"
return dict(
exceptions=self._plugin.get_exceptions(),
printer_profiles=list(PRINTER_PROFILES.values()),
gcode_scripts=list(GCODE_SCRIPTS.values()),
local_ip=self._plugin.get_local_ip(),
custom_events=[e.as_dict() for e in CustomEvents],
local_ip=local_ip,
)

def get_template_configs(self):
Expand Down
68 changes: 58 additions & 10 deletions continuousprint/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@


class Permission(Enum):
GETSTATE = (
"Get state",
"Allows for fetching queue and management state of Continuous Print",
False,
)
STARTSTOP = (
"Start and Stop Queue",
"Allows for starting and stopping the queue",
Expand All @@ -31,17 +36,31 @@ class Permission(Enum):
"Allows for fetching history of print runs by Continuous Print",
False,
)
CLEARHISTORY = (
"Clear history",
RESETHISTORY = (
"Reset history",
"Allows for deleting all continuous print history data",
True,
)
GETQUEUES = ("Get queue", "Allows for fetching metadata on all print queues", False)
GETQUEUES = (
"Get queues",
"Allows for fetching metadata on all print queues",
False,
)
EDITQUEUES = (
"Edit queues",
"Allows for adding/removing queues and rearranging them",
True,
)
GETAUTOMATION = (
"Get automation scripts and events",
"Allows for fetching metadata on all scripts and the events they're configured for",
False,
)
EDITAUTOMATION = (
"Edit automation scripts and events",
"Allows for adding/removing gcode scripts and registering them to execute when events happen",
True,
)

def __init__(self, longname, desc, dangerous):
self.longname = longname
Expand Down Expand Up @@ -112,6 +131,10 @@ def _msg(self, data):
def _preprocess_set(self, data):
pass # Used to auto-fill underspecified sets, e.g. add profile based on gcode analysis

@abstractmethod
def _set_external_symbols(self, data):
pass

def popup(self, msg, type="popup"):
return self._msg(dict(type=type, msg=msg))

Expand All @@ -133,6 +156,7 @@ def _sync_history(self):
# (e.g. 1.4.1 -> 2.0.0)
@octoprint.plugin.BlueprintPlugin.route("/state/get", methods=["GET"])
@restricted_access
@cpq_permission(Permission.GETSTATE)
def get_state(self):
return self._state_json()

Expand All @@ -143,9 +167,11 @@ def get_state(self):
@restricted_access
@cpq_permission(Permission.STARTSTOP)
def set_active(self):
self._update(
DA.ACTIVATE if flask.request.form["active"] == "true" else DA.DEACTIVATE
)
active = flask.request.form["active"]
if type(active) == str:
active = active.lower().strip() == "true"

self._update(DA.ACTIVATE if active else DA.DEACTIVATE)
return self._state_json()

# Public method - adds a new set to an existing job, or creates a new job and adds the set there.
Expand Down Expand Up @@ -193,8 +219,6 @@ def mv_job(self):
new_id = dq.import_job_from_view(sq.get_job_view(src_id))
except ValidationError as e:
return json.dumps(dict(error=str(e)))

print("Imported job from view")
sq.remove_jobs([src_id])
src_id = new_id

Expand Down Expand Up @@ -246,7 +270,7 @@ def export_job(self):
# PRIVATE API METHOD - may change without warning.
@octoprint.plugin.BlueprintPlugin.route("/job/rm", methods=["POST"])
@restricted_access
@cpq_permission(Permission.EDITJOB)
@cpq_permission(Permission.RMJOB)
def rm_job(self):
return json.dumps(
self._get_queue(flask.request.form["queue"]).remove_jobs(
Expand Down Expand Up @@ -275,7 +299,7 @@ def get_history(self):
# PRIVATE API METHOD - may change without warning.
@octoprint.plugin.BlueprintPlugin.route("/history/reset", methods=["POST"])
@restricted_access
@cpq_permission(Permission.CLEARHISTORY)
@cpq_permission(Permission.RESETHISTORY)
def reset_history(self):
queries.resetHistory()
return json.dumps("OK")
Expand All @@ -296,3 +320,27 @@ def edit_queues(self):
(absent_names, added) = queries.assignQueues(queues)
self._commit_queues(added, absent_names)
return json.dumps("OK")

# PRIVATE API METHOD - may change without warning.
@octoprint.plugin.BlueprintPlugin.route("/automation/edit", methods=["POST"])
@restricted_access
@cpq_permission(Permission.EDITAUTOMATION)
def edit_automation(self):
data = json.loads(flask.request.form.get("json"))
queries.assignAutomation(data["scripts"], data["preprocessors"], data["events"])
return json.dumps("OK")

# PRIVATE API METHOD - may change without warning.
@octoprint.plugin.BlueprintPlugin.route("/automation/get", methods=["GET"])
@restricted_access
@cpq_permission(Permission.GETAUTOMATION)
def get_automation(self):
return json.dumps(queries.getAutomation())

# PRIVATE API METHOD - may change without warning.
@octoprint.plugin.BlueprintPlugin.route("/automation/external", methods=["POST"])
@restricted_access
@cpq_permission(Permission.EDITAUTOMATION)
def set_automation_external_symbols(self):
self._set_external_symbols(flask.request.get_json())
return json.dumps("OK")
Loading

0 comments on commit 2cb0dae

Please sign in to comment.