On Thu, Jul 23, 2015 at 03:57:27PM +0000, Eren Yagdiran wrote: > From: Daniel P Berrange <berrange@xxxxxxxxxx> > > virt-sandbox-image.py is a python script that lets you download Docker > images easily. It is a proof of concept code and consumes Docker Rest API. > --- > po/POTFILES.in | 1 + > virt-sandbox-image/virt-sandbox-image.py | 397 +++++++++++++++++++++++++++++++ > 2 files changed, 398 insertions(+) > create mode 100644 virt-sandbox-image/virt-sandbox-image.py > > diff --git a/po/POTFILES.in b/po/POTFILES.in > index afcb050..7204112 100644 > --- a/po/POTFILES.in > +++ b/po/POTFILES.in > @@ -11,3 +11,4 @@ libvirt-sandbox/libvirt-sandbox-context-interactive.c > libvirt-sandbox/libvirt-sandbox-init-common.c > libvirt-sandbox/libvirt-sandbox-rpcpacket.c > libvirt-sandbox/libvirt-sandbox-util.c > +virt-sandbox-image/virt-sandbox-image.py This should really live in the 'bin/' directory and not have any .py suffix > +def get_url(server, path, headers): > + url = "https://" + server + path > + debug(" Fetching %s..." % url) > + There is trailng whitespace here that can be chomped > +def save_data(server, path, headers, dest, checksum=None, datalen=None): > + try: > + res = get_url(server, path, headers) > + > + csum = None > + if checksum is not None: > + csum = hashlib.sha256() > + > + pattern = [".", "o", "O", "o"] > + patternIndex = 0 > + donelen = 0 > + > + with open(dest, "w") as f: > + while 1: > + buf = res.read(1024*64) > + if not buf: > + break > + if csum is not None: > + csum.update(buf) > + f.write(buf) > + > + if datalen is not None: > + donelen = donelen + len(buf) > + debug("\x1b[s%s (%5d Kb of %5d Kb)\x1b8" % ( > + pattern[patternIndex], (donelen/1024), (datalen/1024) > + )) > + patternIndex = (patternIndex + 1) % 4 > + > + debug("\x1b[K") > + if csum is not None: > + csumstr = "sha256:" + csum.hexdigest() > + if csumstr != checksum: > + debug("FAIL checksum '%s' does not match '%s'" % (csumstr, checksum)) > + os.remove(dest) > + raise IOError("Checksum '%s' for data does not match '%s'" % (csumstr, checksum)) > + And here and a few other places. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list