From 3f3d2975a8c534b8da79c4f25564a5ffffed8c67 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Tue, 29 Jul 2008 20:15:03 +0000 Subject: Fetch the total and print percentage svn path=/trunk/; revision=896 --- examples/gio/downloader.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'examples/gio/downloader.py') diff --git a/examples/gio/downloader.py b/examples/gio/downloader.py index b5d5bb9..9c41525 100644 --- a/examples/gio/downloader.py +++ b/examples/gio/downloader.py @@ -8,7 +8,8 @@ import gio class Downloader(object): def __init__(self, uri): - self.total = 0 + self.fetched = 0 + self.total = -1 self.uri = uri self.loop = None self.gfile = gio.File(self.uri) @@ -36,16 +37,20 @@ class Downloader(object): print 'ERROR: %s' % (e.message,) self.stop() return + info = gfile.query_info('standard::size') + self.total = info.get_attribute_uint64('standard::size') stream.read_async(4096, self.stream_read_callback) def data_read(self, data): if self.fd is None: self.fd = open(self.output, 'w') self.fd.write(data) - self.total += len(data) + self.fetched += len(data) + if self.total != -1: + print '%7.2f %%' % (self.fetched / float(self.total) * 100) def data_finished(self): - print '%d bytes read.' % (self.total,) + print '%d bytes read.' % (self.fetched,) self.fd.close() self.stop() -- cgit