Skip to content

Commit

Permalink
* S3/Progress.py: Support for progress meter not starting in 0.
Browse files Browse the repository at this point in the history
git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@266 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
ludvigm committed Nov 25, 2008
1 parent a3f63be commit e42d440
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2008-11-24 Michal Ludvig <michal@logix.cz>

* s3/s3.py: improved retrying in send_request() and send_file()
* S3/Progress.py: Support for progress meter not starting in 0.
* S3/S3.py: improved retrying in send_request() and send_file()

2008-11-24 Michal Ludvig <michal@logix.cz>

Expand Down
14 changes: 10 additions & 4 deletions S3/Progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def __init__(self, label, total_size):
def new_file(self, label, total_size):
self.label = label
self.total_size = total_size
self.current_position = 0
# Set initial_position to something in the
# case we're not counting from 0. For instance
# when appending to a partially downloaded file.
# Setting initial_position will let the speed
# be computed right.
self.initial_position = 0
self.current_position = self.initial_position
self.time_start = datetime.datetime.now()
self.time_last = self.time_start
self.time_current = self.time_start
Expand Down Expand Up @@ -52,7 +58,7 @@ def display(self, new_file = False, done_message = None):
if print_size[1] != "": print_size[1] += "B"
timedelta = self.time_current - self.time_start
sec_elapsed = timedelta.days * 86400 + timedelta.seconds + float(timedelta.microseconds)/1000000.0
print_speed = formatSize(self.current_position / sec_elapsed, True, True)
print_speed = formatSize((self.current_position - self.initial_position) / sec_elapsed, True, True)
sys.stdout.write("100%% %s%s in %.2fs (%.2f %sB/s)\n" %
(print_size[0], print_size[1], sec_elapsed, print_speed[0], print_speed[1]))
sys.stdout.flush()
Expand Down Expand Up @@ -89,15 +95,15 @@ def display(self, new_file = False, done_message = None):
timedelta = self.time_current - self.time_start
sec_elapsed = timedelta.days * 86400 + timedelta.seconds + float(timedelta.microseconds)/1000000.0
if (sec_elapsed > 0):
print_speed = formatSize(self.current_position / sec_elapsed, True, True)
print_speed = formatSize((self.current_position - self.initial_position) / sec_elapsed, True, True)
else:
print_speed = (0, "")
sys.stdout.write(self.ANSI_restore_cursor_pos)
sys.stdout.write(self.ANSI_erase_to_eol)
sys.stdout.write("%(current)s of %(total)s %(percent)3d%% in %(elapsed)ds %(speed).2f %(speed_coeff)sB/s" % {
"current" : str(self.current_position).rjust(len(str(self.total_size))),
"total" : self.total_size,
"percent" : self.current_position * 100 / self.total_size,
"percent" : self.total_size and (self.current_position * 100 / self.total_size) or 0,
"elapsed" : sec_elapsed,
"speed" : print_speed[0],
"speed_coeff" : print_speed[1]
Expand Down

0 comments on commit e42d440

Please sign in to comment.