Added section on passing contextual information to logging and documentation for...
[python.git] / Doc / library / dircache.rst
blob28aa6671295ed563695b65221ea8b6e8c686853c
2 :mod:`dircache` --- Cached directory listings
3 =============================================
5 .. module:: dircache
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
13 slash.
15 The :mod:`dircache` module defines the following functions:
18 .. function:: reset()
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
27    directory structure.
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.
45    >>> import dircache
46    >>> a = dircache.listdir('/')
47    >>> a = a[:] # Copy the return value so we can change 'a'
48    >>> 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)
52    >>> a
53    ['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
54    ', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm
55    linuz']