@@ -531,8 +531,7 @@ def st_download(parser, args, output_manager, return_parser=False):
531531
532532def st_list (parser , args , output_manager , return_parser = False ):
533533
534- def _print_stats (options , stats , human ):
535- total_count = total_bytes = 0
534+ def _print_stats (options , stats , human , totals ):
536535 container = stats .get ("container" , None )
537536 for item in stats ["listing" ]:
538537 item_name = item .get ('name' )
@@ -543,7 +542,7 @@ def _print_stats(options, stats, human):
543542 item_bytes = item .get ('bytes' )
544543 byte_str = prt_bytes (item_bytes , human )
545544 count = item .get ('count' )
546- total_count += count
545+ totals [ 'count' ] += count
547546 try :
548547 meta = item .get ('meta' )
549548 utc = gmtime (float (meta .get ('x-timestamp' )))
@@ -578,17 +577,7 @@ def _print_stats(options, stats, human):
578577 output_manager .print_msg (
579578 "%s %10s %8s %24s %s" ,
580579 byte_str , date , xtime , content_type , item_name )
581- total_bytes += item_bytes
582-
583- # report totals
584- if options ['long' ] or human :
585- if not container :
586- output_manager .print_msg (
587- "%12s %s" , prt_bytes (total_count , True ),
588- prt_bytes (total_bytes , human ))
589- else :
590- output_manager .print_msg (
591- prt_bytes (total_bytes , human ))
580+ totals ['bytes' ] += item_bytes
592581
593582 parser .add_argument (
594583 '-l' , '--long' , dest = 'long' , action = 'store_true' , default = False ,
@@ -642,6 +631,7 @@ def _print_stats(options, stats, human):
642631 try :
643632 if not args :
644633 stats_parts_gen = swift .list ()
634+ container = None
645635 else :
646636 container = args [0 ]
647637 args = args [1 :]
@@ -667,12 +657,24 @@ def listing(stats_parts_gen=stats_parts_gen):
667657 sort_keys = True , indent = 2 )
668658 output_manager .print_msg ('' )
669659 return
660+
661+ totals = {'count' : 0 , 'bytes' : 0 }
670662 for stats in stats_parts_gen :
671663 if stats ["success" ]:
672- _print_stats (options , stats , human )
664+ _print_stats (options , stats , human , totals )
673665 else :
674666 raise stats ["error" ]
675667
668+ # report totals
669+ if options ['long' ] or human :
670+ if container is None :
671+ output_manager .print_msg (
672+ "%12s %s" , prt_bytes (totals ['count' ], True ),
673+ prt_bytes (totals ['bytes' ], human ))
674+ else :
675+ output_manager .print_msg (
676+ prt_bytes (totals ['bytes' ], human ))
677+
676678 except SwiftError as e :
677679 output_manager .error (e .value )
678680
0 commit comments