1
0
mirror of https://github.com/ostreedev/ostree-releng-scripts.git synced 2026-02-05 09:45:02 +01:00
Files
ostree-releng-scripts/print-summary
Jonathan Lebon 389dda1d8c print-summary: support URL path to summary file (#13)
* 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
2017-06-16 17:22:39 -04:00

52 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Print a textual representation of the summary file
#
# Copyright 2015 Colin Walters <walters@verbum.org>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
from __future__ import print_function
import gi
gi.require_version('OSTree', '1.0')
from gi.repository import GLib, Gio, OSTree
import argparse, os, sys, requests
def fatal(msg):
print >>sys.stderr, msg
sys.exit(1)
parser = argparse.ArgumentParser(prog="print-summary")
parser.add_argument("path", help="Summary path as file",
action='store')
args = parser.parse_args()
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)
refs, other = d
for refname, refdata in refs:
size=refdata[0]
csumarray=refdata[1]
if len(csumarray) != 32:
print("warning: invalid csum for ref {}", refname)
continue
csum = ''.join(['%x' % v for v in csumarray])
print("{}{} (size={})".format(refname, csum, size))
deltas = other.get('ostree.static-deltas', {})
for (deltaname, csum) in deltas.iteritems():
print("delta: {}".format(deltaname))