-
Notifications
You must be signed in to change notification settings - Fork 20
/
print-summary
executable file
·51 lines (43 loc) · 1.53 KB
/
print-summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Print a textual representation of the summary file
#
# Copyright 2015 Colin Walters <[email protected]>
# 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))