diff options
author | Johan Dahlin <johan@src.gnome.org> | 2008-07-29 20:15:03 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-07-29 20:15:03 +0000 |
commit | 3f3d2975a8c534b8da79c4f25564a5ffffed8c67 (patch) | |
tree | 4aac288f70bd19e477633dd3462313582a940b20 | |
parent | 59d3c6e08bb01da5bfc07b6e9d77fccb59566b8d (diff) | |
download | pygobject-3f3d2975a8c534b8da79c4f25564a5ffffed8c67.tar.gz |
Fetch the total and print percentage
svn path=/trunk/; revision=896
-rw-r--r-- | examples/gio/downloader.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/examples/gio/downloader.py b/examples/gio/downloader.py index b5d5bb99..9c41525b 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() |