mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
config: allow reading both the defaults file and the modified config
In the process, rename config.proto to config.defaults (because that is what it is now). Also use dict.get('key', default_value) when querying os.environ, rather than an if block, as it is more pythonic/readable/concise, and reduces the number of dict lookups. This change allows aurweb configuration to be done via either: - copying config.defaults to config and modifying values - creating a new config only containing modified values, next to a config.defaults containing unmodified values The motivation for this change is to enable ansible configuration in our flagship deployment by storing only changed values, and deferring to config.defaults otherwise. A side benefit is, it is easier to see what has changed by inspecting only the site configuration file. If a config.defaults file does not exist next to $AUR_CONFIG or in $AUR_CONFIG_DEFAULTS, it is ignored and *all* values are expected to live in the modified config file. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
2b280ea3d8
commit
97c5bcec13
5 changed files with 22 additions and 8 deletions
6
INSTALL
6
INSTALL
|
@ -40,8 +40,10 @@ read the instructions below.
|
||||||
|
|
||||||
Ensure to enable the pdo_mysql extension in php.ini.
|
Ensure to enable the pdo_mysql extension in php.ini.
|
||||||
|
|
||||||
3) Copy conf/config.proto to /etc/aurweb/config and adjust the configuration
|
3) Optionally copy conf/config.defaults to /etc/aurweb/. Create or copy
|
||||||
(pay attention to disable_http_login, enable_maintenance and aur_location).
|
/etc/aurweb/config (this is expected to contain all configuration settings
|
||||||
|
if the defaults file does not exist) and adjust the configuration (pay
|
||||||
|
attention to disable_http_login, enable_maintenance and aur_location).
|
||||||
|
|
||||||
4) Create a new MySQL database and a user and import the aurweb SQL schema:
|
4) Create a new MySQL database and a user and import the aurweb SQL schema:
|
||||||
|
|
||||||
|
|
2
TESTING
2
TESTING
|
@ -23,7 +23,7 @@ INSTALL.
|
||||||
$ sqlite3 ../aurweb.sqlite3 < aur-schema-sqlite.sql
|
$ sqlite3 ../aurweb.sqlite3 < aur-schema-sqlite.sql
|
||||||
$ sqlite3 ../aurweb.sqlite3 < out.sql
|
$ sqlite3 ../aurweb.sqlite3 < out.sql
|
||||||
|
|
||||||
4) Copy conf/config.proto to conf/config and adjust the configuration
|
4) Copy conf/config.defaults to conf/config and adjust the configuration
|
||||||
(pay attention to disable_http_login, enable_maintenance and aur_location).
|
(pay attention to disable_http_login, enable_maintenance and aur_location).
|
||||||
|
|
||||||
Be sure to change backend to sqlite and name to the file location of your
|
Be sure to change backend to sqlite and name to the file location of your
|
||||||
|
|
|
@ -8,11 +8,13 @@ def _get_parser():
|
||||||
global _parser
|
global _parser
|
||||||
|
|
||||||
if not _parser:
|
if not _parser:
|
||||||
|
path = os.environ.get('AUR_CONFIG', '/etc/aurweb/config')
|
||||||
|
defaults = os.environ.get('AUR_CONFIG_DEFAULTS', path + '.defaults')
|
||||||
|
|
||||||
_parser = configparser.RawConfigParser()
|
_parser = configparser.RawConfigParser()
|
||||||
if 'AUR_CONFIG' in os.environ:
|
if os.path.isfile(defaults):
|
||||||
path = os.environ.get('AUR_CONFIG')
|
with open(defaults) as f:
|
||||||
else:
|
_parser.read_file(f)
|
||||||
path = "/etc/aurweb/config"
|
|
||||||
_parser.read(path)
|
_parser.read(path)
|
||||||
|
|
||||||
return _parser
|
return _parser
|
||||||
|
|
|
@ -8,11 +8,21 @@ function config_load() {
|
||||||
if (!$path) {
|
if (!$path) {
|
||||||
$path = "/etc/aurweb/config";
|
$path = "/etc/aurweb/config";
|
||||||
}
|
}
|
||||||
|
$defaults_path = getenv('AUR_CONFIG_DEFAULTS');
|
||||||
|
if (!$defaults_path) {
|
||||||
|
$defaults_path = path . ".defaults";
|
||||||
|
}
|
||||||
|
if (file_exists($defaults_path)) {
|
||||||
|
$default_config = parse_ini_file($defaults_path, true, INI_SCANNER_RAW);
|
||||||
|
} else {
|
||||||
|
$default_config = [];
|
||||||
|
}
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
$AUR_CONFIG = parse_ini_file($path, true, INI_SCANNER_RAW);
|
$config = parse_ini_file($path, true, INI_SCANNER_RAW);
|
||||||
} else {
|
} else {
|
||||||
die("aurweb config file not found");
|
die("aurweb config file not found");
|
||||||
}
|
}
|
||||||
|
$AUR_CONFIG = array_replace_recursive($default_config, $config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue