Commit d86cdacf authored by akhuziy's avatar akhuziy
Browse files

added output as a file

parent dba2bd5b
......@@ -7,6 +7,20 @@ import conf.config as conf
from format import format
from rcm import rcm
def merge_and_out(job_id, aggr, rcm, type, out_dir=None):
formatted = format.format(aggr, type)
formatted["recommendations"] = rcm
if out_dir is None:
filename = "{:s}/{:s}.{:s}.json".format(out_dir, job_id, type)
with open(filename, 'w') as outfile:
json.dump(formatted, outfile)
print("{:s} data was exported in {:s}".format(type, filename))
def main():
parser = argparse.ArgumentParser(description="""
Gets the job information required for generating text or PDF reports
......@@ -14,23 +28,35 @@ def main():
""", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-t", "--type", help="type of the output",
choices=['text', 'pdf'], default="text")
choices=['text', 'pdf', 'all'], default="text")
parser.add_argument("-o", "--output-dir", help="output directory",
const="./out", required=False, nargs='?')
help="job ID used in the batch system")
args = parser.parse_args()
# Errors in arguments
if args.output_dir is None:
if args.type == "all":
print("Cannot print both data in STDOUT")
# End of errors in arguments
job_id = args.JOBID
aggr = aggregator.get_aggregator(job_id, "pdf")
formatted = format.format(aggr, args.type)
recommendations = rcm.get_recommendations(aggr)
formatted["recommendations"] = recommendations
if args.output_dir is None:
merge_and_out(job_id, aggr, recommendations, args.type)
if args.type == "all":
merge_and_out(job_id, aggr, recommendations, "text", args.output_dir)
merge_and_out(job_id, aggr, recommendations, "pdf", args.output_dir)
merge_and_out(job_id, aggr, recommendations, args.type, args.output_dir)
return 0
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