|
|
|
@ -42,6 +42,8 @@ def cli(ctx, default_config_path, local_operation, only_default_layer):
|
|
|
|
in the current working directory beginning with "shepherd" and
|
|
|
|
in the current working directory beginning with "shepherd" and
|
|
|
|
ending with ".toml" will be used.
|
|
|
|
ending with ".toml" will be used.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
ctx.ensure_object(SimpleNamespace)
|
|
|
|
|
|
|
|
|
|
|
|
version_text = pkg_resources.get_distribution("shepherd")
|
|
|
|
version_text = pkg_resources.get_distribution("shepherd")
|
|
|
|
log.info(F"Shepherd Agent [{version_text}]")
|
|
|
|
log.info(F"Shepherd Agent [{version_text}]")
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,8 +58,9 @@ def cli(ctx, default_config_path, local_operation, only_default_layer):
|
|
|
|
with open(default_config_path, 'r+') as f:
|
|
|
|
with open(default_config_path, 'r+') as f:
|
|
|
|
content = f.read()
|
|
|
|
content = f.read()
|
|
|
|
if "Compiled Shepherd config" in content:
|
|
|
|
if "Compiled Shepherd config" in content:
|
|
|
|
log.warn("Default config file looks like it is full compiled config file"
|
|
|
|
log.warning("Default config file looks like it is full compiled config"
|
|
|
|
" generated by Shepherd and picked up due to accidental name match")
|
|
|
|
" file generated by Shepherd and picked up due to accidental"
|
|
|
|
|
|
|
|
" name match")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
log.error("No default config file provided, and no 'shepherd*.toml' could be"
|
|
|
|
log.error("No default config file provided, and no 'shepherd*.toml' could be"
|
|
|
|
" found in the current directory")
|
|
|
|
" found in the current directory")
|
|
|
|
@ -79,6 +82,11 @@ def cli(ctx, default_config_path, local_operation, only_default_layer):
|
|
|
|
del plugin_configs["shepherd"]
|
|
|
|
del plugin_configs["shepherd"]
|
|
|
|
core_config = confman.get_config_bundle("shepherd")
|
|
|
|
core_config = confman.get_config_bundle("shepherd")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.invoked_subcommand == "test":
|
|
|
|
|
|
|
|
ctx.obj.plugin_configs = plugin_configs
|
|
|
|
|
|
|
|
ctx.obj.core_config = core_config
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# control.init_control(core_config, plugin_configs)
|
|
|
|
# control.init_control(core_config, plugin_configs)
|
|
|
|
|
|
|
|
|
|
|
|
scheduler.init_scheduler(core_config)
|
|
|
|
scheduler.init_scheduler(core_config)
|
|
|
|
@ -98,12 +106,37 @@ def cli(ctx, default_config_path, local_operation, only_default_layer):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@cli.command()
|
|
|
|
@click.option('-d', '--plugin-dir', type=click.Path(),
|
|
|
|
@click.argument('plugin_name', required=False)
|
|
|
|
help="Override the configured directory to search for plugin modules, in addition to"
|
|
|
|
@click.argument('interface_function', required=False)
|
|
|
|
" built in Shepherd plugins and the global import path."
|
|
|
|
@click.pass_context
|
|
|
|
" Supplying the option empty will use the current directory.")
|
|
|
|
def test(ctx, plugin_name, interface_function):
|
|
|
|
def test():
|
|
|
|
if not plugin_name:
|
|
|
|
print("test!")
|
|
|
|
click.echo("")
|
|
|
|
|
|
|
|
click.echo(click.style("===", fg='white', bold=True) +
|
|
|
|
|
|
|
|
click.style('Shepherd Test', fg='blue', bold=True) +
|
|
|
|
|
|
|
|
click.style("===", fg='white', bold=True))
|
|
|
|
|
|
|
|
click.secho(" Plugins loaded:", fg='green')
|
|
|
|
|
|
|
|
if len(ctx.obj.plugin_configs) == 0:
|
|
|
|
|
|
|
|
click.echo("---none---")
|
|
|
|
|
|
|
|
for plugin_name, config in ctx.obj.plugin_configs.items():
|
|
|
|
|
|
|
|
click.secho(plugin_name, bold=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
click.secho("\n Loaded core config:", fg='green')
|
|
|
|
|
|
|
|
pprint(ctx.obj.core_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
click.secho("\n Loaded plugin configs:", fg='green')
|
|
|
|
|
|
|
|
if len(ctx.obj.plugin_configs) == 0:
|
|
|
|
|
|
|
|
click.echo("---none---")
|
|
|
|
|
|
|
|
for plugin_name, config in ctx.obj.plugin_configs.items():
|
|
|
|
|
|
|
|
click.secho(plugin_name, bold=True)
|
|
|
|
|
|
|
|
pprint(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
click.echo("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("Initialising plugins...")
|
|
|
|
|
|
|
|
plugin.init_plugins(ctx.obj.plugin_configs, ctx.obj.core_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@cli.command()
|
|
|
|
@ -197,8 +230,8 @@ def compile_config(confman, default_config_path, layers_disabled):
|
|
|
|
log.info(F"Loaded default config layer from {default_config_path}")
|
|
|
|
log.info(F"Loaded default config layer from {default_config_path}")
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
if isinstance(e, InvalidConfigError):
|
|
|
|
if isinstance(e, InvalidConfigError):
|
|
|
|
log.error(
|
|
|
|
log.error(F"Failed to load default config from {default_config_path}."
|
|
|
|
F"Failed to load default config from {default_config_path}. {chr(10).join(e.args)}")
|
|
|
|
F" {chr(10).join(e.args)}")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
log.error(F"Failed to load default config from {default_config_path}", exc_info=True)
|
|
|
|
log.error(F"Failed to load default config from {default_config_path}", exc_info=True)
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
@ -216,7 +249,7 @@ def compile_config(confman, default_config_path, layers_disabled):
|
|
|
|
confman.save_fallback()
|
|
|
|
confman.save_fallback()
|
|
|
|
|
|
|
|
|
|
|
|
if not core_conf["plugin_dir"]:
|
|
|
|
if not core_conf["plugin_dir"]:
|
|
|
|
log.warn("Custom plugin path is empty, won't load custom plugins")
|
|
|
|
log.warning("Custom plugin path is empty, won't load custom plugins")
|
|
|
|
|
|
|
|
|
|
|
|
# ====Custom Local Config Layer====
|
|
|
|
# ====Custom Local Config Layer====
|
|
|
|
# If this fails, maintain default config but continue on to Control layer
|
|
|
|
# If this fails, maintain default config but continue on to Control layer
|
|
|
|
|