2 :mod:`dircache` --- Cached directory listings
3 =============================================
6 :synopsis: Return directory listing, with cache mechanism.
7 .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
10 The :mod:`dircache` module defines a function for reading directory listing
11 using a cache, and cache invalidation using the *mtime* of the directory.
12 Additionally, it defines a function to annotate directories by appending a
15 The :mod:`dircache` module defines the following functions:
20 Resets the directory cache.
23 .. function:: listdir(path)
25 Return a directory listing of *path*, as gotten from :func:`os.listdir`. Note
26 that unless *path* changes, further call to :func:`listdir` will not re-read the
29 Note that the list returned should be regarded as read-only. (Perhaps a future
30 version should change it to return a tuple?)
33 .. function:: opendir(path)
35 Same as :func:`listdir`. Defined for backwards compatibility.
38 .. function:: annotate(head, list)
40 Assume *list* is a list of paths relative to *head*, and append, in place, a
41 ``'/'`` to each path which points to a directory.
46 >>> a = dircache.listdir('/')
47 >>> a = a[:] # Copy the return value so we can change 'a'
49 ['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+
50 found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']
51 >>> dircache.annotate('/', a)
53 ['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
54 ', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm