Exemple #1
0
def config(no_interactive: bool = False, template: str = None):
    """Adjust Thamos and Thoth remote configuration.

    Perform autodiscovery of available hardware and software on the host and
    create a default configuration for Thoth (placed into .thoth.yaml).
    """
    if template:
        _LOGGER.info(
            "Creating configuration file from a configuration template %r",
            template)
        configuration.create_default_config(template)

        if not no_interactive:
            configuration.open_config_file()

        return

    if not configuration.config_file_exists():
        _LOGGER.info(
            "No configuration file found, creating one from a configuration template from %s",
            "a default template" if template is None else template)
        configuration.create_default_config(template)

    if not no_interactive:
        configuration.open_config_file()
    elif no_interactive:
        _LOGGER.info(
            "Configuration file already present, no action performed in non-interactive mode"
        )
def _requirements_config(args):
    """Return script to be executed on `requirements config` command."""
    content = None

    # TODO: Allow the user to edit the file directly in Jupyter

    if args.to_file:
        with workdir():
            fp = Path(thoth_config.CONFIG_NAME)

            if fp.exists() and not args.overwrite:
                raise Exception(
                    "Config file already exists and `overwrite` is not set.")

            thoth_config.create_default_config()

        script = f"console.log('Default Thoth config file has been created:', {json.dumps(thoth_config.content)})"
        return script, {}

    if not thoth_config.config_file_exists():
        content: dict = thoth_config.create_default_config(nowrite=True)
        script = f"console.log('Default Thoth config:', {json.dumps(content)})"
    else:
        script = f"console.log('Thoth config file content:', {json.dumps(thoth_config.content)})"

    if args.to_json:
        print(json.dumps(thoth_config.content, indent=4))
    else:
        with workdir(thoth_config.CONFIG_NAME) as config_dir:
            print(Path(config_dir, thoth_config.CONFIG_NAME).read_text())

    return script, {}