diff --git a/pyproject.toml b/pyproject.toml index 110eb7f..dd01be8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ license-files = ["LICENSE"] [project.scripts] python-mommy-dev = "python_mommy_venv.__main__:development" +python-mommy-generate-config = "python_mommy_venv.__main__:write_current_config" mommify-venv = "python_mommy_venv.__main__:mommify_venv" [build-system] diff --git a/python_mommy_venv/__main__.py b/python_mommy_venv/__main__.py index a4e802c..bb9db02 100644 --- a/python_mommy_venv/__main__.py +++ b/python_mommy_venv/__main__.py @@ -2,8 +2,11 @@ import sys from pathlib import Path import stat +import toml + from . import get_response from .static import Situation +from .config import CONFIG_FILES, CONFIG_DIRECTORY, generate_current_configuration def development(): @@ -11,9 +14,21 @@ def development(): if len(sys.argv) > 1: s = sys.argv[1] - print(get_response(Situation(s))) +def write_current_config(): + f = "python-mommy.toml" + if len(sys.argv) > 1: + f = sys.argv[1] + + config_file = CONFIG_DIRECTORY / f + print(f"writing to: {config_file}") + + data = toml.dumps(generate_current_configuration()) + print(data) + with config_file.open("w") as f: + f.write(data) + TEMPLATE = """#!{inner_bin} # -*- coding: utf-8 -*- diff --git a/python_mommy_venv/config.py b/python_mommy_venv/config.py index 62b1a36..3025005 100644 --- a/python_mommy_venv/config.py +++ b/python_mommy_venv/config.py @@ -1,4 +1,4 @@ -from typing import Optional, List, Dict +from typing import Optional, List, Dict, Union import os from os.path import expandvars from sys import platform @@ -119,10 +119,10 @@ def _get_xdg_config_dir() -> Path: return default -_CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy" +CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy" CONFIG_FILES = [ - _CONFIG_DIRECTORY / "python-mommy.toml", - _CONFIG_DIRECTORY / "mommy.toml", + CONFIG_DIRECTORY / "python-mommy.toml", + CONFIG_DIRECTORY / "mommy.toml", ] def load_config_file(config_file: Path) -> bool: @@ -178,3 +178,16 @@ def get_template_values(mood: str) -> Dict[str, str]: result[key] = random.choice(value["defaults"]) return result + +def generate_current_configuration() -> Dict[str, Union[str, List[str]]]: + global CONFIG + generated = {} + + for key, definition in CONFIG.items(): + value = definition["defaults"] + if len(value) == 1: + value = value[0] + + generated[key] = value + + return generated