Created
January 5, 2013 15:13
-
-
Save ofan/4462042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# This script takes two parameters, the first is the filename needs to be matched, | |
# the second is the file contains glob patterns.One pattern per line. | |
import fnmatch | |
import sys | |
def check_match(f, fn): | |
with open(f) as fpattern: | |
for pat in fpattern.xreadlines(): | |
pat = pat.strip() | |
# Ignore comments | |
if pat.startswith('#'): | |
continue | |
if fnmatch.fnmatch(fn, pat): | |
return True | |
return False | |
if __name__ == "__main__": | |
if len(sys.argv) < 3: | |
print("Usage: %s <filename> <pattern file>" % sys.argv[0]) | |
else: | |
if check_match(sys.argv[2], sys.argv[1]): | |
exit(0) | |
else: | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment