While use of "unofficial" klippy extras an moonraker components
is not officially supported, there is no harm in facilitating
updates for these extensions in the update manager. This adds
configuration which will restart either moonraker or klipper
after an extension is updated.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
If "None" is specified as a separator for getdict and the getlist
variants then strings will split along any whitespace character.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't require a config object to instantiate and don't attempt
to wrap database namespace. These changes allow instantation
after the server has started.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
While the curl based client is better in most respects, it requires
that libcurl be against with an asynchronous DNS resolver, such
as c-ares, in order to prevent blocking. As of now it Debian does
not ship with a version of curl with ares enabled. Fall back to the
simple client until this can be resolved.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Its possible for users to have an unstable internet connection. Log
connection errors rather than warn.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
The parsed feeds are stored in the DB, so there is no
need to cache the result when 304 is returned.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This adds support for announcements retreived via RSS feed from
the "moonlight" GitHub repo. Announcements may also be procedurally
generated internally.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
When using tempfile.TemporaryDirectory it is possible that
exiting the context will block when attempting to delete
the temporary directory. Don't use the context manager,
instead create and cleanup the temp dir using the default
threadpoolexecutor.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This abstracts the tornado http client from the rest of Moonraker,
allowing all components to access the client's most used functionality
without importing tornado modules.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Provide a remote method by which clients may identify their
name, version, and type.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
fix
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
By retreiving and storing the hostname in the websocket
header, it is possible to determine a fully qualified domain
used to reach the instance.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Refactor the PowerDevice initialize() method so that it acquires the
request lock. Always register the "klippy_started" event if the
"restart_klipper" option is set, and always check if Klipper is is
the ready state before performing the restart. Remove stale
PowerDevice methods no longer used.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This method can be used by other components to check if Moonraker has
access to a particular file or folder.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Don't raise an exeption if the config or log paths are invalid,
add warnings instead. This allows the user to see what is wrong
and resolve this issue.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
Make sure that paths registered with full access do not overlap one
another, nor that they overlap sensitive folders such as the database,
Moonraker's source, or Klipper's source.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This option was intended for Moonraker developers to live test
changes to write protected namespaces. This can be accomplished
locally with other methods, thus this option has been removed to
prevent users from compromising sections of the database.
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This component will be a bridge between moonraker and https://github.com/caronc/apprise. This way users can easily add all kind of notification services to their printer.
Signed-off-by: Pieter Willekens <me@pataar.nl>
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>