From bce164eb669ce18b82b16adfcd7bd3e8c4d7019e Mon Sep 17 00:00:00 2001 From: Ramy Asselin Date: Wed, 11 Nov 2015 16:36:35 -0800 Subject: [PATCH] The output file is optional. Default to stdout if not specified. Avoid python stacktrace when omitting the output file. Write to stdout by default. Change-Id: I7e8bc7b2c49402786ddc20dca353bff6269ed594 --- elastic_recheck/cmd/graph.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/elastic_recheck/cmd/graph.py b/elastic_recheck/cmd/graph.py index cc4383a4..7f66e8d7 100755 --- a/elastic_recheck/cmd/graph.py +++ b/elastic_recheck/cmd/graph.py @@ -19,6 +19,7 @@ import ConfigParser from datetime import datetime import json import os +import sys from launchpadlib import launchpad import pytz @@ -81,7 +82,7 @@ def main(): parser.add_argument(dest='queries', help='path to query file') parser.add_argument('-o', dest='output', - help='output filename') + help='output filename. Omit for stdout') parser.add_argument('-q', dest='queue', help='limit results to a specific build queue') parser.add_argument('-c', '--conf', help="Elastic Recheck Configuration " @@ -197,9 +198,15 @@ def main(): key=lambda bug: -(bug['fails24'] * 100000 + bug['fails'])) jsondata['buglist'] = buglist - out = open(args.output, 'w') - out.write(json.dumps(jsondata)) - out.close() + if args.output: + out = open(args.output, 'w') + else: + out = sys.stdout + + try: + out.write(json.dumps(jsondata)) + finally: + out.close() if __name__ == "__main__":