diff options
author | Magnus Ahltorp <map@kth.se> | 2017-07-26 01:34:57 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-07-26 13:19:39 +0200 |
commit | 4f8f473db95c2262c3f387aed3d4459555ac52e2 (patch) | |
tree | 9a4f3706779c7b0a5c4ea17c06305e1b263ae7a0 /tools/readconfig.py | |
parent | e0be874a28c9ee9c9b07e3cff89301cd58cfd31f (diff) |
Output optional and defaults to configuration man page
Diffstat (limited to 'tools/readconfig.py')
-rw-r--r-- | tools/readconfig.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/tools/readconfig.py b/tools/readconfig.py index b9a0b07..edfc342 100644 --- a/tools/readconfig.py +++ b/tools/readconfig.py @@ -65,19 +65,23 @@ def verify_and_read_config(filename, publickey_base64): signature = open(filename + ".sig").read() return verify_config(rawconfig, signature, publickey_base64, filename) -def insert_schema_path(schema, path, datatype, highleveldatatype): +def insert_schema_path(schema, path, datatype, highleveldatatype, extra): if len(path) == 1: - schema[path[0]] = (datatype, highleveldatatype) + schema[path[0]] = (datatype, highleveldatatype, extra) else: if path[0] not in schema: schema[path[0]] = {} - insert_schema_path(schema[path[0]], path[1:], datatype, highleveldatatype) + insert_schema_path(schema[path[0]], path[1:], datatype, highleveldatatype, extra) -def transform_schema(in_schema): +def transform_schema((in_schema, defaults, optionals)): + defaults_dict = dict(defaults) schema = {} for (rawpath, datatype, highleveldatatype) in in_schema: path = rawpath.split("/") - insert_schema_path(schema, path, datatype, highleveldatatype) + extra = {} + extra["optional"] = rawpath in optionals + extra["default"] = defaults_dict.get(rawpath) + insert_schema_path(schema, path, datatype, highleveldatatype, extra) return schema def check_config_schema(config, schema): @@ -98,11 +102,11 @@ def check_config_schema_part(term, schema, path=[]): joined_path = render_path(path) problems = [] if isinstance(term, basestring): - (schema_lowlevel, schema_highlevel) = schema + (schema_lowlevel, schema_highlevel, extra) = schema if schema_lowlevel != "string": problems.append("error: expected %s at %s, not a string" % (schema_lowlevel, joined_path,)) elif isinstance(term, int): - (schema_lowlevel, schema_highlevel) = schema + (schema_lowlevel, schema_highlevel, extra) = schema if schema_lowlevel != "integer": problems.append("error: expected %s at %s, not an integer" % (schema_lowlevel, joined_path,)) elif isinstance(term, dict): @@ -152,7 +156,7 @@ def common_read_config(f, filename, localconfig=True): optionals = configschema.globalconfigoptionals config = yaml.load(f, yaml.SafeLoader) insert_defaults(config, configdefaults) - check_config_schema(config, schema) + check_config_schema(config, (schema, configdefaults, optionals)) return errorhandlify(config, filename, optionals) def read_config(filename, localconfig=True): |