From 4f8f473db95c2262c3f387aed3d4459555ac52e2 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Wed, 26 Jul 2017 01:34:57 +0200 Subject: Output optional and defaults to configuration man page --- doc/catlfish-log.cfg.in.5.adoc | 3 +++ doc/catlfish-node.cfg.5.adoc | 20 +++++++------------- tools/compileconfig.py | 5 +++-- tools/manpage.py | 9 ++++++++- tools/readconfig.py | 20 ++++++++++++-------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/doc/catlfish-log.cfg.in.5.adoc b/doc/catlfish-log.cfg.in.5.adoc index 1cc912f..43559cc 100644 --- a/doc/catlfish-log.cfg.in.5.adoc +++ b/doc/catlfish-log.cfg.in.5.adoc @@ -81,6 +81,9 @@ OPTIONS **storage-quorum-size**: __number-of-nodes__:: // write description here + **storage-sign-quorum-size**: __number-of-nodes__ (default: 0):: +// write description here + **storagenodes**: (list of items):: // write description here diff --git a/doc/catlfish-node.cfg.5.adoc b/doc/catlfish-node.cfg.5.adoc index fabef29..2cbf596 100644 --- a/doc/catlfish-node.cfg.5.adoc +++ b/doc/catlfish-node.cfg.5.adoc @@ -12,13 +12,13 @@ OPTIONS **configurl**: __url__:: // write description here - **ctapiaddress**: __ip-address__:: + **ctapiaddress**: __ip-address__ (optional):: // write description here - **dbbackend**: **permdb**|**fsdb**:: + **dbbackend**: **permdb**|**fsdb** (default: fsdb):: // write description here - **frontendaddress**: __ip-address__:: + **frontendaddress**: __ip-address__ (optional):: // write description here **logadminkey**: __key__:: @@ -48,7 +48,7 @@ OPTIONS **min-delay**: __seconds__::: // write description here - **mergeaddress**: __ip-address__:: + **mergeaddress**: __ip-address__ (optional):: // write description here **nodename**: __nodename__:: @@ -81,22 +81,16 @@ OPTIONS **logpublickey**: __path__::: // write description here - **mergedb**: __path__::: -// write description here - **privatekeys**: __path__::: // write description here **public_cacertfile**: __path__::: // write description here - **publickeys**: __path__::: -// write description here - **verifycert_bin**: __path__::: // write description here - **publichttpaddress**: __ip-address__:: + **publichttpaddress**: __ip-address__ (optional):: // write description here **ratelimits**: :: @@ -105,9 +99,9 @@ OPTIONS **add_chain**: __rate__::: // write description here - **signingaddress**: __ip-address__:: + **signingaddress**: __ip-address__ (optional):: // write description here - **storageaddress**: __ip-address__:: + **storageaddress**: __ip-address__ (optional):: // write description here 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): -- cgit v1.1