Skip to content

Commit

Permalink
Progress bar updates as needed and shows TX and %.
Browse files Browse the repository at this point in the history
The progress bar now shows the transfer rate and percentage complete
instead of the source and destination.

The updating of the progress bar every loop was killing the CPU performance
and causing the Xorg process to go crazy. By only updating the progress bar
if the percent complete value changes stop this from happening.
  • Loading branch information
tbehan committed Feb 12, 2013
1 parent 3529f8d commit 488e557
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lib/mintstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def raw_write(self, source, target):
while gtk.events_pending():
gtk.main_iteration(True)
total_size = float(os.path.getsize(source))
old_size = 0.0
# Add launcher string, only when not root
launcher = ''
size=''
Expand All @@ -155,7 +156,11 @@ def raw_write(self, source, target):
else:
output = Popen(['/usr/bin/python', '/usr/lib/mintstick/raw_write.py','-s',source,'-t',target], shell=False, stdout=PIPE)
while output.stdout.readline():
size = output.stdout.readline().strip()
size_and_rate = output.stdout.readline().strip()
size_and_rate = size_and_rate.split()
size = size_and_rate[0]
if len(size_and_rate) > 1:
rate = float(size_and_rate[1])
try:
size = float(size)
flag = True
Expand All @@ -164,7 +169,11 @@ def raw_write(self, source, target):
while gtk.events_pending():
gtk.main_iteration(True)
if flag:
progress.set_fraction(size)
if round(size*1000) > old_size:
progress.set_fraction(size)
progress.set_text(_("%3.1f%% %s " % (float(size)*100,self.rate_fmt(rate))))
old_size = round(size*1000)

if size == 1.0:
self.logger(_('Image ')+source.split('/')[-1]+_(' successfully written to')+target)
self.success()
Expand All @@ -173,6 +182,13 @@ def raw_write(self, source, target):
self.emergency()
return False

def rate_fmt(self,num):
for x in ['bytes','KB','MB','GB']:
if num < 1024.0:
return "%3.1f%s/s" % (num, x)
num /= 1024.0
return "%3.1f%s/s" % (num, 'TB')

def success(self):
dialog = self.wTree.get_widget("success_dialog")
self.final_unsensitive()
Expand Down
7 changes: 5 additions & 2 deletions lib/raw_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from subprocess import Popen,PIPE,call,STDOUT
import os, sys
import getopt
import time

def raw_write(source, target):
bs = 1024
Expand All @@ -12,13 +13,15 @@ def raw_write(source, target):
total_size = float(os.path.getsize(source))
print total_size
output = open(target, 'wb')
start_time = time.time()
while True:
buffer = input.read(bs)
if len(buffer) == 0:
break
output.write(buffer)
size = size + bs
print size/total_size
elapsed_time = time.time() - start_time
print "%f %f" % (size/total_size,size/elapsed_time)

output.flush()
#os.fsync(output.fileno())
Expand Down Expand Up @@ -56,4 +59,4 @@ def main():
raw_write(source, target)

if __name__ == "__main__":
main()
main()

0 comments on commit 488e557

Please sign in to comment.