Skip to content
Snippets Groups Projects
Commit 86b41dae authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Expand README, try to elevate permissions if needed

parent 59a88bab
No related branches found
No related tags found
No related merge requests found
# common-config
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
__version__ = '0.1.2'
__version__ = '0.1.3'
from common_config.common import *
\ No newline at end of file
#!/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")
......
[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>"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment