Skip to content

Commit

Permalink
PY3 support: ensure to use the adequate / sign for division with pyth…
Browse files Browse the repository at this point in the history
…on3.
  • Loading branch information
fviard committed Feb 10, 2017
1 parent be38a05 commit 6eae2c6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion S3/MultiPart.py
Expand Up @@ -91,7 +91,7 @@ def upload_all_parts(self, extra_label=''):

if filename != "<stdin>":
size_left = file_size = os.stat(deunicodise(filename))[ST_SIZE]
nr_parts = file_size / self.chunk_size + (file_size % self.chunk_size and 1)
nr_parts = file_size // self.chunk_size + (file_size % self.chunk_size and 1)
debug("MultiPart: Uploading %s in %d parts" % (filename, nr_parts))
else:
debug("MultiPart: Uploading from %s" % filename)
Expand Down
14 changes: 8 additions & 6 deletions S3/Progress.py
Expand Up @@ -6,7 +6,7 @@
## License: GPL Version 2
## Copyright: TGRMN Software and contributors

from __future__ import absolute_import
from __future__ import absolute_import, division

import sys
import datetime
Expand Down Expand Up @@ -77,16 +77,18 @@ def display(self, new_file = False, done_message = None):
print_size = S3.Utils.formatSize(self.current_position, True)
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
sec_elapsed = timedelta.days * 86400 + timedelta.seconds + float(timedelta.microseconds) / 1000000.0
print_speed = S3.Utils.formatSize((self.current_position - self.initial_position) / sec_elapsed, True, True)
self._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]))
self._stdout.flush()
return

rel_position = self.current_position * 100 / self.total_size
rel_position = (self.current_position * 100) // self.total_size
if rel_position >= self.last_milestone:
self.last_milestone = (int(rel_position) / 5) * 5
# Move by increments of 5.
# NOTE: to check: Looks like to not do what is looks like to be designed to do
self.last_milestone = (rel_position // 5) * 5
self._stdout.write("%d%% ", self.last_milestone)
self._stdout.flush()
return
Expand Down Expand Up @@ -127,7 +129,7 @@ def display(self, new_file = False, done_message = None):
self._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.total_size and (self.current_position * 100 / self.total_size) or 0,
"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 Expand Up @@ -164,7 +166,7 @@ def display(self, new_file = False, done_message = None):
output = " %(current)s of %(total)s %(percent)3d%% in %(elapsed)4ds %(speed)7.2f %(speed_coeff)sB/s" % {
"current" : str(self.current_position).rjust(len(str(self.total_size))),
"total" : self.total_size,
"percent" : self.total_size and (self.current_position * 100 / self.total_size) or 0,
"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
4 changes: 2 additions & 2 deletions S3/S3.py
Expand Up @@ -6,7 +6,7 @@
## License: GPL Version 2
## Copyright: TGRMN Software and contributors

from __future__ import absolute_import
from __future__ import absolute_import, division

import sys
import os
Expand Down Expand Up @@ -1605,7 +1605,7 @@ def recv_file(self, request, stream, labels, start_position = 0, retries = _max_
#throttle
if self.config.limitrate > 0:
real_duration = time.time() - start_time
expected_duration = float(this_chunk)/self.config.limitrate
expected_duration = float(this_chunk) / self.config.limitrate
if expected_duration > real_duration:
time.sleep(expected_duration - real_duration)

Expand Down
2 changes: 1 addition & 1 deletion S3/Utils.py
Expand Up @@ -6,7 +6,7 @@
## License: GPL Version 2
## Copyright: TGRMN Software and contributors

from __future__ import absolute_import
from __future__ import absolute_import, division

import os
import sys
Expand Down
8 changes: 4 additions & 4 deletions s3cmd
Expand Up @@ -19,7 +19,7 @@
## GNU General Public License for more details.
## --------------------------------------------------------------------

from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, division

import sys

Expand Down Expand Up @@ -1105,7 +1105,7 @@ def cmd_sync_remote2remote(args):
stats_info.files_deleted = deleted_count

total_elapsed = max(1.0, time.time() - timestamp_start)
outstr = "Done. Copied %d files in %0.1f seconds, %0.2f files/s." % (total_files_copied, total_elapsed, seq/total_elapsed)
outstr = "Done. Copied %d files in %0.1f seconds, %0.2f files/s." % (total_files_copied, total_elapsed, seq / total_elapsed)
if cfg.stats:
outstr += stats_info.format_output()
output(outstr)
Expand Down Expand Up @@ -1451,7 +1451,7 @@ def cmd_sync_remote2local(args):
deleted_count, deleted_size = _do_deletes(local_list)

total_elapsed = max(1.0, time.time() - timestamp_start)
speed_fmt = formatSize(size_transferred/total_elapsed, human_readable = True, floating_point = True)
speed_fmt = formatSize(size_transferred / total_elapsed, human_readable = True, floating_point = True)

stats_info.files = orig_remote_count
stats_info.size = remote_total_size
Expand Down Expand Up @@ -1747,7 +1747,7 @@ def cmd_sync_local2remote(args):
if cfg.delete_removed and cfg.delete_after and remote_list:
subcmd_batch_del(remote_list = remote_list)
total_elapsed = max(1.0, time.time() - timestamp_start)
total_speed = total_elapsed and size_transferred/total_elapsed or 0.0
total_speed = total_elapsed and size_transferred / total_elapsed or 0.0
speed_fmt = formatSize(total_speed, human_readable = True, floating_point = True)


Expand Down

0 comments on commit 6eae2c6

Please sign in to comment.