Skip to content

Commit

Permalink
Add --humanize and --summarize options for s3 ls
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhinton committed Jan 21, 2015
1 parent af614bf commit aedd554
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def _run_main(self, parsed_args, parsed_globals):
super(ListCommand, self)._run_main(parsed_args, parsed_globals)
self._empty_result = False
self._at_first_page = True
self.size_accumulator = 0
self.total_objects = 0
self.humanize = parsed_args.humanize
self._size_accumulator = 0
self._total_objects = 0
self._humanize = parsed_args.humanize
path = parsed_args.paths
if path.startswith('s3://'):
path = path[5:]
Expand Down Expand Up @@ -308,8 +308,8 @@ def _display_page(self, response_data, use_basename=True):
uni_print(print_str)
for content in contents:
last_mod_str = self._make_last_mod_str(content['LastModified'])
self.size_accumulator += int(content['Size'])
self.total_objects += 1
self._size_accumulator += int(content['Size'])
self._total_objects += 1
size_str = self._make_size_str(content['Size'])
if use_basename:
filename_components = content['Key'].split('/')
Expand Down Expand Up @@ -363,16 +363,16 @@ def _make_size_str(self, size):
"""
This function creates the size string when objects are being listed.
"""
size_str = humanize(size) if self.humanize else str(size)
size_str = humanize(size) if self._humanize else str(size)
return size_str.rjust(10, ' ')

def _print_summary(self):
"""
This function prints a summary of total objects and total bytes
"""
print_str = str(self.total_objects)
print_str = str(self._total_objects)
uni_print("\nTotal Objects: ".rjust(15, ' ') + print_str + "\n")
print_str = humanize(self.size_accumulator) if self.humanize else str(self.size_accumulator)
print_str = humanize(self._size_accumulator) if self._humanize else str(self._size_accumulator)
uni_print("Total Size: ".rjust(15, ' ') + print_str + "\n")

class WebsiteCommand(S3Command):
Expand Down

0 comments on commit aedd554

Please sign in to comment.