[nanny] Download progress
- From: Roberto Majadas <telemaco src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nanny] Download progress
- Date: Sun, 23 Jan 2011 18:08:19 +0000 (UTC)
commit 6b81dd668cc33040a4a99d5f403473f722a702aa
Author: Roberto Majadas <roberto majadas openshine com>
Date: Mon Jan 17 13:29:36 2011 +0100
Download progress
client/gnome/admin/src/ConfigureProxyDialog.py | 2 +-
daemon/src/FilterManager.py | 48 +++++++++++++++++++++---
2 files changed, 43 insertions(+), 7 deletions(-)
---
diff --git a/client/gnome/admin/src/ConfigureProxyDialog.py b/client/gnome/admin/src/ConfigureProxyDialog.py
index b0bec63..2aaabb8 100644
--- a/client/gnome/admin/src/ConfigureProxyDialog.py
+++ b/client/gnome/admin/src/ConfigureProxyDialog.py
@@ -196,7 +196,7 @@ class ConfigureProxyDialog (gtk.Dialog):
if metadata["status"] == 1:
filter_description = "<b>" + _("There is an update available") + "</b>"
if metadata["status"] == 2:
- filter_description = _("Downloading information, please wait")
+ filter_description = _("Downloading information (%s%%)" % metadata["progress"])
elif metadata["status"] == 3:
filter_description = _("Installing blacklist (%s%%)" % metadata["progress"])
elif metadata["status"] == 4:
diff --git a/daemon/src/FilterManager.py b/daemon/src/FilterManager.py
index ebbea78..5850395 100644
--- a/daemon/src/FilterManager.py
+++ b/daemon/src/FilterManager.py
@@ -277,8 +277,15 @@ class FilterManager (gobject.GObject) :
if pkg_id in fm.db_pools.keys():
db = fm.db_pools.pop(pkg_id)
db.close()
+
+ try:
+ pkg_info = json.load(urllib2.urlopen(url))
+ except:
+ fm.pkg_filters_conf.pop(pkg_id)
+ threads.blockingCallFromThread(reactor,
+ fm._save_pkg_filters_conf)
+ return
- pkg_info = json.load(urllib2.urlopen(url))
fm.pkg_filters_conf[pkg_id]["pkg_info"] = pkg_info
base_filename = pkg_info["base"]
@@ -290,14 +297,28 @@ class FilterManager (gobject.GObject) :
if os.path.exists(dest_file):
os.unlink(dest_file)
-
+
if os.path.exists(dest_db):
os.unlink(dest_db)
df = open(dest_file, "wb")
- df.write(urllib2.urlopen(base_url).read())
+ url_x = urllib2.urlopen(base_url)
+ fm.pkg_filters_conf[pkg_id]["progress"] = 0
+
+ total_len = int(url_x.info().getheaders("Content-Length")[0])
+ downl_len = 0
+
+ while True:
+ x = url_x.read(1024)
+ if x != '' :
+ df.write(x)
+ downl_len += len(x)
+ fm.pkg_filters_conf[pkg_id]["progress"] = (downl_len * 100) / total_len
+ else:
+ break
+
df.close()
-
+
df_uc_c = bz2.BZ2File(dest_file, "r")
lines_counted = 0
for line in df_uc_c.readlines():
@@ -308,7 +329,7 @@ class FilterManager (gobject.GObject) :
db_conn = sqlite3.connect(dest_db)
sql=''
-
+
fm.pkg_filters_conf[pkg_id]["status"]=PKG_STATUS_INSTALLING
fm.pkg_filters_conf[pkg_id]["progress"] = 0
@@ -387,6 +408,7 @@ class FilterManager (gobject.GObject) :
try:
fm.pkg_filters_conf[pkg_id]["status"] = PKG_STATUS_DOWNLOADING
+ fm.pkg_filters_conf[pkg_id]["progress"] = 0
url = fm.pkg_filters_conf[pkg_id]["update_url"]
pkg_info = json.load(urllib2.urlopen(url))
@@ -425,6 +447,9 @@ class FilterManager (gobject.GObject) :
dest_patch_fd = open(dest_patch, "w")
lines_counted = 0
+ total_diffs = len(patches)
+ downl_diffs = 0
+
for diff_filename, diff_url in patches :
dest_file = os.path.join(NANNY_DAEMON_BLACKLISTS_DIR,
"%s-%s" % (pkg_id, diff_filename))
@@ -433,7 +458,15 @@ class FilterManager (gobject.GObject) :
os.unlink(dest_file)
df = open(dest_file, "wb")
- df.write(urllib2.urlopen(diff_url).read())
+ url_x = urllib2.urlopen(diff_url)
+
+ while True:
+ x = url_x.read(1024)
+ if x != '' :
+ df.write(x)
+ else:
+ break
+
df.close()
df_uc = bz2.BZ2File(dest_file, "r")
@@ -444,6 +477,9 @@ class FilterManager (gobject.GObject) :
df_uc.close()
os.unlink(dest_file)
+
+ downl_diffs += 1
+ fm.pkg_filters_conf[pkg_id]["progress"] = (downl_diffs * 100) / total_diffs
dest_patch_fd.close()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]