Wanted: eglob.py 5
Cat.: Wanted, Python01. July 2005
I’d really like to see an enhanced glob
module. Nothing too crazy,
just support for recursive wildcards and maybe a nice filtering
API. Here’s your test case:
>>> import eglob
… or whatever.
A find
function should return an iterator over all matching files and
directories. Note that it should be possible to do recursive searches as
the iterator is moving. yield
kicks so much ass right here.
>>> eglob.find('/etc/**')
<generator object at ...>
Being able to filter the initial glob with such operations as exclude
and
include
(needed?) would be nice. Designing this will be fun - try to abuse
chaining generators as much as possible. :)
>>> list(eglob.find('/etc/**').exclude('passwd', 'group', 'init.d/*'))
['/etc/hosts', '/etc/httpd', '/etc/httpd/conf/httpd.conf']
I should be able to pass a extended glob (str
, unicode
) or a
compiled regular expression (sre.SRE_Pattern
) to any finding or
filtering functions:
>>> list(eglob.find(re.compile(r'^/tmp/.*')))
['/tmp/mysql.sock', '/tmp/foo/bling']
I’d like to filter for directories only or files only:
>>> list(eglob.find('/home/*', directories=1))
['/home/hurly', '/home/curly', '/home/moe']
>>> eglob.find('**/.cvsignore', files=1)
This would be hugely useful in about four projects I’m currently working on.