summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2017-07-26 01:34:57 +0200
committerLinus Nordberg <linus@nordu.net>2017-07-26 13:19:39 +0200
commit4f8f473db95c2262c3f387aed3d4459555ac52e2 (patch)
tree9a4f3706779c7b0a5c4ea17c06305e1b263ae7a0 /tools
parente0be874a28c9ee9c9b07e3cff89301cd58cfd31f (diff)
Output optional and defaults to configuration man page
Diffstat (limited to 'tools')
-rwxr-xr-xtools/compileconfig.py5
-rw-r--r--tools/manpage.py9
-rw-r--r--tools/readconfig.py20
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):