config-validate: Allow defining variables

When trying to validate a template that should later be filled in with
`pungi-config-dump`, there will be errors about undefined variables.
These are meant to be set when the template is populated.

This patch adds support for `-e`, `--define` argument to the validation
script that can be used to suppress these errors.

Alternatively a JSON file is read from the directory with config file
that can contain values for the variables.

The `--define` option is changed in both validation and dumping to allow
empty string as an accepted value.

JIRA: COMPOSE-3599
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2019-06-21 09:44:48 +02:00
parent 32624c59b1
commit acd3c19618
5 changed files with 95 additions and 18 deletions

View file

@ -935,9 +935,10 @@ def iter_module_defaults(path):
yield mmddef
def load_config(file_path):
def load_config(file_path, defaults={}):
"""Open and load configuration file form .conf or .json file."""
conf = kobo.conf.PyConfigParser()
conf.load_from_dict(defaults)
if file_path.endswith(".json"):
with open(file_path) as f:
conf.load_from_dict(json.load(f))