feat: add aurweb-config console script

This can be used to update config values for the entirety
of a config. When config values are set through this tool,
$AUR_CONFIG is overridden with a copy of the config file
with all sections and options found in $AUR_CONFIG
+ $AUR_CONFIG_DEFAULTS.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-27 16:44:56 -08:00
parent e558e979ff
commit 759f18ea75
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
4 changed files with 199 additions and 0 deletions

View file

@ -1,6 +1,8 @@
import configparser
import os
from typing import Any
# Publicly visible version of aurweb. This is used to display
# aurweb versioning in the footer and must be maintained.
# Todo: Make this dynamic/automated.
@ -52,3 +54,13 @@ def getint(section, option, fallback=None):
def get_section(section):
if section in _get_parser().sections():
return _get_parser()[section]
def replace_key(section: str, option: str, value: Any) -> Any:
_get_parser().set(section, option, value)
def save() -> None:
aur_config = os.environ.get("AUR_CONFIG", "/etc/aurweb/config")
with open(aur_config, "w") as fp:
_get_parser().write(fp)