Moonraker now checks the modified time of both the install script and requirements file for git repos. If either is out of date their associated dependencies will be installed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This ensures that jobs in the database will be stored in the order they were started. Doing so also eliminates the need for the `history_auto_inc_id", as we can initialize the next id from the database keys.
This also caches history keys in memory so we do not need to read them from the database on each access.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add an additional checks to determine if a job needs to be cancelled when we receive a new "printing" state. A file name mismatch or a decrease in total_duration indicates a virtual sdcard reset.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add GET and DELETE `/server/history/job` APIs and remvoe the `DELETE /server/history/delete` API. When returning a list of jobs, return it as an array rather than as a object. The `/server/history/list` API no longer accepts a job id.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows the repo init sequence to distinguish between a broken git repo and an invalid git repo.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If a trusted IP address is passed as the origin then it is safe to assume that CORS access to this origin should be granted, but only if CORS is enabled by specifying at least one cors domain.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
A user may unintentionally allow access to dangerous domains if they place a wildcard in the top level domain portion of an entry. Raise a config error when this condition is detected.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move git command functionality to its own class outside of the Updater class. This class is responsible for tracking repo state and executing commands on the repo. Fetch and Pull no longer use built in command timeouts, instead a callback is scheduled to see if the command returned progress. Only when no progress is returned will a fetch or pull be terminated after a timeout.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This class handles running shell commands and sending http API requests. Each updater class shares an instance of the command helper rather than the UpdateManager instance.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
In the "run()" method verbosity should still be allowed if log_stderr is True, even
if both callbacks are not set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows plugins to interact with other plugins before they are closed. For example, a plugin may wish to save persistent state to the database before it is closed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This handler provides consistent error reporting in the event that the client attempts to access an unknown endpoint. If the request is unauthorized, an 401 will be returned. Otherwise a 404 will be returned, however if CORS is available the CORS headers will be set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Pass GIT_HTTP_LOW_SPEED_LIMIT and GIT_HTTP_LOW_SPEED_TIME environment variables to the "git fetch" and "git pull" commands. If the remote is unreachable this should force the command to timeout before Moonraker forcefully terminates it.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This brings consistency to the "run" methods. It also removes potential confusion between the previous "quiet" argument and the "verbose" argument in "run()".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
A consumer of shell command can achieve "fire and forget" by scheduling the future returned by "run()" to execute on the event loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is now possible to redirect stderr to a callback for asynchronous message transfer. Also added is the env option, allowing custom environment variables to be passed to the subprocess.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than use terminate to pre-emptively exit a shell command, attempt to exit with SIGINT, SIGTERM, and finally SIGKILL.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Moving log level init to the app module and have it explicitly set the level. This allows the logging level to be toggled with a server restart. Default debug logging to False.
When debug logging is disabled do not log HTTP requests.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Only report extruder and bed temperatures. Use dict "get()" methods to make sure that the fields are available.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This error is an indication that a JSON body was sent without the content type set to "application/json".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The prior implementations assumed that uploaded files would be buffered in memory.
This is no longer the case, so UFP extraction is more efficient when done straight to disk.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This PR is a minimal implementation of the Octoprint REST API that is required
for Cura to be able to establish a connection and send gcode/UFP files to
moonraker without errors.
Currently it only supports the "global apikey authentication" method.
Signed-off-by: Nickolas Grigoriadis <nagrigoriadis@gmail.com>
When a websocket is closed, set "is_closed" to True in the on_closed handler. When closing all websockets, iterate through a list of values.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows gcode file metadata to persist through restarts, reducing the time spent parsing. The gcode file path also persists, so it is available even when Klippy is not.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
At times a subprocess created by shell command fails. Attempt to mitigate this by using asyncio's version of subprocess, which should be more stable when running via the event loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Instead, look up klippy_apis after all plugins are loaded. This allows the "CORE_PLUGINS" list to determine the exact order in which core plugins are loaded.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This provides an lmdb database which can be used to keep persistent data. This can be used by internal plugins or by clients.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than require developers to add new notification handlers to websockets.py directly, implement a method that may be called to register websocket notifications during init.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When a closed websocket is detected set a flag to prevent further status updates until the websocket is removed.
Also make sure that the associated subscriptions are removed if a closed websocket is detected during a notification.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows clients to define files that will persist through an update, useful if the client has some sort of static configuration.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When this option is set Mooraker will restart Klipper after the device has been powered on. An additional "restart_delay" option has been added to customize the delay in which the restart is executed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the service restart functionality out of the "service restart" request into its own method. This allows the "service restart" to be called internally by other modules.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Fix issue where apt-get update is called on startup. This should only be done by the "auto updater" or by a specific request to refresh.
Always set an Updater's init event to true when refresh() is called, regardless of the result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Decrease the frequency of auto updates roughly every 24 hours. The manager will attempt to update once between 12am and 4am.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This is a workaround for an issue where the http client fails to propogate an exception back to the caller, hanging the update process.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Attach "is_complete" to the response so clients know that the transaction is done, even though it resulted in an error.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The entire configuration should be validated prior to device initialization. In the event of an error, the GPIO Chip factory must be closed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
We need to be sure that the entire update_manager is correctly configured prior to queueing the callbacks for the initial refresh. Rather than have each updater spawn a "refesh" callback, move them all into a single init method spawned after the module has been fully configured.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The server can still operate and be used to fetch the logs if a plugin fails to load. Add a 'failed_plugins' field to the /server/info response so clients can notify users that this plugin failed to load.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>