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>
changes/95/1127895/5
Sergiy Byelozyorov 7 years ago committed by Commit Bot
parent 92745a5b0e
commit c3975e55e1

@ -71,7 +71,10 @@ def main(argv):
put_parser.add_argument( put_parser.add_argument(
'-p', '-p',
'--properties', '--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() args = parser.parse_args()
@ -93,6 +96,11 @@ def main(argv):
properties = {} properties = {}
if args.properties: if args.properties:
try: try:
# 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: with open(args.properties) as fp:
properties.update(json.load(fp)) properties.update(json.load(fp))
except (TypeError, ValueError): except (TypeError, ValueError):

Loading…
Cancel
Save