#!/usr/bin/env python3 import shutil import click from pathlib import Path from lib.config import load_yaml, write_yaml, get_profile_dir from lib.functions import deep_update, copytree_no_copystat from lib.run import compose_exec def profile_exists(container, name): command = [ "sh", "-lc", f"test -d /opt/data/profiles/{name}" ] result = compose_exec(container, *command, check=False) return result.returncode == 0 def ensure_profile(container, name, description=None): if not profile_exists(container, name): if description: description = ["--description", description] else: description = [] compose_exec(container, "hermes", "profile", "create", name, *description, "--clone") def set_state(container, name, state): if state == "running": compose_exec(container, "hermes", "-p", name, "gateway", "start") elif state == "stopped": compose_exec(container, "hermes", "-p", name, "gateway", "stop") elif state in (None, "existing"): return else: raise click.ClickException(f"Unsupported state for {name}: {state}") def copy_seed(container, profile, source): destination = get_profile_dir(container, profile) if not Path(source).is_dir(): click.echo(f"[WARNING] {source} is not a valid seed directory") return print(f"Copying to {destination}") copytree_no_copystat(source, destination) def apply_settings(container, name, config): profile_path = get_profile_dir(container, name) config_path = profile_path / "config.yaml" data = load_yaml(config_path) data = deep_update(data, {'model': config['model']}) data = deep_update(data, config['config']) write_yaml(config_path, data) if config.get("soul"): open(profile_path / "SOUL.md", 'w').write(config['soul'])