32a6415e58
If the validation or dumping script is given some options, they should only be removed if they are not valid. We have to remove the invalid ones, otherwise that would cause a warning about unknown options. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
31 lines
847 B
Python
31 lines
847 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
import argparse
|
|
import re
|
|
|
|
from pungi.checks import make_schema
|
|
|
|
|
|
def validate_definition(value):
|
|
"""Check that the variable name is a valid Python variable name, and that
|
|
there is an equals sign. The value can by anything non-empty.
|
|
"""
|
|
if not re.match(r"^[a-z_]\w*=.*$", value):
|
|
raise argparse.ArgumentTypeError(
|
|
"definition should be in var=value format: %r" % value
|
|
)
|
|
return value
|
|
|
|
|
|
def extract_defines(args):
|
|
"""Given an iterable of "key=value" strings, parse them into a dict."""
|
|
return dict(var.split("=", 1) for var in args)
|
|
|
|
|
|
def remove_unknown(conf, keys):
|
|
"""Remove given keys from the config unless they are known Pungi options."""
|
|
schema = make_schema()
|
|
for key in keys:
|
|
if key not in schema["properties"]:
|
|
del conf[key]
|