Skip to content
Browse files

Use Unix style file patterns instead of python regexes for ignored files

  • Loading branch information...
1 parent d2b7e9e commit 1e6dbcb61ee7ef4f0390f4ac6ac7e33173a1b9ff @flavioamieiro committed
Showing with 9 additions and 10 deletions.
  1. +9 −10 dojotools.py
View
19 dojotools.py
@@ -24,7 +24,7 @@
import os
import sys
-import re
+from fnmatch import fnmatch
import subprocess
from time import ctime
from optparse import OptionParser
@@ -84,15 +84,16 @@ def __init__(self, ui, directory, commands, patterns_file, commit=False):
def _get_patterns(self, patterns_file):
"""
- Reads `patterns_file' and returns a list of compiled regexes with
- every pattern found in the file + the file name.
+ Reads `patterns_file' and returns a list of patterns found in
+ the patterns file, so they can be used in fnmatch.
+
+ Patterns should be Unix style.
+
+ For more information, type help(fnmatch) in a python shell
"""
try:
with open(patterns_file, 'r') as f:
- patterns = [
- p.strip().replace('*.', '.*\.')
- for p in f.readlines()
- ]
+ patterns = [pattern.strip() for pattern in f.readlines()]
except IOError:
sys.stdout.write(
'Could not find %s. Patterns will not be ignored\n'
@@ -103,8 +104,6 @@ def _get_patterns(self, patterns_file):
# Add patterns_file to the ignored patterns so it won't be tracked
patterns += [os.path.basename(patterns_file)]
- patterns = [re.compile(p) for p in patterns]
-
return patterns
def _filter_files(self, files):
@@ -116,7 +115,7 @@ def _filter_files(self, files):
files is not an instance attribute)
"""
for p in self.patterns:
- files = [f for f in files if not p.match(f)]
+ files = [f for f in files if not fnmatch(f, p)]
return files
def git_commit_all(self):

0 comments on commit 1e6dbcb

Please sign in to comment.
Something went wrong with that request. Please try again.