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