From 517da8b864a275fa4a18aba4b16c10794174b5f0 Mon Sep 17 00:00:00 2001 From: David Huss <dh@atoav.com> Date: Sun, 31 Oct 2021 15:09:37 +0100 Subject: [PATCH] Try priviledge escalation --- README.md | 2 +- common_config/__init__.py | 2 +- common_config/common.py | 4 +++- examples/config.py | 27 +++++++++++++++++++++++++++ pyproject.toml | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 examples/config.py diff --git a/README.md b/README.md index 9412072..93eedd5 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ import common_config from common_config import initialize_config, read_settings, main # Name of this application, used in directory names, etc -APPLICATION_NAME = "eigenservice" +APPLICATION_NAME = "my_application" # suffix added to the config files (e.g. `00-suffix.toml`) SUFFIX = "config" diff --git a/common_config/__init__.py b/common_config/__init__.py index 0d72cd9..f8fb29d 100644 --- a/common_config/__init__.py +++ b/common_config/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.1.3' +__version__ = '0.1.4' from common_config.common import * \ No newline at end of file diff --git a/common_config/common.py b/common_config/common.py index d7288b3..27ea294 100644 --- a/common_config/common.py +++ b/common_config/common.py @@ -389,7 +389,9 @@ def create_config(): 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)) - subprocess.call(['sudo', 'python3', *sys.argv]) + # Run again with priviledges + python_path = f"{sys.prefix}/bin/python3" + subprocess.call(['sudo', python_path, *sys.argv]) sys.exit() config_path = Path(f"{selection['path']}/00-{SUFFIX}.toml") diff --git a/examples/config.py b/examples/config.py new file mode 100644 index 0000000..e211a40 --- /dev/null +++ b/examples/config.py @@ -0,0 +1,27 @@ +#!/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 = "my_application" + +# 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() diff --git a/pyproject.toml b/pyproject.toml index 516208a..b0f5269 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "common-config" -version = "0.1.3" +version = "0.1.4" description = "A config library for eigenservice" authors = ["David Huss <dh@atoav.com>"] -- GitLab