Add option to skip paths matching glob
diff --git a/TODO b/TODO
index fa4ca48..df7aa1a 100644
--- a/TODO
+++ b/TODO
@@ -1,11 +1,6 @@
- Add option to disable changes to source code, allowing them only on comments
and text files
-- Add option to exclude paths. codespell already ignores .git and .svn
- subdirectories. It'd be good to give the user to ignore certain paths. E.g:
- .eps files -- they are not binary files but codespell shouldn't check them
- whatsoever.
-
- Add option to ignore big files. The biggest issue is if you try to run
codespell with a file in the source code tree like cscope.out. I don't know
if the best approach is to filter by name or by size
diff --git a/codespell.py b/codespell.py
index 8541de9..c772ca8 100755
--- a/codespell.py
+++ b/codespell.py
@@ -22,6 +22,7 @@
import re
from optparse import OptionParser
import os
+import fnmatch
USAGE = """
\t%prog [OPTIONS] dict_filename [file1 file2 ... fileN]
@@ -50,6 +51,22 @@
NON_AUTOMATIC_FIXES = 8
FIXES = 16
+class GlobMatch:
+ def __init__(self, pattern):
+ if pattern:
+ self.pattern_list = pattern.split(',')
+ else:
+ self.pattern_list = None
+
+ def match(self, filename):
+ if self.pattern_list is None:
+ return False
+
+ for p in self.pattern_list:
+ if fnmatch.fnmatch(filename, p):
+ return True
+
+ return False
class Misspell:
def __init__(self, data, fix, reason):
@@ -188,6 +205,14 @@
action = 'store_true', default = False,
help = 'print summary of fixes')
+ parser.add_option('-S', '--skip',
+ help = 'Comma-separated list of files to skip. It '\
+ 'accepts globs as well. E.g.: if you want '\
+ 'codespell to skip .eps and .txt files, '\
+ 'you\'d give "*.eps,*.txt" to this option. '\
+ 'It is expecially useful if you are using in '\
+ 'conjunction with -r option.')
+
parser.add_option('-x', '--exclude-file',
help = 'FILE with lines that should not be changed',
metavar='FILE')
@@ -463,6 +488,8 @@
fileopener = FileOpener(options.hard_encoding_detection)
+ glob_match = GlobMatch(options.skip)
+
for filename in args[1:]:
# ignore hidden files
if ishidden(filename):
@@ -483,7 +510,8 @@
for file in files:
if os.path.islink(file):
continue
-
+ if glob_match.match(file):
+ continue
parse_file(os.path.join(root, file), colors, summary)
continue