parameters: (apk_filename, min_pak_resource_size)
docstring: Print sizes of all resources in all pak files in |apk_filename|.
docstring_summary: Print sizes of all resources in all pak files in |apk_filename|.
docstring_tokens: Print sizes of all resources in all pak files in |apk_filename| .
function: def PrintPakAnalysis(apk_filename, min_pak_resource_size):
    """Print sizes of all resources in all pak files in |apk_filename|."""
    print
    print 'Analyzing pak files in %s...' % apk_filename
  
    # A structure for holding details about a pak file.
    Pak = collections.namedtuple(
        'Pak', ['filename', 'compress_size', 'file_size', 'resources'])
  
    # Build a list of Pak objets for each pak file.
    paks = []
    apk = zipfile.ZipFile(apk_filename, 'r')
    try:
      for i in (x for x in apk.infolist() if IsPakFileName(x.filename)):
        with tempfile.NamedTemporaryFile() as f:
          f.write(apk.read(i.filename))
          f.flush()
          paks.append(Pak(i.filename, i.compress_size, i.file_size,
                          data_pack.DataPack.ReadDataPack(f.name).resources))
    finally:
      apk.close()
  
    # Output the overall pak file summary.
    total_files = len(paks)
    total_compress_size = sum(pak.compress_size for pak in paks)
    total_file_size = sum(pak.file_size for pak in paks)
    print 'Total pak files: %d' % total_files
    print 'Total compressed size: %s' % _FormatBytes(total_compress_size)
    print 'Total uncompressed size: %s' % _FormatBytes(total_file_size)
    print
  
    # Output the table of details about all pak files.
    print '%25s%11s%21s%21s' % (
        'FILENAME', 'RESOURCES', 'COMPRESSED SIZE', 'UNCOMPRESSED SIZE')
    for pak in sorted(paks, key=operator.attrgetter('file_size'), reverse=True):
      print '%25s %10s %12s %6.2f%% %12s %6.2f%%' % (
          pak.filename,
          len(pak.resources),
          _FormatBytes(pak.compress_size),
          100.0 * pak.compress_size / total_compress_size,
          _FormatBytes(pak.file_size),
          100.0 * pak.file_size / total_file_size)
  
    print
    print 'Analyzing pak resources in %s...' % apk_filename
  
    # Calculate aggregate stats about resources across pak files.
    resource_count_map = collections.defaultdict(int)
    resource_size_map = collections.defaultdict(int)
    resource_overhead_bytes = 6
    for pak in paks:
      for r in pak.resources:
        resource_count_map[r] += 1
        resource_size_map[r] += len(pak.resources[r]) + resource_overhead_bytes
  
    # Output the overall resource summary.
    total_resource_size = sum(resource_size_map.values())
    total_resource_count = len(resource_count_map)
    assert total_resource_size <= total_file_size
    print 'Total pak resources: %s' % total_resource_count
    print 'Total uncompressed resource size: %s' % _FormatBytes(
        total_resource_size)
    print
  
    resource_id_name_map = _GetResourceIdNameMap()
  
    # Output the table of details about all resources across pak files.
    print
    print '%56s %5s %17s' % ('RESOURCE', 'COUNT', 'UNCOMPRESSED SIZE')
    for i in sorted(resource_size_map, key=resource_size_map.get,
                    reverse=True):
      if resource_size_map[i] >= min_pak_resource_size:
        print '%56s %5s %9s %6.2f%%' % (
            resource_id_name_map.get(i, i),
            resource_count_map[i],
            _FormatBytes(resource_size_map[i]),
            100.0 * resource_size_map[i] / total_resource_size)
function_tokens: def PrintPakAnalysis ( apk_filename , min_pak_resource_size ) : print print 'Analyzing pak files in %s...' % apk_filename # A structure for holding details about a pak file. Pak = collections . namedtuple ( 'Pak' , [ 'filename' , 'compress_size' , 'file_size' , 'resources' ] ) # Build a list of Pak objets for each pak file. paks = [ ] apk = zipfile . ZipFile ( apk_filename , 'r' ) try : for i in ( x for x in apk . infolist ( ) if IsPakFileName ( x . filename ) ) : with tempfile . NamedTemporaryFile ( ) as f : f . write ( apk . read ( i . filename ) ) f . flush ( ) paks . append ( Pak ( i . filename , i . compress_size , i . file_size , data_pack . DataPack . ReadDataPack ( f . name ) . resources ) ) finally : apk . close ( ) # Output the overall pak file summary. total_files = len ( paks ) total_compress_size = sum ( pak . compress_size for pak in paks ) total_file_size = sum ( pak . file_size for pak in paks ) print 'Total pak files: %d' % total_files print 'Total compressed size: %s' % _FormatBytes ( total_compress_size ) print 'Total uncompressed size: %s' % _FormatBytes ( total_file_size ) print # Output the table of details about all pak files. print '%25s%11s%21s%21s' % ( 'FILENAME' , 'RESOURCES' , 'COMPRESSED SIZE' , 'UNCOMPRESSED SIZE' ) for pak in sorted ( paks , key = operator . attrgetter ( 'file_size' ) , reverse = True ) : print '%25s %10s %12s %6.2f%% %12s %6.2f%%' % ( pak . filename , len ( pak . resources ) , _FormatBytes ( pak . compress_size ) , 100.0 * pak . compress_size / total_compress_size , _FormatBytes ( pak . file_size ) , 100.0 * pak . file_size / total_file_size ) print print 'Analyzing pak resources in %s...' % apk_filename # Calculate aggregate stats about resources across pak files. resource_count_map = collections . defaultdict ( int ) resource_size_map = collections . defaultdict ( int ) resource_overhead_bytes = 6 for pak in paks : for r in pak . resources : resource_count_map [ r ] += 1 resource_size_map [ r ] += len ( pak . resources [ r ] ) + resource_overhead_bytes # Output the overall resource summary. total_resource_size = sum ( resource_size_map . values ( ) ) total_resource_count = len ( resource_count_map ) assert total_resource_size <= total_file_size print 'Total pak resources: %s' % total_resource_count print 'Total uncompressed resource size: %s' % _FormatBytes ( total_resource_size ) print resource_id_name_map = _GetResourceIdNameMap ( ) # Output the table of details about all resources across pak files. print print '%56s %5s %17s' % ( 'RESOURCE' , 'COUNT' , 'UNCOMPRESSED SIZE' ) for i in sorted ( resource_size_map , key = resource_size_map . get , reverse = True ) : if resource_size_map [ i ] >= min_pak_resource_size : print '%56s %5s %9s %6.2f%%' % ( resource_id_name_map . get ( i , i ) , resource_count_map [ i ] , _FormatBytes ( resource_size_map [ i ] ) , 100.0 * resource_size_map [ i ] / total_resource_size )