Commit c2a7d27a authored by Łukasz Nowak's avatar Łukasz Nowak

Provide file for status

In cases where surykatka is used, it's very good that it would write the
status to some file, as otherwise the output has to be read, and then the
status has to be directed to the file, which requires adding one more layer
of complexity.
parent a25dd45a
......@@ -384,24 +384,32 @@ class WebBot:
if status_dict is not None:
if self.config["FORMAT"] == "json":
print(json.dumps(status_dict))
status_output = json.dumps(status_dict)
else:
status_list = []
a = status_list.append
for table_key in status_dict:
print("# %s" % table_key)
print("")
a("# %s" % table_key)
a("")
table = status_dict[table_key]
if table:
# Print the header
# a the header
table_key_list = [x for x in table[0].keys()]
table_key_list.sort()
print(" | ".join(table_key_list))
a(" | ".join(table_key_list))
for line in table:
print(
a(
" | ".join(
["%s" % (line[x]) for x in table_key_list]
)
)
print("")
a("")
status_output = '\n'.join(status_list)
if self.config['DESTINATION']:
with open(self.config['DESTINATION'], 'w') as fh:
fh.write(status_output)
else:
print(status_output)
def create_bot(**kw):
......
......@@ -55,6 +55,11 @@ from .bot import create_bot
default="plain",
show_default=True,
)
@click.option(
"--destination",
"-d",
help="File to store status. (default: stdout)",
)
def runSurykatka(
run,
sqlite,
......@@ -65,6 +70,7 @@ def runSurykatka(
configuration,
reload,
output,
destination,
):
mapping = {}
......@@ -84,6 +90,7 @@ def runSurykatka(
if reload:
mapping["RELOAD"] = str(reload)
mapping["FORMAT"] = output
mapping["DESTINATION"] = destination or ''
bot = create_bot(cfgfile=configuration, mapping=mapping)
return bot.run(run)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment