crutch for plugins configuring

This commit is contained in:
Devaev Maxim 2019-09-14 06:07:36 +03:00
parent a2f91fb741
commit e8f0b361e3
5 changed files with 37 additions and 13 deletions

View File

@ -74,8 +74,9 @@ def init(
prog: Optional[str]=None, prog: Optional[str]=None,
description: Optional[str]=None, description: Optional[str]=None,
add_help: bool=True, add_help: bool=True,
sections: Optional[List[str]]=None,
argv: Optional[List[str]]=None, argv: Optional[List[str]]=None,
sections: Optional[List[str]]=None,
**plugins: bool,
) -> Tuple[argparse.ArgumentParser, List[str], Section]: ) -> Tuple[argparse.ArgumentParser, List[str], Section]:
argv = (argv or sys.argv) argv = (argv or sys.argv)
@ -90,7 +91,7 @@ def init(
help="View current configuration (include all overrides)") help="View current configuration (include all overrides)")
(options, remaining) = args_parser.parse_known_args(argv) (options, remaining) = args_parser.parse_known_args(argv)
config = _init_config(options.config_path, (sections or []), options.set_options) config = _init_config(options.config_path, options.set_options, (sections or []), **plugins)
if options.dump_config: if options.dump_config:
_dump_config(config) _dump_config(config)
raise SystemExit() raise SystemExit()
@ -101,7 +102,16 @@ def init(
# ===== # =====
def _init_config(config_path: str, sections: List[str], override_options: List[str]) -> Section: def _init_config(
config_path: str,
override_options: List[str],
sections: List[str],
with_auth: bool=False,
with_hid: bool=False,
with_atx: bool=False,
with_msd: bool=False,
) -> Section:
config_path = os.path.expanduser(config_path) config_path = os.path.expanduser(config_path)
raw_config: Dict = load_yaml_file(config_path) raw_config: Dict = load_yaml_file(config_path)
@ -112,12 +122,18 @@ def _init_config(config_path: str, sections: List[str], override_options: List[s
config = make_config(raw_config, scheme) config = make_config(raw_config, scheme)
if "kvmd" in sections: if "kvmd" in sections:
if with_auth:
scheme["kvmd"]["auth"]["internal"].update(get_auth_service_class(config.kvmd.auth.internal.type).get_plugin_options()) scheme["kvmd"]["auth"]["internal"].update(get_auth_service_class(config.kvmd.auth.internal.type).get_plugin_options())
if config.kvmd.auth.external.type: if config.kvmd.auth.external.type:
scheme["kvmd"]["auth"]["external"].update(get_auth_service_class(config.kvmd.auth.external.type).get_plugin_options()) scheme["kvmd"]["auth"]["external"].update(get_auth_service_class(config.kvmd.auth.external.type).get_plugin_options())
if with_hid:
scheme["kvmd"]["hid"].update(get_hid_class(config.kvmd.hid.type).get_plugin_options()) scheme["kvmd"]["hid"].update(get_hid_class(config.kvmd.hid.type).get_plugin_options())
if with_atx:
scheme["kvmd"]["atx"].update(get_atx_class(config.kvmd.atx.type).get_plugin_options()) scheme["kvmd"]["atx"].update(get_atx_class(config.kvmd.atx.type).get_plugin_options())
if with_msd:
scheme["kvmd"]["msd"].update(get_msd_class(config.kvmd.msd.type).get_plugin_options()) scheme["kvmd"]["msd"].update(get_msd_class(config.kvmd.msd.type).get_plugin_options())
config = make_config(raw_config, scheme) config = make_config(raw_config, scheme)

View File

@ -39,8 +39,11 @@ def main(argv: Optional[List[str]]=None) -> None:
config = init( config = init(
prog="kvmd-cleanup", prog="kvmd-cleanup",
description="Kill KVMD and clear resources", description="Kill KVMD and clear resources",
sections=["logging", "kvmd"],
argv=argv, argv=argv,
sections=["logging", "kvmd"],
with_hid=True,
with_atx=True,
with_msd=True,
)[2].kvmd )[2].kvmd
logger = get_logger(0) logger = get_logger(0)

View File

@ -101,8 +101,9 @@ def _cmd_delete(config: Section, options: argparse.Namespace) -> None:
def main(argv: Optional[List[str]]=None) -> None: def main(argv: Optional[List[str]]=None) -> None:
(parent_parser, argv, config) = init( (parent_parser, argv, config) = init(
add_help=False, add_help=False,
sections=["logging", "kvmd"],
argv=argv, argv=argv,
sections=["logging", "kvmd"],
with_auth=True,
) )
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog="kvmd-htpasswd", prog="kvmd-htpasswd",

View File

@ -34,8 +34,8 @@ def main(argv: Optional[List[str]]=None) -> None:
config = init( config = init(
prog="kvmd-ipmi", prog="kvmd-ipmi",
description="IPMI to KVMD proxy", description="IPMI to KVMD proxy",
sections=["logging", "ipmi"],
argv=argv, argv=argv,
sections=["logging", "ipmi"],
)[2].ipmi )[2].ipmi
# pylint: disable=protected-access # pylint: disable=protected-access

View File

@ -45,8 +45,12 @@ def main(argv: Optional[List[str]]=None) -> None:
config = init( config = init(
prog="kvmd", prog="kvmd",
description="The main Pi-KVM daemon", description="The main Pi-KVM daemon",
sections=["logging", "kvmd"],
argv=argv, argv=argv,
sections=["logging", "kvmd"],
with_auth=True,
with_hid=True,
with_atx=True,
with_msd=True,
)[2].kvmd )[2].kvmd
with gpio.bcm(): with gpio.bcm():