Add script to merge and dump multiple configuration files
The script can either take config from an existing compose, or load files by path. By default it will perform full validation (and add default values and resolved git references). This can be turned off. The final JSON is printed to stdout. JIRA: COMPOSE-3066 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
ca7d6256e5
commit
df35f26910
74
bin/pungi-config-dump
Executable file
74
bin/pungi-config-dump
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import kobo.conf
|
||||||
|
import pungi.checks
|
||||||
|
|
||||||
|
|
||||||
|
def load_file(source, conf):
|
||||||
|
try:
|
||||||
|
with open(source) as f:
|
||||||
|
conf.load_from_dict(json.load(f))
|
||||||
|
except ValueError:
|
||||||
|
conf.load_from_file(source)
|
||||||
|
|
||||||
|
|
||||||
|
def load_source(source, conf):
|
||||||
|
if os.path.isfile(source):
|
||||||
|
load_file(source, conf)
|
||||||
|
else:
|
||||||
|
load_file(os.path.join(source, "logs/global/config-dump.global.log"), conf)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"sources",
|
||||||
|
metavar="SOURCE",
|
||||||
|
nargs="+",
|
||||||
|
help=(
|
||||||
|
"Source for the configuration; either a compose "
|
||||||
|
"or arbitrary number of config files."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument(
|
||||||
|
"--just-dump",
|
||||||
|
action="store_true",
|
||||||
|
help=(
|
||||||
|
"Do not transform the config in any way. Default values are not "
|
||||||
|
"added, git references are not resolved."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--offline", action="store_true", help="Do not resolve git references."
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
conf = kobo.conf.PyConfigParser()
|
||||||
|
|
||||||
|
for source in args.sources:
|
||||||
|
load_source(source, conf)
|
||||||
|
|
||||||
|
if not args.just_dump:
|
||||||
|
errors, _ = pungi.checks.validate(conf, offline=args.offline)
|
||||||
|
if errors:
|
||||||
|
for error in errors:
|
||||||
|
print(error, file=sys.stderr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
json.dump(conf, sys.stdout, sort_keys=True, indent=4)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if not main():
|
||||||
|
sys.exit(1)
|
@ -96,6 +96,7 @@ rm -rf %{buildroot}
|
|||||||
%files utils
|
%files utils
|
||||||
%{python_sitelib}/%{name}_utils
|
%{python_sitelib}/%{name}_utils
|
||||||
%{_bindir}/%{name}-create-unified-isos
|
%{_bindir}/%{name}-create-unified-isos
|
||||||
|
%{_bindir}/%{name}-config-dump
|
||||||
%{_bindir}/%{name}-config-validate
|
%{_bindir}/%{name}-config-validate
|
||||||
%{_bindir}/%{name}-fedmsg-notification
|
%{_bindir}/%{name}-fedmsg-notification
|
||||||
%{_bindir}/%{name}-patch-iso
|
%{_bindir}/%{name}-patch-iso
|
||||||
|
1
setup.py
1
setup.py
@ -36,6 +36,7 @@ setup(
|
|||||||
scripts = [
|
scripts = [
|
||||||
'bin/comps_filter',
|
'bin/comps_filter',
|
||||||
'bin/pungi',
|
'bin/pungi',
|
||||||
|
'bin/pungi-config-dump',
|
||||||
'bin/pungi-config-validate',
|
'bin/pungi-config-validate',
|
||||||
'bin/pungi-create-unified-isos',
|
'bin/pungi-create-unified-isos',
|
||||||
'bin/pungi-fedmsg-notification',
|
'bin/pungi-fedmsg-notification',
|
||||||
|
Loading…
Reference in New Issue
Block a user