1515# limitations under the License.
1616
1717import argparse
18+ import glob
1819import os
1920import shutil
2021import subprocess
@@ -46,6 +47,7 @@ def main(argv=sys.argv[1:]):
4647 '--exclude' ,
4748 nargs = '*' ,
4849 default = [],
50+ dest = 'excludes' ,
4951 help = 'Exclude specific file names and directory names from the check' )
5052 # not using a file handle directly
5153 # in order to prevent leaving an empty file when something fails early
@@ -62,7 +64,7 @@ def main(argv=sys.argv[1:]):
6264 if args .xunit_file :
6365 start_time = time .time ()
6466
65- files = get_files (args .paths , args .extensions , args .exclude )
67+ files = get_files (args .paths , args .extensions , args .excludes )
6668 if not files :
6769 print ('No files found' , file = sys .stderr )
6870 return 1
@@ -158,7 +160,12 @@ def main(argv=sys.argv[1:]):
158160 return rc
159161
160162
161- def get_files (paths , extensions , excludes = []):
163+ def get_files (paths , extensions , exclude_patterns ):
164+ excludes = []
165+ for exclude_pattern in exclude_patterns :
166+ excludes .extend (glob .glob (exclude_pattern ))
167+ excludes = {os .path .realpath (x ) for x in excludes }
168+
162169 files = []
163170 for path in paths :
164171 if os .path .isdir (path ):
@@ -169,12 +176,12 @@ def get_files(paths, extensions, excludes=[]):
169176 # ignore folder starting with . or _
170177 dirnames [:] = [d for d in dirnames if d [0 ] not in ['.' , '_' ]]
171178 # ignore excluded folders
172- dirnames [:] = [d for d in dirnames if d not in excludes ]
179+ dirnames [:] = [d for d in dirnames if os . path . realpath ( d ) not in excludes ]
173180 dirnames .sort ()
174181
175182 # select files by extension
176183 for filename in sorted (filenames ):
177- if filename in excludes :
184+ if os . path . realpath ( os . path . join ( dirpath , filename )) in excludes :
178185 continue
179186 _ , ext = os .path .splitext (filename )
180187 if ext not in ['.%s' % e for e in extensions ]:
0 commit comments