-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Suppress core OctoPrint GCODE scripts when running CPQ scripts of our own * Also protect the patchComms() function from exceptions e.g. due to OctoPrint refactors * Also return original script values in passthru * Configurable GCODE override in print files * Properly order sets by rank * Preprocessor simulator and preview (#194) * Partial commit - extended CustomEvents to include sim stuff, added sim api endpoint, split out settings JS into a separate _event.js file * Fixed simulation execution events, added styling, plus modifiable symtable and display of mutations * Pluralize simulation summary, separate asteval code into automation.py from storage/queries.py, set up tests * Fix tests * Add tests for CPSettingsEvent * Make simulator UI more friendly/helpful and well formatted * Remove todo lines * Tighten spoolmanager integration (#195) * Tighten spoolmanager integration, including validation checks and print-start adjustments * Add tests, improve set_status behavior, add spoolmanager.py files * Fix tests, eliminate stack overflow * Increase idle timeout seconds * Add preprocessor basics to docs (#196) * Add S3D processor (#197) * Compute stats for whole queues (#198) * Extract stats calculations from continuousprint_jobs.js, make also usable on whole queues * Add HTML for viewing queue rollups, make selectively visible * Fix tests, fix batch selection, auto-hide mass estimates when zero * Auto-slice STLs in queue (#166) * First attempt at integrating OctoPrint configured slicers into queue automation; also anticipate FILE_ADDED changes upstream * Added auto-slicing docs and fixed small bug in octoprint version detection * Add working auto-slicer implementation; unit tests TBD * Fix tests * Add driver test * Add tests for slicer profiles in JS, remove extra debug logging * Remove unused driver state, improve verbosity of slicing errors, and fixed slicer output path in tmp folder * Get working enough to verify STL and gcode handled correctly, plus update docs * Fix tests, remove octoprint version req thing and reduce DB noise in testing * Cleanup * 2.4.0rc1 * Creality Ender 3 S1 Pro added (#207) * Ender 3 S1 Pro bed cleaning (#208) * Update gcode_scripts.yaml * Update gcode_scripts.yaml * Add safety temp directory creation, fixed YAML data files * Appease linter * Fix tests and broken links --------- Co-authored-by: UdDReX <44963788+UdDReX@users.noreply.github.com>
- Loading branch information
1 parent
a767ed5
commit 1a685a7
Showing
52 changed files
with
2,166 additions
and
473 deletions.
There are no files selected for viewing
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
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
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
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
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,45 @@ | ||
from io import StringIO | ||
import re | ||
from asteval import Interpreter | ||
|
||
|
||
def getInterpreter(symbols): | ||
out = StringIO() | ||
err = StringIO() | ||
interp = Interpreter(writer=out, err_writer=err) | ||
# Merge in so default symbols (e.g. exceptions) are retained | ||
for k, v in symbols.items(): | ||
interp.symtable[k] = v | ||
return interp, out, err | ||
|
||
|
||
def genEventScript(automation: list, interp=None, logger=None) -> str: | ||
result = [] | ||
for script, preprocessor in automation: | ||
procval = True | ||
if preprocessor is not None and preprocessor.strip() != "": | ||
procval = interp(preprocessor) | ||
if logger: | ||
logger.info( | ||
f"EventHook preprocessor: {preprocessor}\nResult: {procval}" | ||
) | ||
|
||
if procval is None or procval is False: | ||
continue | ||
elif procval is True: | ||
formatted = script | ||
elif type(procval) is dict: | ||
if logger: | ||
logger.info(f"Appending script using formatting data {procval}") | ||
formatted = script.format(**procval) | ||
else: | ||
raise Exception( | ||
f"Invalid return type {type(procval)} for peprocessor {preprocessor}" | ||
) | ||
|
||
leftovers = re.findall(r"\{.*?\}", formatted) | ||
if len(leftovers) > 0: | ||
ppname = " (preprocessed)" if e.preprocessor is not None else "" | ||
raise Exception(f"Unformatted placeholders in script{ppname}: {leftovers}") | ||
result.append(formatted) | ||
return "\n".join(result) |
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,37 @@ | ||
import unittest | ||
from .automation import getInterpreter, genEventScript | ||
|
||
|
||
class TestInterpreter(unittest.TestCase): | ||
def testGetInterpreter(self): | ||
interp, _, _ = getInterpreter(dict(a=1)) | ||
self.assertEqual(interp.symtable["a"], 1) | ||
|
||
|
||
class TestGenEventScript(unittest.TestCase): | ||
def testEvalTrueFalseNone(self): | ||
a = [("gcode1", "p1")] | ||
self.assertEqual(genEventScript(a, lambda cond: True), "gcode1") | ||
self.assertEqual(genEventScript(a, lambda cond: False), "") | ||
self.assertEqual(genEventScript(a, lambda cond: None), "") | ||
|
||
def testPlaceholderNoPreprocessor(self): | ||
a = [("{foo} will never be formatted!", None)] | ||
with self.assertRaises(Exception): | ||
genEventScript(a, lambda cond: False) | ||
|
||
def testEvalMissedPlaceholder(self): | ||
a = [("{foo} will never be formatted!", "p1")] | ||
with self.assertRaises(Exception): | ||
genEventScript(a, lambda cond: dict(bar="baz")) | ||
|
||
def testEvalFormat(self): | ||
a = [("Hello {val}", "p1")] | ||
self.assertEqual( | ||
genEventScript(a, lambda cond: dict(val="World")), "Hello World" | ||
) | ||
|
||
def testEvalBadType(self): | ||
a = [("dontcare", "p1")] | ||
with self.assertRaises(Exception): | ||
genEventScript(a, lambda cond: 7) |
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
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
Oops, something went wrong.