[aur-dev][PATCH] config: allow reading both the proto file and the modified config
Nodiv Byzero
nodivbyzero at gmail.com
Thu Apr 12 17:51:08 UTC 2018
What do you think about adding one more line to check if $config is already set?
Something like:
if (!isset($config)) {
... do the parse_ini_file
}
Just to reduce disk operations.
On Thu, Apr 12, 2018 at 10:44 AM, Eli Schwartz <eschwartz at archlinux.org> wrote:
> This change allows aurweb configuration to be done via either:
> - copying config.proto to config and modifying values
> - creating a new config only containing modified values, next to a
> config.proto containing unmodified values
>
> The motivation for this change is to enable ansible configuration by
> storing only changed values, and deferring to config.proto otherwise.
>
> If a config.proto file does not exist next to /etc/aurweb/config or
> $AUR_CONFIG, it is ignored and *all* values are expected to live in the
> modified config file.
>
> Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
> ---
> aurweb/config.py | 4 ++++
> web/lib/confparser.inc.php | 8 +++++++-
> 2 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/aurweb/config.py b/aurweb/config.py
> index a52d942..c333c43 100644
> --- a/aurweb/config.py
> +++ b/aurweb/config.py
> @@ -13,6 +13,10 @@ def _get_parser():
> path = os.environ.get('AUR_CONFIG')
> else:
> path = "/etc/aurweb/config"
> +
> + if os.path.isfile(path + '.proto'):
> + with open(path + '.proto') as f:
> + _parser.read_file(f)
> _parser.read(path)
>
> return _parser
> diff --git a/web/lib/confparser.inc.php b/web/lib/confparser.inc.php
> index 499481d..2ed0108 100644
> --- a/web/lib/confparser.inc.php
> +++ b/web/lib/confparser.inc.php
> @@ -8,11 +8,17 @@ function config_load() {
> if (!$path) {
> $path = "/etc/aurweb/config";
> }
> + if (file_exists($path . ".proto")) {
> + $defaults = parse_ini_file($path . ".proto", true, INI_SCANNER_RAW);
> + } else {
> + $defaults = [];
> + }
> if (file_exists($path)) {
> - $AUR_CONFIG = parse_ini_file($path, true, INI_SCANNER_RAW);
> + $config = parse_ini_file($path, true, INI_SCANNER_RAW);
> } else {
> die("aurweb config file not found");
> }
> + $AUR_CONFIG = array_replace_recursive($defaults, $config)
> }
> }
>
> --
> 2.17.0
More information about the aur-dev
mailing list