added generation of config file

This commit is contained in:
Hazel Noack 2025-07-28 12:40:27 +02:00
parent 6f589b86e2
commit aff54b38ed
3 changed files with 34 additions and 5 deletions

View File

@ -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]

View File

@ -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 -*-

View File

@ -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