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 <iannucci@chromium.org>
Reviewed-by: smut <smut@google.com>
Commit-Queue: Sergiy Byelozyorov <sergiyb@chromium.org>
diff --git a/buildbucket.py b/buildbucket.py
index bb7d61a..09315e9 100755
--- a/buildbucket.py
+++ b/buildbucket.py
@@ -71,7 +71,10 @@
   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 @@
     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