From ae86d50d68d717ac05bc64b432284474355f9093 Mon Sep 17 00:00:00 2001 From: Binyamin Sharet Date: Fri, 19 Jul 2013 03:20:07 +0300 Subject: [PATCH 1/3] Better file state indication --- speedtest-cli | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/speedtest-cli b/speedtest-cli index ff4ff15..11511b8 100755 --- a/speedtest-cli +++ b/speedtest-cli @@ -83,6 +83,13 @@ class FileGetter(threading.Thread): self.result = 0 +def show_progress( count, total ): + status = " %d out of %d files" % ( count, total ) + sys.stdout.write( status ) + if ( count < total ): + sys.stdout.write( '\b' * len( status ) ) + sys.stdout.flush( ) + def downloadSpeed(files, quiet=False): start = time.time() @@ -91,17 +98,16 @@ def downloadSpeed(files, quiet=False): thread = FileGetter(file, start) thread.start() q.put(thread, True) - if not quiet: - sys.stdout.write('.') - sys.stdout.flush() finished = [] def consumer(q, total_files): + show_progress( len( finished ), total_files ) while len(finished) < total_files: thread = q.get(True) thread.join() finished.append(thread.result) + show_progress( len( finished ), total_files ) thread.result = 0 q = Queue(6) @@ -149,17 +155,16 @@ def uploadSpeed(url, sizes, quiet=False): thread = FilePutter(url, start, size) thread.start() q.put(thread, True) - if not quiet: - sys.stdout.write('.') - sys.stdout.flush() finished = [] def consumer(q, total_sizes): + show_progress( len( finished ), total_sizes ) while len(finished) < total_sizes: thread = q.get(True) thread.join() finished.append(thread.result) + show_progress( len( finished ), total_sizes ) thread.result = 0 q = Queue(6) From 3d4e51aa1831d86e32ad716ed44fbbe75b80fed6 Mon Sep 17 00:00:00 2001 From: Binyamin Sharet Date: Fri, 19 Jul 2013 03:21:54 +0300 Subject: [PATCH 2/3] Fixed show_progress for quiet mode --- speedtest-cli | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/speedtest-cli b/speedtest-cli index 11511b8..0cdaa90 100755 --- a/speedtest-cli +++ b/speedtest-cli @@ -84,11 +84,12 @@ class FileGetter(threading.Thread): def show_progress( count, total ): - status = " %d out of %d files" % ( count, total ) - sys.stdout.write( status ) - if ( count < total ): - sys.stdout.write( '\b' * len( status ) ) - sys.stdout.flush( ) + if not quiet: + status = " %d out of %d files" % ( count, total ) + sys.stdout.write( status ) + if ( count < total ): + sys.stdout.write( '\b' * len( status ) ) + sys.stdout.flush( ) def downloadSpeed(files, quiet=False): start = time.time() From 57a1ba8390277722fc3ed5ca4ddb5756824030b6 Mon Sep 17 00:00:00 2001 From: Binyamin Sharet Date: Fri, 19 Jul 2013 03:30:04 +0300 Subject: [PATCH 3/3] Added [] --- speedtest-cli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speedtest-cli b/speedtest-cli index 0cdaa90..a5d216a 100755 --- a/speedtest-cli +++ b/speedtest-cli @@ -85,7 +85,7 @@ class FileGetter(threading.Thread): def show_progress( count, total ): if not quiet: - status = " %d out of %d files" % ( count, total ) + status = "[ %d out of %d files ]" % ( count, total ) sys.stdout.write( status ) if ( count < total ): sys.stdout.write( '\b' * len( status ) )