3333
3434CWD = os .getcwd ()
3535CHUNKSIZE = 1024
36+ MAX_TYPE_LEN = len ("Type" )
37+ MAX_EXT_LEN = len ("Extension" )
3638result = {}
37- max_ext_len = len ("Extension" )
3839
3940def is_binary (filename ):
4041 """Return true if the given filename is binary.
@@ -55,6 +56,10 @@ def is_binary(filename):
5556 return False
5657
5758def add_file (ext , type , size_mb ):
59+ global MAX_EXT_LEN
60+ MAX_EXT_LEN = max (MAX_EXT_LEN , len (ext ))
61+ global MAX_TYPE_LEN
62+ MAX_TYPE_LEN = max (MAX_TYPE_LEN , len (type ))
5863 if ext not in result :
5964 result [ext ] = {
6065 'ext' : ext ,
@@ -76,8 +81,8 @@ def add_file(ext, type, size_mb):
7681
7782def print_line (type , ext , share_large , count_large , count_all , size_all , min , max ):
7883 print ('{}{}{}{}{}{}{}{}' .format (
79- type .ljust (10 ),
80- ext .ljust (3 + max_ext_len ),
84+ type .ljust (3 + MAX_TYPE_LEN ),
85+ ext .ljust (3 + MAX_EXT_LEN ),
8186 str (share_large ).rjust (10 ),
8287 str (count_large ).rjust (10 ),
8388 str (count_all ).rjust (10 ),
@@ -102,7 +107,6 @@ def print_line(type, ext, share_large, count_large, count_all, size_all, min, ma
102107 ext = ext [ext .find ('.' )+ 1 :]
103108 if ext .find ('.' ) <= 0 :
104109 add_file (ext , file_type , size_mb )
105- max_ext_len = max (max_ext_len , len (ext ))
106110 except Exception as e :
107111 print (e )
108112
0 commit comments