5 # find symbolic links to a path matching a regular expression
14 opts
, args
= getopt
.getopt(sys
.argv
[1:], '')
16 raise getopt
.GetoptError('not enough arguments', None)
17 except getopt
.GetoptError
, msg
:
18 sys
.stdout
= sys
.stderr
20 print 'usage: findlinksto pattern directory ...'
22 pat
, dirs
= args
[0], args
[1:]
23 prog
= re
.compile(pat
)
25 os
.path
.walk(dirname
, visit
, prog
)
27 def visit(prog
, dirname
, names
):
28 if os
.path
.islink(dirname
):
31 if os
.path
.ismount(dirname
):
32 print 'descend into', dirname
34 name
= os
.path
.join(dirname
, name
)
36 linkto
= os
.readlink(name
)
37 if prog
.search(linkto
) is not None:
38 print name
, '->', linkto
42 if __name__
== '__main__':