@@ -64,75 +64,51 @@ def do_license_check(name, contents):
6464src_dir = sys .argv [1 ]
6565
6666try :
67- count_rs = 0
68- count_py = 0
69- count_js = 0
70- count_sh = 0
71- count_pl = 0
72- count_c = 0
73- count_h = 0
74- count_other = 0
75-
7667 count_lines = 0
7768 count_non_blank_lines = 0
7869
70+ interesting_files = ['.rs' , '.py' , '.js' , '.sh' , '.c' , '.h' ]
71+
72+ file_counts = {ext : 0 for ext in interesting_files }
73+ file_counts ['other' ] = 0
74+
7975 def update_counts (current_name ):
80- global count_rs
81- global count_py
82- global count_js
83- global count_sh
84- global count_pl
85- global count_c
86- global count_h
87- global count_other
88-
89- if current_name .endswith (".rs" ):
90- count_rs += 1
91- if current_name .endswith (".py" ):
92- count_py += 1
93- if current_name .endswith (".js" ):
94- count_js += 1
95- if current_name .endswith (".sh" ):
96- count_sh += 1
97- if current_name .endswith (".pl" ):
98- count_pl += 1
99- if current_name .endswith (".c" ):
100- count_c += 1
101- if current_name .endswith (".h" ):
102- count_h += 1
76+ global file_counts
77+ _ , ext = os .path .splitext (current_name )
78+
79+ if ext in file_counts :
80+ file_counts [ext ] += 1
81+ else :
82+ file_counts ['other' ] += 1
10383
10484 all_paths = set ()
10585
10686 for (dirpath , dirnames , filenames ) in os .walk (src_dir ):
10787
10888 # Skip some third-party directories
109- if "src/jemalloc" in dirpath : continue
110- if "src/llvm" in dirpath : continue
111- if "src/gyp" in dirpath : continue
112- if "src/libbacktrace" in dirpath : continue
113- if "src/compiler-rt" in dirpath : continue
114- if "src/rt/hoedown" in dirpath : continue
115- if "src/rustllvm" in dirpath : continue
116- if "src/rt/valgrind" in dirpath : continue
117- if "src/rt/msvc" in dirpath : continue
118- if "src/rust-installer" in dirpath : continue
89+ skippable_dirs = {
90+ 'src/jemalloc' ,
91+ 'src/llvm' ,
92+ 'src/gyp' ,
93+ 'src/libbacktrace' ,
94+ 'src/compiler-rt' ,
95+ 'src/rt/hoedown' ,
96+ 'src/rustllvm' ,
97+ 'src/rt/valgrind' ,
98+ 'src/rt/msvc' ,
99+ 'src/rust-installer'
100+ }
101+
102+ if any (d in dirpath for d in skippable_dirs ):
103+ continue
119104
120105 def interesting_file (f ):
121106 if "miniz.c" in f \
122107 or "jquery" in f \
123108 or "rust_android_dummy" in f :
124109 return False
125110
126- if f .endswith (".rs" ) \
127- or f .endswith (".py" ) \
128- or f .endswith (".js" ) \
129- or f .endswith (".sh" ) \
130- or f .endswith (".pl" ) \
131- or f .endswith (".c" ) \
132- or f .endswith (".h" ) :
133- return True
134- else :
135- return False
111+ return any (os .path .splitext (f )[1 ] == ext for ext in interesting_files )
136112
137113 file_names = [os .path .join (dirpath , f ) for f in filenames
138114 if interesting_file (f )
@@ -219,14 +195,8 @@ def interesting_file(f):
219195 report_err ("UTF-8 decoding error " + str (e ))
220196
221197print
222- print "* linted .rs files: " + str (count_rs )
223- print "* linted .py files: " + str (count_py )
224- print "* linted .js files: " + str (count_js )
225- print "* linted .sh files: " + str (count_sh )
226- print "* linted .pl files: " + str (count_pl )
227- print "* linted .c files: " + str (count_c )
228- print "* linted .h files: " + str (count_h )
229- print "* other linted files: " + str (count_other )
198+ for ext in file_counts :
199+ print "* linted " + str (file_counts [ext ]) + " " + ext + " files"
230200print "* total lines of code: " + str (count_lines )
231201print "* total non-blank lines of code: " + str (count_non_blank_lines )
232202print
0 commit comments