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>
Previously this check was only on done when a directory was requested by the API. Moving this check to _list_directory ()updates metadata for internal calls as well.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The slower system package update will now only executed by the auto-refresh routine. Moonraker will check for updates roughly every 2 hours, however system packages updates will only occur between 1am and 4am local time.
If a print is in progress any attempt to refresh or update will be aborted.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This should reduce the load on low perfomance devices. This also makes it possible to queue update requests.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Calls to "refresh" should not be allowed to occur while a client a current refresh is in progress. Updates will wait for a pending refresh to complete before beginning the update procedure.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible for the log files to be registered after a rollover, which can result in the file not existing. Force the log endpoints to register, bypassing the existance check.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Instead make sure that the supplied path is not the system root and check that moonraker has the appropriate privileges to access the directory.
Also track visited directories when retreiving a full file list to prevent infinite recursion.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This provides the update manager flexibility, such as the ability to define disto specific dependencies. This also fixes an issue where two updates are necessary to install additional dependencies.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows the config object to read additional config files as requred. Also implement a "get_options" method that can be used to retrive a dictionary of all options in the current section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
After a repo has been updated fetching the remote is not needed, as it was just done in the prior update step.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Track rate limit attributes and reject requests when the user IP has reached their limit. Use conditional API requests to reduce the number of requests that count against the limit.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It shouldn't be necessary to use gen.with_timeout during the fetch with tornado 6.1. Also fix some potential issues with unbound timeouts variables.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The remote version info can be retrieved by simply doing a git fetch, then running "git rev-parse" and "git describe" on the desired remote branch.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Allow developers to update a detached git repo. Note that this option should not be used on production machines.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Clear partial output and cancelled attributes prior to each call of run(). This allows a command to be cleanly run again after a failure.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows Moonraker to update its paths to Klippy immediately upon a successful response from the info endpoint.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This will make klippy.log available in the event that Klippy has not successfully connected, assuming the log is available at the default location.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows for the installation of python "dist-packages" without enabling "system-site-packages" in the virtualenv. As of the moment moonraker only requires the gpiod dist package.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This may be useful for system packaging options that do not wish to put configuration in the home directory.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Before the service is restarted, check the local version. This should make sure that the local repo state is reported correctly after an update, regardless of the timing of a status request.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible that a status request can occur while an updater is checking intial state. Use an event to wait on initializing before returning the status request.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This resolves an issue where an unhandled exception is rasied when a websocket attempts to write to a closed websocket.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This implements two queues, one for commands that execute locally and a second
for gcode commands that execute on the Klippy host. While it is valid for a local
command to execute concurrently with a remote command, commands of the same type
(local or remote) should execute sequentially.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Update paneldue.py
Report that the PanelDue is "idle" until it is first initialized. This allows for the Macros to be set upon first connection
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add a "get_return_code" method that allows users to fetch the return code after the shell command has executed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This implementation adds a delay that allows for pip to function correclty after the venv is built.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The current method for rebuilding the virtualenv fails. A potential workaround is to do the rebuild and subsequent update with a script. For now, disable the rebuild.
Signed-off-by: Eric Callahan <arskine.code@gmail.com>
This manager can perform updates on moonraker and klipper, assuming that the source is located in a valid git repo, the origin points to the official repo, and the currently selected branch is "master".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This makes it possible for clients to hard restart an service in the event it becomes unresponsive.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This method collects the entire response and returns it with the call. Suitable for commands that produce little output.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows moonraker plugins to look up the stored info without needing to make an addition "info" request to Klippy.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Do not allow on, off, or status requests without arguments. Pass device objects to "power_device()" rather than device names.
Signed-off-by: Eric Callahan <arkine.code@gmail.com>
Devices are now configured using "prefix" sections. The pin configuration now more closely mimics that of Klipper's configuration so as to reduce confusion.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Only load the plugin for each prefix section once. Plugins themselves will be responsible for parsing the configuration from each prefix section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Tornado clears the headers when an error is detected, "set_default_headers" must be overrridden so that errors are properly returned.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than allow all origins as was the default with "enable_cors", users may not specify the domains allowed. If "*" is specified, all domains are allowed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
GIven that subscriptions are reset, connected clients no longer maintained and they cannot check "webhooks.state" to see if Klippy is ready. This notifcation may be used to in its place.
SIgned-off-by: Eric Callahan <arksine.code@gmail.com>
Clients may provide arguments either in the query string or body. Reserved arguments "token" and "connection_id" are excluded from the result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Some requests, such "printer/objects/subscribe", require a websocket
for asynchronous updates. Clients may now specify a "connection_id"
in the form data that identifies an associated websocket.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
There is no need to pass the auth, server, or websocket manager objects to request handlers. They can be retreived directly from the application reference.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows clients to "unsubscribe"by sending an empty dict. Each client will receive updates only for subscribed objects.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>