Skip to content

Commit

Permalink
print-summary: support URL path to summary file (ostreedev#13)
Browse files Browse the repository at this point in the history
* print-summary: support URL path to summary file

It's just more convenient to be able to just paste in the summary URL
directly without having to download it first.

* fixup! print-summary: support URL path to summary file

* fixup! print-summary: support URL path to summary file
  • Loading branch information
jlebon authored and cgwalters committed Jun 16, 2017
1 parent 6fd88de commit 389dda1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions print-summary
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from __future__ import print_function
import gi
gi.require_version('OSTree', '1.0')
from gi.repository import GLib, Gio, OSTree
import argparse, os, sys
import argparse, os, sys, requests

def fatal(msg):
print >>sys.stderr, msg
Expand All @@ -22,8 +22,16 @@ parser.add_argument("path", help="Summary path as file",
action='store')
args = parser.parse_args()

with open(args.path) as f:
bytedata = GLib.Bytes.new(f.read())
if args.path.startswith("http://") or args.path.startswith("https://"):
r = requests.get(args.path)
if r.status_code != requests.codes.ok:
print(r.headers)
print(r.text)
fatal("Couldn't fetch summary file")
bytedata = GLib.Bytes.new(r.content)
else:
with open(args.path) as f:
bytedata = GLib.Bytes.new(f.read())
typestr = GLib.VariantType.new('(a(s(taya{sv}))a{sv})')
d = GLib.Variant.new_from_bytes(typestr, bytedata, False)

Expand Down

0 comments on commit 389dda1

Please sign in to comment.