Add JSON Schema for configuration
The schema is written in Python to reduce duplication. When configuration is loaded, the validation checks if it's correct and fills in default values. There is a custom extension to the schema to report deprecated options. The config dependencies are implemented as a separate pass. While it's technically possible to express the dependencies in the schema itself, the error messages are not very helpful and it makes the schema much harder to read. Phases no longer define `config_options`. New options should be added to the schema. Since the default values are populated automatically during validation, there is no need to duplicate them into the code. The `pungi-config-validate` script is updated to use the schema and report errors even for deeply nested fields. The dependencies are updated: pungi now depends on `python-jsonschema` (which is already available in Fedora). Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
5534fda192
commit
f9a6c8418f
53 changed files with 1423 additions and 903 deletions
|
|
@ -4,12 +4,12 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import kobo.conf
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import contextlib
|
||||
import shutil
|
||||
|
||||
here = sys.path[0]
|
||||
if here != '/usr/bin':
|
||||
|
|
@ -17,8 +17,9 @@ if here != '/usr/bin':
|
|||
sys.path[0] = os.path.dirname(here)
|
||||
|
||||
import pungi.compose
|
||||
import pungi.phases
|
||||
import pungi.checks
|
||||
import pungi.paths
|
||||
import pungi.phases
|
||||
|
||||
|
||||
class ValidationCompose(pungi.compose.Compose):
|
||||
|
|
@ -63,6 +64,12 @@ def run(config, topdir, has_old):
|
|||
conf = kobo.conf.PyConfigParser()
|
||||
conf.load_from_file(config)
|
||||
|
||||
errors = pungi.checks.validate(conf)
|
||||
if errors:
|
||||
for error in errors:
|
||||
print(error)
|
||||
sys.exit(1)
|
||||
|
||||
compose = ValidationCompose(conf, has_old, topdir)
|
||||
|
||||
pkgset_phase = pungi.phases.PkgsetPhase(compose)
|
||||
|
|
|
|||
|
|
@ -173,6 +173,11 @@ def main():
|
|||
if not pungi.checks.check(conf):
|
||||
sys.exit(1)
|
||||
pungi.checks.check_umask(logger)
|
||||
errors = pungi.checks.validate(conf)
|
||||
if errors:
|
||||
for error in errors:
|
||||
print >>sys.stderr, error
|
||||
sys.exit(1)
|
||||
|
||||
if opts.target_dir:
|
||||
compose_dir = Compose.get_compose_dir(opts.target_dir, conf, compose_type=compose_type, compose_label=opts.label)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue