diff --git a/src/doblib/__main__.py b/src/doblib/__main__.py index 16c39e6..9e83784 100644 --- a/src/doblib/__main__.py +++ b/src/doblib/__main__.py @@ -104,16 +104,19 @@ def main(args=None): args, left = load_arguments(args) log_level = LOG_LEVELS.get(args.logging, logging.INFO) + if args.command in ("c", "config"): + # Show the configuration of the environment (skip all non-ERROR logging) + config_logger(logging.ERROR) + print(Environment(args.cfg).config(left)) + sys.exit() + if log_level: config_logger(log_level) if show_help: left.append("--help") - if args.command in ("c", "config"): - # Show the configuration of the environment - print(Environment(args.cfg).config(left)) - elif args.command in ("g", "generate"): + if args.command in ("g", "generate"): # Regenerate the configuration file sys.exit(Environment(args.cfg).generate_config()) elif args.command in ("f", "freeze"): diff --git a/src/doblib/env.py b/src/doblib/env.py index 8c32846..1fe9f48 100644 --- a/src/doblib/env.py +++ b/src/doblib/env.py @@ -18,6 +18,11 @@ def load_config_arguments(args): parser = utils.default_parser("config") parser.add_argument("option", nargs="?", help="Show only specific information") + parser.add_argument( + "--modules", + action="store_true", + help="Show the modules within the environment", + ) return parser.parse_known_args(args) @@ -146,6 +151,26 @@ def _load_config(self, cfg, raise_if_missing=True): # Merge the configurations self._config = utils.merge(self._config, options, replace=["merges"]) + def _get_modules(self): + """Return the list of modules""" + modes = self.get(base.SECTION, "mode", default=[]) + modes = set(modes.split(",") if isinstance(modes, str) else modes) + + modules = set() + for module in self.get("modules", default=[]): + if isinstance(module, str): + modules.add(module) + elif isinstance(module, dict) and len(module) == 1: + mod, mode = list(module.items())[0] + if isinstance(mode, str) and mode in modes: + modules.add(mod) + elif isinstance(mode, list) and modes.intersection(mode): + modules.add(mod) + else: + raise TypeError("modules: must be str or dict of length 1") + + return modules + def _link_modules(self): """Create symlinks to the modules to allow black-/whitelisting""" shutil.rmtree(base.ADDON_PATH, True) @@ -249,6 +274,9 @@ def config(self, args=None): """Simply output the rendered configuration file""" args, _ = load_config_arguments(args or []) + if args.modules: + return "\n".join(sorted(self._get_modules())) + if args.option: return yaml.dump(self.get(*args.option.split(":"))) diff --git a/src/doblib/module.py b/src/doblib/module.py index 1e1b2f6..b75afa5 100644 --- a/src/doblib/module.py +++ b/src/doblib/module.py @@ -81,26 +81,6 @@ def _run_migration_sql(self, db_name, script_name): with closing(db.cursor()) as cr, open(script_name, "r") as f: cr.execute(f.read()) - def _get_modules(self): - """Return the list of modules""" - modes = self.get(base.SECTION, "mode", default=[]) - modes = set(modes.split(",") if isinstance(modes, str) else modes) - - modules = set() - for module in self.get("modules", default=[]): - if isinstance(module, str): - modules.add(module) - elif isinstance(module, dict) and len(module) == 1: - mod, mode = list(module.items())[0] - if isinstance(mode, str) and mode in modes: - modules.add(mod) - elif isinstance(mode, list) and modes.intersection(mode): - modules.add(mod) - else: - raise TypeError("modules: must be str or dict of length 1") - - return modules - def _get_installed_modules(self, db_name): """Return the list of modules which are installed""" with self.env(db_name, False) as env: