diff --git a/README.md b/README.md index c0ce7aa896ddff7b8aff89c4c326d0c1b985745a..941207223d782cdee306dfa1ab2e30057d697f71 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,55 @@ # common-config -This is a common configuration library for eigenservice \ No newline at end of file +This is a common configuration library for eigenservice + + + +Add this dependency to your application e.g. using poetry (ssh-add so you don't have to type the ssh-password over and over): + +```bash + ssh-add + poetry add git+ssh://git@code.hfbk.net:4242/id/eigenservice/common-config.git -vvv +``` + +When something changes update it like this: + +```bash +poetry update common-config +``` + + + +Then in the application use something like this as a starting point: + +```python +#!/usr/bin/env python +#-*- coding: utf-8 -*- +import common_config +from common_config import initialize_config, read_settings, main + +# Name of this application, used in directory names, etc +APPLICATION_NAME = "eigenservice" + +# suffix added to the config files (e.g. `00-suffix.toml`) +SUFFIX = "config" + +# Do not change here, just use an override instead +DEFAULT_CONFIG = """ +[application] +loglevel = "info" +level = 9001 +mood = "very" +""" + +# Override the global variables in the common-config.common module +common_config.common.APPLICATION_NAME = APPLICATION_NAME +common_config.common.SUFFIX = SUFFIX +common_config.common.DEFAULT_CONFIG = DEFAULT_CONFIG + + +if __name__ == "__main__": + main() +``` + +If people now run that file, they will get an interactive configuration-tool + diff --git a/common_config/__init__.py b/common_config/__init__.py index f6cb7392c2cceb944a88e5babd862e09c78d79e0..0d72cd9006d93c7b9e50273517ffb053e7df19f0 100644 --- a/common_config/__init__.py +++ b/common_config/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.1.2' +__version__ = '0.1.3' from common_config.common import * \ No newline at end of file diff --git a/common_config/common.py b/common_config/common.py index 6cee50d6b765fdee87d85942762c609cea52b39f..d7288b34bca2dae895eccdf023fdee5c6e5bae7f 100644 --- a/common_config/common.py +++ b/common_config/common.py @@ -1,6 +1,7 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- import os, getpass, sys +import subprocess import logging import toml from pathlib import Path @@ -12,11 +13,6 @@ APPLICATION_NAME = "" SUFFIX = "" DEFAULT_CONFIG = "" -def read_settings(APPLICATION_NAME, SUFFIX, DEFAULT_CONFIG): - common_config.common.APPLICATION_NAME = APPLICATION_NAME - common_config.common.SUFFIX = SUFFIX - common_config.common.DEFAULT_CONFIG = DEFAULT_CONFIG - def this_or_else(this: Optional[str], other: str) -> str: """ @@ -392,7 +388,9 @@ def create_config(): print() print("Error: Didn't have the permissions to create the config directory at {}".format(selection["path"]), file=sys.stderr) print("Hint: Change the owner of the directory temporarily to {} or run {} config create with more permissions".format(getpass.getuser(), APPLICATION_NAME)) - exit() + + subprocess.call(['sudo', 'python3', *sys.argv]) + sys.exit() config_path = Path(f"{selection['path']}/00-{SUFFIX}.toml") diff --git a/pyproject.toml b/pyproject.toml index 25247237743ea658b64f81d51722517a123870bd..516208ab00e7351add521c7c87b08c3f749208e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "common-config" -version = "0.1.2" +version = "0.1.3" description = "A config library for eigenservice" authors = ["David Huss <dh@atoav.com>"]