From c3975e55e1465d9d9320ae67889f0b057c7d7ec3 Mon Sep 17 00:00:00 2001 From: Sergiy Byelozyorov Date: Mon, 9 Jul 2018 22:30:09 +0000 Subject: [PATCH] Allow using pipes to specify properties for buildbucket.py R=machenbach@chromium.org, smut@google.com Change-Id: Ibdad06fa32294c19347eb4f52322b050f45b6a01 Reviewed-on: https://chromium-review.googlesource.com/1127895 Reviewed-by: Robbie Iannucci Reviewed-by: smut Commit-Queue: Sergiy Byelozyorov --- buildbucket.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/buildbucket.py b/buildbucket.py index bb7d61afc..09315e9bf 100755 --- a/buildbucket.py +++ b/buildbucket.py @@ -71,7 +71,10 @@ def main(argv): put_parser.add_argument( '-p', '--properties', - help='A file to load a JSON dict of properties from.', + help=( + 'A file to load a JSON dict of properties from. Use "-" to pipe JSON ' + 'from another command.' + ), ) args = parser.parse_args() @@ -93,8 +96,13 @@ def main(argv): properties = {} if args.properties: try: - with open(args.properties) as fp: - properties.update(json.load(fp)) + # Allow using pipes to stream properties from another command, e.g. + # echo '{"foo": "bar", "baz": 42}' | buildbucket.py -p - + if args.properties == '-': + properties.update(json.load(sys.stdin)) + else: + with open(args.properties) as fp: + properties.update(json.load(fp)) except (TypeError, ValueError): sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties) raise