added generation of config file
This commit is contained in:
parent
6f589b86e2
commit
aff54b38ed
@ -15,6 +15,7 @@ license-files = ["LICENSE"]
|
|||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
python-mommy-dev = "python_mommy_venv.__main__:development"
|
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"
|
mommify-venv = "python_mommy_venv.__main__:mommify_venv"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
|
@ -2,8 +2,11 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
|
import toml
|
||||||
|
|
||||||
from . import get_response
|
from . import get_response
|
||||||
from .static import Situation
|
from .static import Situation
|
||||||
|
from .config import CONFIG_FILES, CONFIG_DIRECTORY, generate_current_configuration
|
||||||
|
|
||||||
|
|
||||||
def development():
|
def development():
|
||||||
@ -11,9 +14,21 @@ def development():
|
|||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
s = sys.argv[1]
|
s = sys.argv[1]
|
||||||
|
|
||||||
|
|
||||||
print(get_response(Situation(s)))
|
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}
|
TEMPLATE = """#!{inner_bin}
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict, Union
|
||||||
import os
|
import os
|
||||||
from os.path import expandvars
|
from os.path import expandvars
|
||||||
from sys import platform
|
from sys import platform
|
||||||
@ -119,10 +119,10 @@ def _get_xdg_config_dir() -> Path:
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
_CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
|
CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
|
||||||
CONFIG_FILES = [
|
CONFIG_FILES = [
|
||||||
_CONFIG_DIRECTORY / "python-mommy.toml",
|
CONFIG_DIRECTORY / "python-mommy.toml",
|
||||||
_CONFIG_DIRECTORY / "mommy.toml",
|
CONFIG_DIRECTORY / "mommy.toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
def load_config_file(config_file: Path) -> bool:
|
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"])
|
result[key] = random.choice(value["defaults"])
|
||||||
|
|
||||||
return result
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user