Moonraker depends on "future" annotations and uses fstrings, so
versions of Python older than 3.7 will fail to load and never make
it to the version check.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Start tracking the Remote API version separately from the application
version. This allows the API to stick to semantic versioning while
and track the application version separately. This is necessary as
we prepare to release a beta.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rename the "on_when_upload_queued" option to "on_when_job_queued",
deprecate the former. This option now applies to any queued job while
the device is off.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The "wait_connected" method would block indefinitely until a klippy
connection is established. This isn't the behavior we want, we only
want to wait "if" a connection has been established until Klippy
reports that its startup sequence is complete.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This makes the order in which they are reported consistent,
as the namespaces are stored in a set.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible to reduce to a value that is not a dict in "insert_item()"
and "update_item()". Raise a ServerError with a clear description of
what went wrong in these situations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It is possible that Moonraker can be instantiated while the eventloop
is running during tests. To avoid errors allow synchronous calls until
the server starts.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since the User DB is not going to be large cache the users
in local memory and sync with the DB when changes are
made to the local user store.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Now that all transactions run in a thread it is possible for them to
interleave. The record based operations allow for batch operations
within a single transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Wrap command implementations in with a _run_command() method. All
database commands now return a Future object. If the command was
run before the eventloop starts its possible to immediately query
the Future's result.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Similar to the update method, however sync will remove any
keys in the database not in the new value.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than creating two wrappers, use a single wrapper whose methods
always return a future or awaitable. If the operation occurs during
the __init__() method of a component it will be syncrhonous, and the
result from the future can be immediately queried.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than reading out the entire database, attempt to pop off
empty keys in each database. This should should speed up
init on platforms with slow disk I/O and prevents reading
large namespaces in memory.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
It isn't necessary to read out the entire namespace, just attempt
to fetch the record and reduce the key list.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Since transactions are now threaded we need updating
and clearing a namespace needs to be performed within
one transaction.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Database transactions can perform disk I/O tasks, which at times will
block the eventloop. Run all transactions in threads to prevent this
from occuring.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The read() method will return an empty list if the file specified
does not exist or if the read failed in some fashion.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Moonraker requires that some Klipper objects be configured
and loaded. This check has always been performed and logged,
now track and report missing requirements.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the KlippyConnection class into its own module. Refactor
init to use loops rather than callbacks, this reduces complexity
of tracking and cancelling callback handles.
All Klippy state previously tracked by the Server is now in the
KlippyConnection. This improves testing and makes the code
less ambiguous, ie: the `server.make_request()` method is not
as clear as `klippy.request()`.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move the version check to the top of the module. An older version
of python is unlikely to make it beyond the initial import statements,
so print a message to stdout and stderr.
Move argument parsing out of the main method. This makes it possible
to invoke main without parsing command line arguments, which is useful
for tests.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than instantiate a new version of the event loop wrapper
we can simply reset the internal event loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't load components and start the server from within the
__init__() method. Break those out and call them in __main__().
This makes unit testing individual components possible.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Dont directly import components for instance checks. Instead
check to see if the type is serializable, if not store the string
representation.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The result should be a dictionary of dictionaries rather than a
dictionary of SectionProxy objects.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Attempt to take a backup of the configuration file if Moonraker
loads successfully and has not seen a config change.
If Moonraker fails to load due to a config error, attempt to fallback
to the backup configuration. If that fails, exit the server.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Its safer to let the attempt to read fail before additional error
checking. Also there is no need to remove DEFAULT from
config.sections(), as it can't be there per the Python docs.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't exit the server if the log path is invalid. Instead start
logging to stdout and add a warning for the user to
resolve.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Commit 7401192 introduced a regression where the saved klipper
paths were not loaded into the Update object.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Shallow clones don't report the tag in git describe, so use
git rev-list to extract the tag and prepend it to the version
string.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If Klipper or its python executable is located at a custom path
this allows moonraker to instantiate its update on startup
rather than wait for Klipper to connect. This also resolves an
issue where Klipper's update state is always refreshed on startup
when its located in a non-default path.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When the "none" provider is set service action APIs will be disabled
and return an error when called. Service state tracking is also
disabled.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
All requests to update, refresh, recover, or reinstall must acquire
the command lock. Given that the individual Deployment implementations
are not (and should not be) called from outside of a request the locks they
use to prevent unwanted re-entry are redundant, confusing, and could
potential result in a deadlock if used improperly.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows for the inclusion of 3rd party Python Source
within the Moonraker package. Initially this includes
a python source file containing PackageKit enumerations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The DBus manager is a core component that connects to the
system bus, providing resources used to communicate with other
processes on the the system through the DBus interface.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move all systemd cli calls to its own provider class, inherted from
a base provider class. This is in preparation for multiple provider
implementations.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows other components to be register callbacks that will
be executed in the stat update timer. This is useful for methods
that wish to poll subprocess commands, as its desireable to
prevent multiple subprocesses from running simultaneously.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This allows for users to execute a method directly rather than
create a command. This is useful for fire once commands that
do not need to inspect the return code unless there is an error.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Rather than override the Process class instead create a custom
protocol that forwards data over callbacks.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Support more synonym strings for colors
Case insensitive string type checks
Show errors in UI if e.g. wrong color was selected
Public color_config not color_order as it has confused users
Fix documentation for white stealthburner example
Signed-off-by: Richard Mitchell <richardjm+moonraker@gmail.com>
Log the User Agent when a websocket is opened.
When a websocket is closed log the close code, close Reason, and
time elapsed since the last pong was recieved from the client.
When Moonraker shuts down send a 1001 Code with Server Shutdown
as the reason.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Adds support for GPIO buttons. Each button is configured to render
a template when pressed and/or released. The button event
templates recieve a context with a "call_method" field, allowing
them to call nearly all Moonraker APIs.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Allow base modules to register themselves as components during
initialization. This makes them accessible via lookup_component()
across the entire application.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit will add parsing of optional filament name metadata for:
- PrusaSlicer and it's derivatives
- Simplify3D
- Cura
- IdeaMaker
For Cura and IdeaMaker it is necessary to add a custom start g-code comment.
Cura:
;Filament name = {material_name}
IdeaMaker:
;Filament name = {filament_name1}
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit will add parsing of optional filament type metadata for:
- PrusaSlicer and it's derivatives
- Cura
- IdeaMaker
For Cura and IdeaMaker it is necessary to add a custom start g-code comment.
Cura:
;Filament type = {material_type}
IdeaMaker:
;Filament type = {filament_name_abbreviation1}
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit will add parsing of optional nozzle diameter metadata for:
- PrusaSlicer and it's derivatives
- Simplify3D
- Cura
- IdeaMaker
For Cura and IdeaMaker it is necessary to add a custom start g-code comment.
Cura:
;Nozzle diameter = {machine_nozzle_size}
IdeaMaker:
;Nozzle diameter = {machine_nozzle_diameter1}
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
The "user", "password", and "token" options are templates
that can resolve items stored in the secrets file.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add the secrets module as a Jinja2 Environment global.
All templates will be able to access secrets as if it were
a dictionary.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add support for an external "secrets" file that may contain
usernames, passwords, and tokens. This file may be in
"ini" or "json" format.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Check for "Prusa" style embedded thumbnails by default for
all slicers. This is becoming a standard, as it is now available
in Cura, Ideamaker, and Simplify3D via plugins.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't require that gcode files embed two thumbnails. When
a single large thumbnail is parsed use pillow to create a
small one.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Cura's Octoprint plugin expects an "axes" field for each profile.
Report these values to match the default values used by the
plugin.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Cura's Octoprint plugin does not set the 'start' flag on uploads
when UFP is enabled. Instead it waits for the upload to
finish then issues Octoprint's "file command" request. Add
limited support for this API, mimicing how uploads are normally
handled.
Singed-off-by: Eric Callahan <arksine.code@gmail.com>
If a dynamic request handler returns None with "wrap_result"
disabled, set the return status to 204.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move upload handler registration out of the file manager.
Register the primary hander in the app module, and the
Octoprint Comptaiblity handler in octoprint_compat.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When creating a virtualenv, some operating systems provide
symbolic links back to /usr/bin/python3 rather than copy
the python exectuable over. Previously Moonraker resolved
this symbolic link, resulting in a failure to locate pip.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Handle connection errors in the read loop. Set a maximum number
of consecutive errors encountered during a read before aborting.
Resolves#309.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Move logging setup to the Server class and enable asyncio debugging.
Sanitize debug logging for all "/access" endpoints so tokens and
passwords are not logged.
SIgned-off-by: Eric Callahan <arksine.code@gmail.com>
Sort heater response so that the bed is displayed first, followed
by extruders in ascending order. Set inactive extruders to
"standby" if they are on rather than "active".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If the destination exits in the metadata database it is necessary
to either overwrite it with the source metadata or delete it
so that the new metadata can be rescanned.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Flush pending delete events when move and create events are detected. This resolves timing issues with rapidfire create/delete events.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Handle all potential exceptions. Run the connect/disconnect
in another thread, as its possible for some calls to block
the event loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't parse non "ether" types. Don't add interfaces that don't
have mac addresses and at least one IP address.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When a folder is copied processing can take several minutes, depending on the size and number of gcode files in the
path. Suppress all file events on a node until processing
is complete.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The the cancel object post processor results in an additional
"create_file" notification when the old file is replaced.
Track previous "create_file" notifications for valid gcode
files so the dups can be suppressed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When destructively iterating over pending metdata requests
don't pop the pending item until metadata processing is
complete. If a call to `parse_metadata()` has a request
pending, return the asyncio Event associated with that
request.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Now that the update manager doesn't rely on the rate
limit it should always initialize successfully. An individual
updater may still fail to initialize, however this does
not prevent the update manager from loading.
Singed-off-by: Eric Callahan <arksine.code@gmail.com>
The rate limit fields can be extracted from the response
to an API request, even if that request fails with 403. This speeds up update manager initialization and reduces
failures if github is unreachable.
SIgned-off-by: Eric Callahan <arksine.code@gmail.com>
This returns the checksum of a config section and can be used to check
if the section has changed.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Make sure that the queue is set to ready after resuming,
even if the next job is unable to be loaded.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When set to true, the queue will automatically transition
to the next job in the queue upon completion of the
current job. When false the queue will pause between
jobs, requiring that the user manually resume.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Resolve issues with ipv6 addresses. Only register the
net_state_changed event handler if Moonraker is bound
to all interfaces. Build a new instance of ServiceInfo
for each update rather than attempt to modify the
existing object.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add `--plain` and `--no-legend` to the command to list service units.
This fixes a bug where a service could be prefixed with a unique
character, resulting undetected services.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Some devices on the Home Assistant server do not update their internal state immediately after a request returns. Introduce a configurable delay to work around this issue.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This provides corrective action in the event that an
invalid user entry makes its way into the database.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
For gpiod versions 1.3 or greater use the "default_val" keyword argument to set the default, otherwise use
"default_vals".
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Determine if a firmware restart should be postponed by checking Klippy's state. This should correctly schedule the restart regardless of whether or not the device is bound to Klipper.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This handles a specific scenario where a power device is bound to the Klipper service and is configured to perform a firmware restart after power on. In this case, we can detect if the firmware restart is required and abort it if necessary.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When this option is set to "True", the device will power on after the file manager queues an upload for printing.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Now that init occurs before the server starts there is no need to block requests until post initialization.
Signed-off-buy: Eric Callahan <arksine.code@gmail.com>
Occasionally a server restart will fail as the new loop instantiates as closed. This seems to be an issue with asyncio, attempt to work around by retyring to create a new loop.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Previously a set was used to remove duplicate components, however this is unnecessary as the `load_component` method immediately returns dups. Using a list should preserve the load order based on the configuration, making it more predictable.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The `send_event()` method now returns a future that can be awaited until all callbacks are complete. All events emitted during Klipper init are now awaited, and a Lock is used to prevent re-entry. This resolves potential timing issues with commands sent during the init sequence.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Components may call a "component_init" method for initialization that requires async calls. This allows moonraker to track init progress and guarantee init order.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Remove the "load_component_multi" method as it is not
necessary. Components are responsible for loading
"child" sections as required. Core components can
now have their own config section.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Add support for holding multiple printer jobs in a queue.
When a job successfully completes Moonraker will load
the next job in the queue.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This module adds a helper to track Klippy's "print_stats" module. It
stores the current stats and emits events for changes in job state.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The `update_service_status()` method could result in the creation of multiple subprocesses for each update, resulting in a performance hit as subprocesses are inherently expensive.
Fetch the state for all detected services in a single subprocess.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Log all import errors other than ModuleNotFound errors. Add a server warning if a gpio type is configured and the gpiod module is not loaded.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>