I've done a smallish patch to the progress bars in urlgrabber, they help a couple of problems I've seen:
1. Long filenames can't be read, even after they've downloaded. 2. It's not easy to see your "average download speed". 3. Add hours in, because large numbers of minutes suck. 4. For download times of less than a minute the extra "00:" just clutters up the view (dito. less than an hour). ...now I've currently got it split into two versions, one which sacrifices some of #1 but gives #2 and one which does. And I added some test functions if you run the progress module, so you can see it in action. So first, this tries to do "solve" all four of the above: (1/10): sm-1.0.0-1.fc8.i386.rpm | 90 B/s | 1.0 kB 11 (2/10): s-1.0.1-1.fc8.i386.rpm | 163 B/s | 9.8 kB 01:01 (3/10): m-1.0.1-2.fc8.i386.rpm | 1.1 kB/s | 9.8 kB 08 (4/10): large-file-name-Foo-11.8.7-4.5.6.1.fc | 9.4 kB/s | 977 kB 01:43 (5/10): large-file-name-Foo2-11.8.7-4.5.6.2.f | 49 kB/s | 977 kB 20 (6/10): large-file-name-Foo3-11.8.7-4.5.6.3.f | 391 kB/s | 977 kB 02 (7/10): large-file-name-Foo4-10.8.7-4.5.6.1.f | 1.0 kB/s | 9.8 kB 10 (8/10): large-file-name-Foo5-10.8.7-4.5.6.2.f | 2.0 kB/s | 9.8 kB 05 (9/10): large-file-name-Foo6-10.8.7-4.5.6.3.f | 3.9 kB/s | 9.8 kB 02 (10/10): large-file-name- 0% | | 20 B/s | 8.0 kB 13:46:31 ETA ...and here's the one that doesn't show the B/s data in current or done downloads (but still has the minute/blank changes): (1/10): sm-1.0.0-1.fc8.i386.rpm | 1.0 kB 11 (2/10): s-1.0.1-1.fc8.i386.rpm | 9.8 kB 01:01 (3/10): m-1.0.1-2.fc8.i386.rpm | 9.8 kB 08 (4/10): large-file-name-Foo-11.8.7-4.5.6.1.fc8.x86_64.rp | 977 kB 01:43 (5/10): large-file-name-Foo2-11.8.7-4.5.6.2.fc8.x86_64.r | 977 kB 20 (6/10): large-file-name-Foo3-11.8.7-4.5.6.3.fc8.x86_64.r | 977 kB 02 (7/10): large-file-name-Foo4-10.8.7-4.5.6.1.fc8.x86_64.r | 9.8 kB 10 (8/10): large-file-name-Foo5-10.8.7-4.5.6.2.fc8.x86_64.r | 9.8 kB 05 (9/10): large-file-name-Foo6-10.8.7-4.5.6.3.fc8.x86_64.r | 9.8 kB 02 (10/10): large-file-name- 0% | | 380 B 13:34:48 ETA ...so what does everyone think? . I assume noone cares about dropping the dead space from the bar and percentage? . What about including the B/s, is that worth killing 11 bytes from the name and/or bar? They are separate, so we could just do it in one or the other (they are also slightly different, in the update() it is the rolling average in end() it is the full B/s for the file). . What about dropping the minutes when they are "00:"? . What about including the hours when the minutes are >=60? If yes, I assume we want to drop the hours when they are == "00:"? ...the patch, against current urlgrabber CVS, is attached and available from: http://people.redhat.com/jantill/python/urlgrabber.patch -- James Antill <[EMAIL PROTECTED]> Red Hat
Index: urlgrabber/progress.py
===================================================================
RCS file: /home/groups/urlgrabber/cvs-root/urlgrabber/urlgrabber/progress.py,v
retrieving revision 1.7
diff -u -r1.7 progress.py
--- urlgrabber/progress.py 19 Aug 2005 21:59:07 -0000 1.7
+++ urlgrabber/progress.py 29 Jan 2008 18:37:28 -0000
@@ -102,18 +102,24 @@
(text, fread, fetime)
else:
rtime = self.re.remaining_time()
- frtime = format_time(rtime)
+ frtime = format_time(rtime, 1, True)
frac = self.re.fraction_read()
- bar = '='*int(25 * frac)
- out = '\r%-25.25s %3i%% |%-25.25s| %5sB %8s ETA ' % \
- (text, frac*100, bar, fread, frtime)
+ if False:
+ bar = '='*int(25 * frac)
+ out = '\r%-25.25s %3i%% |%-25.25s| %5sB %8s ETA ' % \
+ (text, frac*100, bar, fread, frtime)
+ else:
+ bar = '='*int(14 * frac)
+ ave_dl = format_number(self.re.average_rate())
+ out = '\r%-25.25s %3i%% |%-14.14s| %5sB/s | %5sB %8s ETA ' % \
+ (text, frac*100, bar, ave_dl, fread, frtime)
self.fo.write(out)
self.fo.flush()
def _do_end(self, amount_read, now=None):
- total_time = format_time(self.re.elapsed_time())
+ total_time = format_time(self.re.elapsed_time(), 1, True)
total_size = format_number(amount_read)
if self.text is not None:
text = self.text
@@ -123,9 +129,15 @@
out = '\r%-60.60s %5sB %s ' % \
(text, total_size, total_time)
else:
- bar = '='*25
- out = '\r%-25.25s %3i%% |%-25.25s| %5sB %8s ' % \
- (text, 100, bar, total_size, total_time)
+ bar = ' '*25
+ if False:
+ out = '\r%-56.56s | %5sB %8s ' % \
+ (text, total_size, total_time)
+ else:
+ ave_dl = format_number(amount_read / self.re.elapsed_time())
+ out = '\r%-45.45s | %5sB/s | %5sB %8s ' % \
+ (text, ave_dl, total_size, total_time)
+
self.fo.write(out + '\n')
self.fo.flush()
@@ -475,7 +487,7 @@
return float(int(rt) >> shift << shift)
-def format_time(seconds, use_hours=0):
+def format_time(seconds, use_hours=0, blank_expand=False):
if seconds is None or seconds < 0:
if use_hours: return '--:--:--'
else: return '--:--'
@@ -486,9 +498,11 @@
if use_hours:
hours = minutes / 60
minutes = minutes % 60
- return '%02i:%02i:%02i' % (hours, minutes, seconds)
- else:
+ if not blank_expand or hours >= 1:
+ return '%02i:%02i:%02i' % (hours, minutes, seconds)
+ if not blank_expand or minutes >= 1 :
return '%02i:%02i' % (minutes, seconds)
+ return '%02i' % (seconds)
def format_number(number, SI=0, space=' '):
"""Turn numbers into human-readable metric-like numbers"""
@@ -528,3 +542,47 @@
format = '%.0f%s%s'
return(format % (float(number or 0), space, symbols[depth]))
+
+def _tst(fn, cur, tot, beg, size, *args):
+ tm = TextMeter()
+ text = "(%d/%d): %s" % (cur, tot, fn)
+ tm.start(fn, "http://www.example.com/path/to/fn/" + fn, fn, size, text=text)
+ num = beg
+ off = 0
+ for (inc, delay) in args:
+ off += 1
+ while num < ((size * off) / len(args)):
+ num += inc
+ tm.update(num)
+ time.sleep(delay)
+ tm.end(size)
+
+if __name__ == "__main__":
+ # (1/2): subversion-1.4.4-7.x86_64.rpm 2.4 MB / 85 kB/s 00:28
+ # (2/2): mercurial-0.9.5-6.fc8.x86_64.rpm 924 kB / 106 kB/s 00:08
+
+ _tst("sm-1.0.0-1.fc8.i386.rpm", 1, 10, 0, 1000,
+ (10, 0.2), (10, 0.1), (100, 0.25))
+ _tst("s-1.0.1-1.fc8.i386.rpm", 2, 10, 0, 10000,
+ (10, 0.2), (100, 0.1), (100, 0.1), (100, 0.25))
+ _tst("m-1.0.1-2.fc8.i386.rpm", 3, 10, 5000, 10000,
+ (10, 0.2), (100, 0.1), (100, 0.1), (100, 0.25))
+ _tst("large-file-name-Foo-11.8.7-4.5.6.1.fc8.x86_64.rpm", 4, 10, 0, 1000000,
+ (1000, 0.2), (1000, 0.1), (10000, 0.1))
+ _tst("large-file-name-Foo2-11.8.7-4.5.6.2.fc8.x86_64.rpm", 5, 10,
+ 500001, 1000000, (1000, 0.2), (1000, 0.1), (10000, 0.1))
+ _tst("large-file-name-Foo3-11.8.7-4.5.6.3.fc8.x86_64.rpm", 6, 10,
+ 750002, 1000000, (1000, 0.2), (1000, 0.1), (10000, 0.1))
+ _tst("large-file-name-Foo4-10.8.7-4.5.6.1.fc8.x86_64.rpm", 7, 10, 0, 10000,
+ (100, 0.1))
+ _tst("large-file-name-Foo5-10.8.7-4.5.6.2.fc8.x86_64.rpm", 8, 10,
+ 5001, 10000, (100, 0.1))
+ _tst("large-file-name-Foo6-10.8.7-4.5.6.3.fc8.x86_64.rpm", 9, 10,
+ 7502, 10000, (100, 0.1))
+ _tst("large-file-name-Foox-9.8.7-4.5.6.1.fc8.x86_64.rpm", 10, 10,
+ 0, 1000000, (10, 0.5),
+ (10000, 0.1), (10000, 0.1), (10000, 0.1), (10000, 0.1),
+ (10000, 0.1), (10000, 0.1), (10000, 0.1), (10000, 0.1),
+ (10000, 0.1), (10000, 0.1), (10000, 0.1), (10000, 0.1),
+ (10000, 0.1), (10000, 0.1), (10000, 0.1), (10000, 0.1),
+ (10000, 0.1), (10000, 0.25))
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Yum-devel mailing list [email protected] https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
