summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2008-07-29 20:15:03 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-07-29 20:15:03 +0000
commit3f3d2975a8c534b8da79c4f25564a5ffffed8c67 (patch)
tree4aac288f70bd19e477633dd3462313582a940b20 /examples
parent59d3c6e08bb01da5bfc07b6e9d77fccb59566b8d (diff)
downloadpygobject-3f3d2975a8c534b8da79c4f25564a5ffffed8c67.tar.gz
pygobject-3f3d2975a8c534b8da79c4f25564a5ffffed8c67.tar.xz
pygobject-3f3d2975a8c534b8da79c4f25564a5ffffed8c67.zip
Fetch the total and print percentage
svn path=/trunk/; revision=896
Diffstat (limited to 'examples')
-rw-r--r--examples/gio/downloader.py11
1 files changed, 8 insertions, 3 deletions
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()