Use new name for GetoptError, and pass it two arguments

Use re module instead of regex
This commit is contained in:
Andrew M. Kuchling 2003-02-06 19:55:35 +00:00
parent c755758906
commit d683504b85
1 changed files with 5 additions and 5 deletions

View File

@ -6,21 +6,21 @@
import os
import sys
import regex
import re
import getopt
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], '')
if len(args) < 2:
raise getopt.error, 'not enough arguments'
except getopt.error, msg:
raise getopt.GetoptError('not enough arguments', None)
except getopt.GetoptError, msg:
sys.stdout = sys.stderr
print msg
print 'usage: findlinksto pattern directory ...'
sys.exit(2)
pat, dirs = args[0], args[1:]
prog = regex.compile(pat)
prog = re.compile(pat)
for dirname in dirs:
os.path.walk(dirname, visit, prog)
@ -34,7 +34,7 @@ def visit(prog, dirname, names):
name = os.path.join(dirname, name)
try:
linkto = os.readlink(name)
if prog.search(linkto) >= 0:
if prog.search(linkto) is not None:
print name, '->', linkto
except os.error:
pass