From 86b41dae57f325ebe633e9f91c2f8bcfcd5fec8a Mon Sep 17 00:00:00 2001 From: David Huss <dh@atoav.com> Date: Sun, 31 Oct 2021 14:59:02 +0100 Subject: [PATCH] Expand README, try to elevate permissions if needed --- README.md | 54 ++++++++++++++++++++++++++++++++++++++- common_config/__init__.py | 2 +- common_config/common.py | 10 +++----- pyproject.toml | 2 +- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c0ce7aa..9412072 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 f6cb739..0d72cd9 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 6cee50d..d7288b3 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 2524723..516208a 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>"] -- GitLab