Browse code

* S3/Progress.py: Support for progress meter not starting in 0.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@266 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2008/11/25 14:12:43
Showing 2 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 2008-11-24  Michal Ludvig  <michal@logix.cz>
2 2
 
3
-	* s3/s3.py: improved retrying in send_request() and send_file()
3
+	* S3/Progress.py: Support for progress meter not starting in 0.
4
+	* S3/S3.py: improved retrying in send_request() and send_file()
4 5
 
5 6
 2008-11-24  Michal Ludvig  <michal@logix.cz>
6 7
 
... ...
@@ -14,7 +14,13 @@ class Progress(object):
14 14
 	def new_file(self, label, total_size):
15 15
 		self.label = label
16 16
 		self.total_size = total_size
17
-		self.current_position = 0
17
+		# Set initial_position to something in the
18
+		# case we're not counting from 0. For instance
19
+		# when appending to a partially downloaded file.
20
+		# Setting initial_position will let the speed
21
+		# be computed right.
22
+		self.initial_position = 0
23
+		self.current_position = self.initial_position
18 24
 		self.time_start = datetime.datetime.now()
19 25
 		self.time_last = self.time_start
20 26
 		self.time_current = self.time_start
... ...
@@ -52,7 +58,7 @@ class Progress(object):
52 52
 			if print_size[1] != "": print_size[1] += "B"
53 53
 			timedelta = self.time_current - self.time_start
54 54
 			sec_elapsed = timedelta.days * 86400 + timedelta.seconds + float(timedelta.microseconds)/1000000.0
55
-			print_speed = formatSize(self.current_position / sec_elapsed, True, True)
55
+			print_speed = formatSize((self.current_position - self.initial_position) / sec_elapsed, True, True)
56 56
 			sys.stdout.write("100%%  %s%s in %.2fs (%.2f %sB/s)\n" % 
57 57
 				(print_size[0], print_size[1], sec_elapsed, print_speed[0], print_speed[1]))
58 58
 			sys.stdout.flush()
... ...
@@ -89,7 +95,7 @@ class ProgressANSI(Progress):
89 89
 		timedelta = self.time_current - self.time_start
90 90
 		sec_elapsed = timedelta.days * 86400 + timedelta.seconds + float(timedelta.microseconds)/1000000.0
91 91
 		if (sec_elapsed > 0):
92
-			print_speed = formatSize(self.current_position / sec_elapsed, True, True)
92
+			print_speed = formatSize((self.current_position - self.initial_position) / sec_elapsed, True, True)
93 93
 		else:
94 94
 			print_speed = (0, "")
95 95
 		sys.stdout.write(self.ANSI_restore_cursor_pos)
... ...
@@ -97,7 +103,7 @@ class ProgressANSI(Progress):
97 97
 		sys.stdout.write("%(current)s of %(total)s   %(percent)3d%% in %(elapsed)ds  %(speed).2f %(speed_coeff)sB/s" % {
98 98
 			"current" : str(self.current_position).rjust(len(str(self.total_size))),
99 99
 			"total" : self.total_size,
100
-			"percent" : self.current_position * 100 / self.total_size,
100
+			"percent" : self.total_size and (self.current_position * 100 / self.total_size) or 0,
101 101
 			"elapsed" : sec_elapsed,
102 102
 			"speed" : print_speed[0],
103 103
 			"speed_coeff" : print_speed[1]