@@ -28,11 +28,7 @@ import os
28
28
import sys
29
29
30
30
# Threshold that defines a large file
31
- if len (sys .argv ) > 1 :
32
- THRESHOLD_IN_MB = float (sys .argv [1 ]) / 1024
33
- else :
34
- THRESHOLD_IN_MB = 0.5
35
-
31
+ THRESHOLD_IN_MB = float (sys .argv [1 ]) / 1024 if len (sys .argv ) > 1 else 0.5
36
32
CWD = os .getcwd ()
37
33
CHUNKSIZE = 1024
38
34
MAX_TYPE_LEN = len ("Type" )
@@ -77,38 +73,28 @@ def add_file(ext, type, size_mb):
77
73
if size_mb > THRESHOLD_IN_MB :
78
74
result [ext ]['count_large' ] = result [ext ]['count_large' ] + 1
79
75
result [ext ]['size_large' ] = result [ext ]['size_large' ] + size_mb
80
- if not 'max' in result [ext ] or size_mb > result [ext ]['max' ]:
76
+ if 'max' not in result [ext ] or size_mb > result [ext ]['max' ]:
81
77
result [ext ]['max' ] = size_mb
82
- if not 'min' in result [ext ] or size_mb < result [ext ]['min' ]:
78
+ if 'min' not in result [ext ] or size_mb < result [ext ]['min' ]:
83
79
result [ext ]['min' ] = size_mb
84
80
85
81
def print_line (type , ext , share_large , count_large , count_all , size_all , min , max ):
86
- print ('{}{}{}{}{}{}{}{}' .format (
87
- type .ljust (3 + MAX_TYPE_LEN ),
88
- ext .ljust (3 + MAX_EXT_LEN ),
89
- str (share_large ).rjust (10 ),
90
- str (count_large ).rjust (10 ),
91
- str (count_all ).rjust (10 ),
92
- str (size_all ).rjust (10 ),
93
- str (min ).rjust (10 ),
94
- str (max ).rjust (10 )
95
- ))
82
+ print (
83
+ f'{ type .ljust (3 + MAX_TYPE_LEN )} { ext .ljust (3 + MAX_EXT_LEN )} { str (share_large ).rjust (10 )} { str (count_large ).rjust (10 )} { str (count_all ).rjust (10 )} { str (size_all ).rjust (10 )} { str (min ).rjust (10 )} { str (max ).rjust (10 )} '
84
+ )
96
85
97
86
for root , dirs , files in os .walk (CWD ):
98
87
for basename in files :
99
88
filename = os .path .join (root , basename )
100
89
try :
101
90
size_mb = float (os .path .getsize (filename )) / 1024 / 1024
102
91
if not filename .startswith (os .path .join (CWD , '.git' )) and size_mb > 0 :
103
- if is_binary (filename ):
104
- file_type = "binary"
105
- else :
106
- file_type = "text"
92
+ file_type = "binary" if is_binary (filename ) else "text"
107
93
ext = os .path .basename (filename )
108
94
add_file ('*' , 'all' , size_mb )
109
95
if ext .find ('.' ) == - 1 :
110
96
# files w/o extension
111
- add_file (ext , file_type + " w/o ext" , size_mb )
97
+ add_file (ext , f" { file_type } w/o ext" , size_mb )
112
98
else :
113
99
while ext .find ('.' ) >= 0 :
114
100
ext = ext [ext .find ('.' )+ 1 :]
@@ -128,17 +114,17 @@ for ext in sorted(result, key=lambda x: (result[x]['type'], -result[x]['size_lar
128
114
print_line (
129
115
result [ext ]['type' ],
130
116
ext ,
131
- str (round (large_share )) + ' %' ,
117
+ f' { str (round (large_share ))} %' ,
132
118
result [ext ]['count_large' ],
133
119
result [ext ]['count_all' ],
134
120
int (result [ext ]['size_all' ]),
135
121
int (result [ext ]['min' ]),
136
- int (result [ext ]['max' ])
122
+ int (result [ext ]['max' ]),
137
123
)
138
124
139
125
print ("\n Add to .gitattributes:\n " )
140
126
for ext in sorted (result , key = lambda x : (result [x ]['type' ], x )):
141
127
if len (ext ) > 0 and result [ext ]['type' ] == "binary" and result [ext ]['count_large' ] > 0 :
142
- print ('*.{} filter=lfs diff=lfs merge=lfs -text' . format (
143
- "" . join ("[" + c .upper () + c .lower () + " ]" if (( 'a' <= c <= 'z' ) or ( 'A' <= c <= 'Z' )) else c for c in ext )
144
- ))
128
+ print (
129
+ f"""*. { "" . join (f"[ { c .upper ()} { c .lower ()} ]" if 'a' <= c <= 'z' or 'A' <= c <= 'Z' else c for c in ext )} filter=lfs diff=lfs merge=lfs -text"""
130
+ )
0 commit comments