Skip to content

Instantly share code, notes, and snippets.

@ofan
Created January 5, 2013 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofan/4462042 to your computer and use it in GitHub Desktop.
Save ofan/4462042 to your computer and use it in GitHub Desktop.
#!/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