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 ),
@@ -96,13 +101,17 @@ def print_line(type, ext, share_large, count_large, count_all, size_all, min, ma
96101 file_type = "binary"
97102 else :
98103 file_type = "text"
99- ext = filename
104+ ext = os . path . basename ( filename )
100105 add_file ('*' , 'all' , size_mb )
101- while ext .find ('.' ) >= 0 :
102- ext = ext [ext .find ('.' )+ 1 :]
103- if ext .find ('.' ) <= 0 :
104- add_file (ext , file_type , size_mb )
105- max_ext_len = max (max_ext_len , len (ext ))
106+ if ext .find ('.' ) == - 1 :
107+ # files w/o extension
108+ add_file (ext , file_type + " w/o ext" , size_mb )
109+ else :
110+ while ext .find ('.' ) >= 0 :
111+ ext = ext [ext .find ('.' )+ 1 :]
112+ if ext .find ('.' ) <= 0 :
113+ add_file (ext , file_type , size_mb )
114+
106115 except Exception as e :
107116 print (e )
108117
@@ -116,7 +125,7 @@ def print_line(type, ext, share_large, count_large, count_all, size_all, min, ma
116125 print_line (
117126 result [ext ]['type' ],
118127 ext ,
119- str (large_share ) + ' %' ,
128+ str (round ( large_share ) ) + ' %' ,
120129 result [ext ]['count_large' ],
121130 result [ext ]['count_all' ],
122131 int (result [ext ]['size_all' ]),
0 commit comments