diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/compileconfig.py | 5 | ||||
-rw-r--r-- | tools/manpage.py | 9 | ||||
-rw-r--r-- | tools/readconfig.py | 20 |
3 files changed, 23 insertions, 11 deletions
diff --git a/tools/compileconfig.py b/tools/compileconfig.py index 199e446..a023a6b 100755 --- a/tools/compileconfig.py +++ b/tools/compileconfig.py @@ -10,6 +10,7 @@ import re import base64 from datetime import datetime import manpage +import configschema class Symbol(str): pass @@ -562,8 +563,8 @@ def printnodenames(config): print " ".join(frontendnodenames|storagenodenames|signingnodenames|mergenodenames|statusservernodenames) def gen_manpage(manpagedir): - manpage.rewrite_manpage(manpagedir + "/catlfish-log.cfg.in.5.adoc", globalconfigschema, "Catlfish", "Catlfish Manual", "CATLFISH-LOG.CFG.IN(5)", "catlfish-log.cfg.in - catlfish log configuration") - manpage.rewrite_manpage(manpagedir + "/catlfish-node.cfg.5.adoc", localconfigschema, "Catlfish", "Catlfish Manual", "CATLFISH-NODE.CFG(5)", "catlfish-node.cfg - catlfish node configuration") + manpage.rewrite_manpage(manpagedir + "/catlfish-log.cfg.in.5.adoc", (configschema.globalconfigschema, configschema.globalconfigdefaults, configschema.globalconfigoptionals), "Catlfish", "Catlfish Manual", "CATLFISH-LOG.CFG.IN(5)", "catlfish-log.cfg.in - catlfish log configuration") + manpage.rewrite_manpage(manpagedir + "/catlfish-node.cfg.5.adoc", (configschema.localconfigschema, configschema.localconfigdefaults, configschema.localconfigoptionals), "Catlfish", "Catlfish Manual", "CATLFISH-NODE.CFG(5)", "catlfish-node.cfg - catlfish node configuration") def main(): parser = argparse.ArgumentParser(description="") diff --git a/tools/manpage.py b/tools/manpage.py index 1ea8753..d8ce09f 100644 --- a/tools/manpage.py +++ b/tools/manpage.py @@ -23,7 +23,7 @@ def traverse_schema_part(schema): schema_part = schema.get(k) result = None if isinstance(schema_part, tuple): - (lowleveldatatype, highleveldatatype) = schema_part + (lowleveldatatype, highleveldatatype, extra) = schema_part if isinstance(highleveldatatype, list): formatted_datatype = "|".join(["**"+t+"**" for t in highleveldatatype]) else: @@ -33,6 +33,13 @@ def traverse_schema_part(schema): else: result = "**" + k + "**: " + formatted_datatype + if extra["optional"]: + result += " (optional)" + + default = extra["default"] + if default != None: + result += " (default: %s)" % (default) + tree.add(k, (result, [])) elif isinstance(schema_part, dict): 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): |