treewide: reformat python code
This commit is contained in:
parent
f9fcbe9430
commit
a7d580b934
3 changed files with 185 additions and 129 deletions
|
@ -21,64 +21,71 @@ template = """
|
|||
f = open(sys.argv[1])
|
||||
options = json.load(f)
|
||||
|
||||
groups = ["mailserver.loginAccounts",
|
||||
"mailserver.certificate",
|
||||
"mailserver.dkim",
|
||||
"mailserver.dmarcReporting",
|
||||
"mailserver.fullTextSearch",
|
||||
"mailserver.redis",
|
||||
"mailserver.ldap",
|
||||
"mailserver.monitoring",
|
||||
"mailserver.backup",
|
||||
"mailserver.borgbackup"]
|
||||
groups = [
|
||||
"mailserver.loginAccounts",
|
||||
"mailserver.certificate",
|
||||
"mailserver.dkim",
|
||||
"mailserver.dmarcReporting",
|
||||
"mailserver.fullTextSearch",
|
||||
"mailserver.redis",
|
||||
"mailserver.ldap",
|
||||
"mailserver.monitoring",
|
||||
"mailserver.backup",
|
||||
"mailserver.borgbackup",
|
||||
]
|
||||
|
||||
|
||||
def render_option_value(opt, attr):
|
||||
if attr not in opt:
|
||||
return ""
|
||||
|
||||
if isinstance(opt[attr], dict) and '_type' in opt[attr]:
|
||||
if opt[attr]['_type'] == 'literalExpression':
|
||||
if '\n' in opt[attr]['text']:
|
||||
res = '\n```nix\n' + opt[attr]['text'].rstrip('\n') + '\n```'
|
||||
if isinstance(opt[attr], dict) and "_type" in opt[attr]:
|
||||
if opt[attr]["_type"] == "literalExpression":
|
||||
if "\n" in opt[attr]["text"]:
|
||||
res = "\n```nix\n" + opt[attr]["text"].rstrip("\n") + "\n```"
|
||||
else:
|
||||
res = '```{}```'.format(opt[attr]['text'])
|
||||
elif opt[attr]['_type'] == 'literalMD':
|
||||
res = opt[attr]['text']
|
||||
res = "```{}```".format(opt[attr]["text"])
|
||||
elif opt[attr]["_type"] == "literalMD":
|
||||
res = opt[attr]["text"]
|
||||
else:
|
||||
assert RuntimeError(f"Unhandled option type {opt[attr]["_type"]}")
|
||||
else:
|
||||
s = str(opt[attr])
|
||||
if s == "":
|
||||
res = '`""`'
|
||||
elif '\n' in s:
|
||||
res = '\n```\n' + s.rstrip('\n') + '\n```'
|
||||
elif "\n" in s:
|
||||
res = "\n```\n" + s.rstrip("\n") + "\n```"
|
||||
else:
|
||||
res = '```{}```'.format(s)
|
||||
res = "```{}```".format(s)
|
||||
|
||||
return "- " + attr + ": " + res # type: ignore
|
||||
|
||||
return '- ' + attr + ': ' + res # type: ignore
|
||||
|
||||
def print_option(opt):
|
||||
if isinstance(opt['description'], dict) and '_type' in opt['description']: # mdDoc
|
||||
description = opt['description']['text']
|
||||
if isinstance(opt["description"], dict) and "_type" in opt["description"]: # mdDoc
|
||||
description = opt["description"]["text"]
|
||||
else:
|
||||
description = opt['description']
|
||||
print(template.format(
|
||||
key=opt['name'],
|
||||
description=description or "",
|
||||
type="- type: ```{}```".format(opt['type']),
|
||||
default=render_option_value(opt, 'default'),
|
||||
example=render_option_value(opt, 'example')))
|
||||
description = opt["description"]
|
||||
print(
|
||||
template.format(
|
||||
key=opt["name"],
|
||||
description=description or "",
|
||||
type="- type: ```{}```".format(opt["type"]),
|
||||
default=render_option_value(opt, "default"),
|
||||
example=render_option_value(opt, "example"),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
print(header)
|
||||
for opt in options:
|
||||
if any([opt['name'].startswith(c) for c in groups]):
|
||||
if any([opt["name"].startswith(c) for c in groups]):
|
||||
continue
|
||||
print_option(opt)
|
||||
|
||||
for c in groups:
|
||||
print('## `{}`'.format(c))
|
||||
print("## `{}`".format(c))
|
||||
print()
|
||||
for opt in options:
|
||||
if opt['name'].startswith(c):
|
||||
if opt["name"].startswith(c):
|
||||
print_option(opt)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue