gget r71 - trunk/gget



Author: johans
Date: Mon Aug 11 20:02:43 2008
New Revision: 71
URL: http://svn.gnome.org/viewvc/gget?rev=71&view=rev

Log:
Started working on ETA information.

Modified:
   trunk/gget/MainWindow.py
   trunk/gget/Utils.py

Modified: trunk/gget/MainWindow.py
==============================================================================
--- trunk/gget/MainWindow.py	(original)
+++ trunk/gget/MainWindow.py	Mon Aug 11 20:02:43 2008
@@ -295,7 +295,8 @@
     def __eta_cell_data_func(self, column, cell, model, iter):
         """Data function for estemated time of arrival (ETA) of downloads."""
         download = model.get_value(iter, 0)
-        cell.props.text = "N/A"
+        size = download.total_size - download.current_size
+        cell.props.text = Utils.get_readable_eta(size, download.bit_rate)
 
     def __connect_widgets(self):
         """Connect to the widget signals we are interested in."""

Modified: trunk/gget/Utils.py
==============================================================================
--- trunk/gget/Utils.py	(original)
+++ trunk/gget/Utils.py	Mon Aug 11 20:02:43 2008
@@ -22,6 +22,8 @@
 import os
 import os.path
 import time
+from datetime import timedelta
+from gettext import gettext as _
 
 import gnomevfs
 import dbus
@@ -77,6 +79,32 @@
         return "%.2f MB/s" % (float(bitrate) / float(1000))
     return "%.0f kB/s" % bitrate
 
+def get_readable_eta(size, bitrate):
+    seconds = 0
+    try:
+        seconds = int(size / bitrate / 1024)
+    except ZeroDivisionError:
+        seconds = 0
+
+    return secs_to_human(seconds)
+
+def secs_to_human(secs):
+    days = secs / 86400
+    secs %= 86400
+    hours = secs / 3600
+    secs %= 3600
+    mins = secs / 60
+    secs %= 60
+
+    if days:
+        return "%dd %dh %dm %ds" % (days, hours, mins, secs)
+    elif hours:
+        return "%dh %dm %ds" % (hours, mins, secs)
+    elif mins:
+        return "%dm %ds" % (mins, secs)
+    else:
+        return "%ds" % secs
+
 def debug_print(message):
     config = Configuration()
     if config.debug:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]