🐛 Make systeminfo command also work w/ plugin env data
At least as long as the plugins that provide said env data only require a limited set of injected properties.
This commit is contained in:
1 parent
caa63017cf
commit
ee63eea02f
2 files changed
+76
-14
No files matched your search
@@ -30,6 +30,74 @@ class OctoPrintContext(object):
|
|||||||
pass_octoprint_ctx = click.make_pass_decorator(OctoPrintContext, ensure=True)
|
pass_octoprint_ctx = click.make_pass_decorator(OctoPrintContext, ensure=True)
|
||||||
"""Decorator to pass in the :class:`OctoPrintContext` instance."""
|
"""Decorator to pass in the :class:`OctoPrintContext` instance."""
|
||||||
|
|
||||||
|
# ~~ Basic CLI initialization for plugins
|
||||||
|
|
||||||
|
|
||||||
|
def init_platform_for_cli(ctx):
|
||||||
|
"""
|
||||||
|
Performs a basic platform initialization for the CLI.
|
||||||
|
|
||||||
|
Plugin implementations will be initialized, but only with a subset of the usual
|
||||||
|
property injections:
|
||||||
|
|
||||||
|
* _identifier and everything else parsed from metadata
|
||||||
|
* _logger
|
||||||
|
* _connectivity_checker
|
||||||
|
* _environment_detector
|
||||||
|
* _event_bus
|
||||||
|
* _plugin_manager
|
||||||
|
* _settings
|
||||||
|
|
||||||
|
Returns: the same list of components as returned by ``init_platform``
|
||||||
|
"""
|
||||||
|
|
||||||
|
from octoprint import (
|
||||||
|
init_custom_events,
|
||||||
|
init_platform,
|
||||||
|
init_settings_plugin_config_migration_and_cleanup,
|
||||||
|
)
|
||||||
|
from octoprint import octoprint_plugin_inject_factory as opif
|
||||||
|
from octoprint import settings_plugin_inject_factory as spif
|
||||||
|
|
||||||
|
components = init_platform(
|
||||||
|
get_ctx_obj_option(ctx, "basedir", None),
|
||||||
|
get_ctx_obj_option(ctx, "configfile", None),
|
||||||
|
safe_mode=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
settings,
|
||||||
|
logger,
|
||||||
|
safe_mode,
|
||||||
|
event_manager,
|
||||||
|
connectivity_checker,
|
||||||
|
plugin_manager,
|
||||||
|
environment_detector,
|
||||||
|
) = components
|
||||||
|
|
||||||
|
init_custom_events(plugin_manager)
|
||||||
|
octoprint_plugin_inject_factory = opif(
|
||||||
|
settings,
|
||||||
|
{
|
||||||
|
"plugin_manager": plugin_manager,
|
||||||
|
"event_bus": event_manager,
|
||||||
|
"connectivity_checker": connectivity_checker,
|
||||||
|
"environment_detector": environment_detector,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
settings_plugin_inject_factory = spif(settings)
|
||||||
|
|
||||||
|
plugin_manager.implementation_inject_factories = [
|
||||||
|
octoprint_plugin_inject_factory,
|
||||||
|
settings_plugin_inject_factory,
|
||||||
|
]
|
||||||
|
plugin_manager.initialize_implementations()
|
||||||
|
|
||||||
|
init_settings_plugin_config_migration_and_cleanup(plugin_manager)
|
||||||
|
|
||||||
|
return components
|
||||||
|
|
||||||
|
|
||||||
# ~~ Custom click option to hide from help
|
# ~~ Custom click option to hide from help
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import logging
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from octoprint.cli import get_ctx_obj_option, standard_options
|
from octoprint.cli import init_platform_for_cli, standard_options
|
||||||
|
|
||||||
click.disable_unicode_literals_warning = True
|
click.disable_unicode_literals_warning = True
|
||||||
|
|
||||||
@@ -43,20 +43,8 @@ def systeminfo_commands():
|
|||||||
@click.pass_context
|
@click.pass_context
|
||||||
def systeminfo_command(ctx, **kwargs):
|
def systeminfo_command(ctx, **kwargs):
|
||||||
"""Retrieves and prints the system info."""
|
"""Retrieves and prints the system info."""
|
||||||
from octoprint import FatalStartupError, init_platform
|
|
||||||
|
|
||||||
logging.disable(logging.ERROR)
|
logging.disable(logging.ERROR)
|
||||||
try:
|
try:
|
||||||
components = init_platform(
|
|
||||||
get_ctx_obj_option(ctx, "basedir", None),
|
|
||||||
get_ctx_obj_option(ctx, "configfile", None),
|
|
||||||
safe_mode=True,
|
|
||||||
)
|
|
||||||
except FatalStartupError as e:
|
|
||||||
click.echo(str(e), err=True)
|
|
||||||
click.echo("There was a fatal error initializing the settings manager.", err=True)
|
|
||||||
ctx.exit(-1)
|
|
||||||
else:
|
|
||||||
(
|
(
|
||||||
settings,
|
settings,
|
||||||
logger,
|
logger,
|
||||||
@@ -65,8 +53,14 @@ def systeminfo_command(ctx, **kwargs):
|
|||||||
connectivity_checker,
|
connectivity_checker,
|
||||||
plugin_manager,
|
plugin_manager,
|
||||||
environment_detector,
|
environment_detector,
|
||||||
) = components
|
) = init_platform_for_cli(ctx)
|
||||||
|
except Exception as e:
|
||||||
|
click.echo(str(e), err=True)
|
||||||
|
click.echo("There was a fatal error initializing the platform.", err=True)
|
||||||
|
ctx.exit(-1)
|
||||||
|
else:
|
||||||
systeminfo = get_systeminfo(environment_detector, connectivity_checker)
|
systeminfo = get_systeminfo(environment_detector, connectivity_checker)
|
||||||
|
|
||||||
for k in sorted(systeminfo.keys()):
|
for k in sorted(systeminfo.keys()):
|
||||||
click.echo("{}: {}".format(k, systeminfo[k]))
|
click.echo("{}: {}".format(k, systeminfo[k]))
|
||||||
|
ctx.exit(0)
|
||||||
Reference in new issue
Block a user