2222import re
2323from optparse import OptionParser
2424import os
25+ import fnmatch
2526
2627USAGE = """
2728\t %prog [OPTIONS] dict_filename [file1 file2 ... fileN]
@@ -50,6 +51,22 @@ class QuietLevels:
5051 NON_AUTOMATIC_FIXES = 8
5152 FIXES = 16
5253
54+ class GlobMatch :
55+ def __init__ (self , pattern ):
56+ if pattern :
57+ self .pattern_list = pattern .split (',' )
58+ else :
59+ self .pattern_list = None
60+
61+ def match (self , filename ):
62+ if self .pattern_list is None :
63+ return False
64+
65+ for p in self .pattern_list :
66+ if fnmatch .fnmatch (filename , p ):
67+ return True
68+
69+ return False
5370
5471class Misspell :
5572 def __init__ (self , data , fix , reason ):
@@ -188,6 +205,14 @@ def parse_options(args):
188205 action = 'store_true' , default = False ,
189206 help = 'print summary of fixes' )
190207
208+ parser .add_option ('-S' , '--skip' ,
209+ help = 'Comma-separated list of files to skip. It ' \
210+ 'accepts globs as well. E.g.: if you want ' \
211+ 'codespell to skip .eps and .txt files, ' \
212+ 'you\' d give "*.eps,*.txt" to this option. ' \
213+ 'It is expecially useful if you are using in ' \
214+ 'conjunction with -r option.' )
215+
191216 parser .add_option ('-x' , '--exclude-file' ,
192217 help = 'FILE with lines that should not be changed' ,
193218 metavar = 'FILE' )
@@ -463,6 +488,8 @@ def main(*args):
463488
464489 fileopener = FileOpener (options .hard_encoding_detection )
465490
491+ glob_match = GlobMatch (options .skip )
492+
466493 for filename in args [1 :]:
467494 # ignore hidden files
468495 if ishidden (filename ):
@@ -483,7 +510,8 @@ def main(*args):
483510 for file in files :
484511 if os .path .islink (file ):
485512 continue
486-
513+ if glob_match .match (file ):
514+ continue
487515 parse_file (os .path .join (root , file ), colors , summary )
488516
489517 continue
0 commit comments