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

Remove some .format functions

parent 5e7d242f
No related branches found
No related tags found
No related merge requests found
__version__ = '0.1.15' __version__ = '0.1.16'
from common_config.common import * from common_config.common import *
\ No newline at end of file
...@@ -54,7 +54,7 @@ def get_config_directories() -> List[dict]: ...@@ -54,7 +54,7 @@ def get_config_directories() -> List[dict]:
] ]
# If the EIGENSERVICE_CONFIG_PATH environment variable exists append to list # If the EIGENSERVICE_CONFIG_PATH environment variable exists append to list
key = "{}_CONFIG_DIR".format(APPLICATION_NAME.upper()).replace("-", "_").replace(" ", "_") key = f"{APPLICATION_NAME.upper().replace("-", "_").replace(" ", "_")}_CONFIG_DIR"
env_key = os.getenv(key) env_key = os.getenv(key)
if env_key is not None: if env_key is not None:
env_dir = { "path": Path(env_key), "kind": "env", "source": key } env_dir = { "path": Path(env_key), "kind": "env", "source": key }
...@@ -77,7 +77,7 @@ def get_potential_config_file_paths(suffix: str) -> List[dict]: ...@@ -77,7 +77,7 @@ def get_potential_config_file_paths(suffix: str) -> List[dict]:
config_paths.append(path) config_paths.append(path)
# If the EIGENSERVICE_CONFIG_PATH environment variable exists append to list # If the EIGENSERVICE_CONFIG_PATH environment variable exists append to list
key = "{}_CONFIG_PATH".format(APPLICATION_NAME.upper()).replace("-", "_").replace(" ", "_") key = f"{APPLICATION_NAME.upper().replace("-", "_").replace(" ", "_")}_CONFIG_PATH"
env_key = os.getenv(key) env_key = os.getenv(key)
if env_key is not None: if env_key is not None:
env_path = { "path": Path(env_key), "kind": "env", "source": key } env_path = { "path": Path(env_key), "kind": "env", "source": key }
...@@ -351,7 +351,7 @@ def create_config(): ...@@ -351,7 +351,7 @@ def create_config():
for i, p in enumerate(config_directories): for i, p in enumerate(config_directories):
# Create a source string describing the origin of the directory # Create a source string describing the origin of the directory
if p["kind"] == "env": if p["kind"] == "env":
source = "set via environment variable {}, ".format(p["source"]) source = f"set via environment variable {p['source']}, "
else: else:
source = "" source = ""
# Display some options # Display some options
...@@ -387,13 +387,11 @@ def create_config(): ...@@ -387,13 +387,11 @@ def create_config():
selection["path"].mkdir(mode=0o755, parents=True, exist_ok=True) selection["path"].mkdir(mode=0o755, parents=True, exist_ok=True)
except PermissionError: except PermissionError:
python_path = f"{sys.prefix}/bin/python3" python_path = f"{sys.prefix}/bin/python3"
script_path = f"{inspect.stack()[-1][1]}"
print() print()
print(f"Error: Didn't have the permissions to create the config directory at {selection['path']}", file=sys.stderr) print(f"Error: Didn't have the permissions to create the config directory at {selection['path']}", file=sys.stderr)
print(f"Hint: Change the owner of the directory temporarily to {getpass.getuser()} or run {APPLICATION_NAME} config create with more permissions", file=sys.stderr) print(f"Hint: Change the owner of the directory temporarily to {getpass.getuser()} or run {APPLICATION_NAME} config create with more permissions", file=sys.stderr)
print(f"Hint: The python executable used by this script is located at \"{python_path}\"", file=sys.stderr) print(f"Hint: To run the script with this python executable run \"sudo {python_path} {script_path}\"", file=sys.stderr)
# Run again with priviledges
subprocess.call(['sudo', python_path, *sys.argv])
sys.exit() sys.exit()
config_path = Path(f"{selection['path']}/00-{SUFFIX}.toml") config_path = Path(f"{selection['path']}/00-{SUFFIX}.toml")
...@@ -406,9 +404,9 @@ def create_config(): ...@@ -406,9 +404,9 @@ def create_config():
i = 1 i = 1
while alt_config_path is None or alt_config_path.exists(): while alt_config_path is None or alt_config_path.exists():
if i == 1: if i == 1:
alt_config_path = Path("{}.old".format(config_path)) alt_config_path = Path(f"{config_path}.old")
else: else:
alt_config_path = Path("{}.old{}".format(config_path, i)) alt_config_path = Path(f"{config_path}.old{i}")
i += 1 i += 1
# Ask for confirmation # Ask for confirmation
...@@ -433,8 +431,6 @@ def create_config(): ...@@ -433,8 +431,6 @@ def create_config():
print() print()
print(f"Hint: Change the owner of the directory temporarily to {getpass.getuser()} or run {APPLICATION_NAME} config create with more permissions") print(f"Hint: Change the owner of the directory temporarily to {getpass.getuser()} or run {APPLICATION_NAME} config create with more permissions")
print(f"Hint: To run the script with this python executable run \"sudo {python_path} {script_path}\"", file=sys.stderr) print(f"Hint: To run the script with this python executable run \"sudo {python_path} {script_path}\"", file=sys.stderr)
# Run again with priviledges
# subprocess.call(['sudo', python_path, *sys.argv])
sys.exit() sys.exit()
print(f"Default Config has been written to {config_path}") print(f"Default Config has been written to {config_path}")
......
[tool.poetry] [tool.poetry]
name = "common-config" name = "common-config"
version = "0.1.15" version = "0.1.16"
description = "A config library for eigenservice" description = "A config library for eigenservice"
authors = ["David Huss <dh@atoav.com>"] 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