async def reload(self): """Reload opsdroid.""" await self.unload() self.config = load_config_file( [ "configuration.yaml", DEFAULT_CONFIG_PATH, "/etc/opsdroid/configuration.yaml", ] ) await self.load()
def test_load_pre_0_17_config_file(self): config = load_config_file( [os.path.abspath("tests/configs/minimal_pre_0_17_layout.yaml")]) self.assertLogs("_LOGGER", "warning") self.assertEqual(config, { "connectors": { "shell": {} }, "skills": { "hello": {}, "seen": {} } })
def start(): """Start the opsdroid bot.""" check_dependencies() config = load_config_file([ "configuration.yaml", DEFAULT_CONFIG_PATH, "/etc/opsdroid/configuration.yaml" ]) configure_lang(config) configure_logging(config) welcome_message(config) with OpsDroid(config=config) as opsdroid: opsdroid.run()
def start(path): """Start the opsdroid bot. If the `-f` flag is used with this command, opsdroid will load the configuration specified on that path otherwise it will use the default configuration. """ check_dependencies() config = load_config_file([path] if path else DEFAULT_CONFIG_LOCATIONS) configure_lang(config) configure_logging(config) welcome_message(config) with OpsDroid(config=config) as opsdroid: opsdroid.run()
def list_all_modules(ctx, path): """List the active modules from config. This function will try to get information from the modules that are active in the configuration file and print them as a table or will just print a sentence saying that there are no active modules for that type. Args: ctx (:obj:`click.Context`): The current click cli context. path (str): a str that contains a path passed. Returns: int: the exit code. Always returns 0 in this case. """ config = load_config_file([path] if path else DEFAULT_CONFIG_LOCATIONS) click.echo( click.style( f"{'NAME':15} {'TYPE':15} {'MODE':15} {'CACHED':15} {'LOCATION':15}", fg="blue", bold=True, ) ) for module_type, module in config.items(): if module_type in ("connectors", "databases", "parsers", "skills"): for name, options in module.items(): mode = get_config_option( ["repo", "path", "gist"], options, True, "module" ) cache = get_config_option(["no-cache"], options, "no", "yes") location = get_config_option( ["repo", "path", "gist"], options, True, f"opsdroid.{module_type}.{name}", ) click.echo( f"{name:15} {module_type:15} {mode[1]:15} {cache[0]:15} {location[2]:15}" ) ctx.exit(0)
def build_config(ctx, params): """Load configuration, load modules and install dependencies. This function loads the configuration and install all necessary dependencies defined on a `requirements.txt` file inside the module. If the flag `--verbose` is passed the logging level will be set as debug and all logs will be shown to the user. Args: ctx (:obj:`click.Context`): The current click cli context. params (dict): a dictionary of all parameters pass to the click context when invoking this function as a callback. Returns: int: the exit code. Always returns 0 in this case. """ click.echo("Opsdroid will build modules from config.") path = params.get("path") with contextlib.suppress(Exception): check_dependencies() config = load_config_file([path] if path else DEFAULT_CONFIG_LOCATIONS) if params["verbose"]: config["logging"] = {"level": "debug"} configure_logging(config) with OpsDroid(config=config) as opsdroid: opsdroid.loader.load_modules_from_config(config) click.echo(click.style("SUCCESS:", bg="green", bold=True), nl=False) click.echo(" Opsdroid modules successfully built from config.")
def test_load_config_file_with_env_vars(self): os.environ["ENVVAR"] = "opsdroid" config = load_config_file( [os.path.abspath("tests/configs/minimal_with_envs.yaml")]) self.assertEqual(config["connectors"]["shell"]["bot-name"], os.environ["ENVVAR"])
def test_load_config_file_2(self): config = load_config_file( [os.path.abspath("tests/configs/minimal_2.yaml")]) self.assertIsNotNone(config)
def test_load_config_broken(self): with self.assertRaises(SystemExit) as cm: _ = load_config_file( [os.path.abspath("tests/configs/full_broken.yaml")]) self.assertEqual(cm.exception.code, 1)
def test_load_config_valid_case_sensitivity(self): opsdroid, loader = self.setup() config = load_config_file( [os.path.abspath("tests/configs/valid_case_sensitivity.yaml")]) self.assertIsNotNone(config)
def test_load_config_valid(self): config = load_config_file( [os.path.abspath("tests/configs/full_valid.yaml")]) self.assertIsNotNone(config)
def test_load_broken_config_file(self): with mock.patch("sys.exit") as patched_sysexit: load_config_file([os.path.abspath("tests/configs/broken.yaml")]) self.assertTrue(patched_sysexit.called)
async def reload(self): """Reload opsdroid.""" await self.unload() self.config = load_config_file(self.config_path) await self.load()