/Doc/library/dircache.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 62 lines · 38 code · 24 blank · 0 comment · 0 complexity · fcaa832851257eeef6277062e2a9431f MD5 · raw file

  1. :mod:`dircache` --- Cached directory listings
  2. =============================================
  3. .. module:: dircache
  4. :synopsis: Return directory listing, with cache mechanism.
  5. :deprecated:
  6. .. deprecated:: 2.6
  7. The :mod:`dircache` module has been removed in Python 3.0.
  8. .. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
  9. The :mod:`dircache` module defines a function for reading directory listing
  10. using a cache, and cache invalidation using the *mtime* of the directory.
  11. Additionally, it defines a function to annotate directories by appending a
  12. slash.
  13. The :mod:`dircache` module defines the following functions:
  14. .. function:: reset()
  15. Resets the directory cache.
  16. .. function:: listdir(path)
  17. Return a directory listing of *path*, as gotten from :func:`os.listdir`. Note
  18. that unless *path* changes, further call to :func:`listdir` will not re-read the
  19. directory structure.
  20. Note that the list returned should be regarded as read-only. (Perhaps a future
  21. version should change it to return a tuple?)
  22. .. function:: opendir(path)
  23. Same as :func:`listdir`. Defined for backwards compatibility.
  24. .. function:: annotate(head, list)
  25. Assume *list* is a list of paths relative to *head*, and append, in place, a
  26. ``'/'`` to each path which points to a directory.
  27. ::
  28. >>> import dircache
  29. >>> a = dircache.listdir('/')
  30. >>> a = a[:] # Copy the return value so we can change 'a'
  31. >>> a
  32. ['bin', 'boot', 'cdrom', 'dev', 'etc', 'floppy', 'home', 'initrd', 'lib', 'lost+
  33. found', 'mnt', 'proc', 'root', 'sbin', 'tmp', 'usr', 'var', 'vmlinuz']
  34. >>> dircache.annotate('/', a)
  35. >>> a
  36. ['bin/', 'boot/', 'cdrom/', 'dev/', 'etc/', 'floppy/', 'home/', 'initrd/', 'lib/
  37. ', 'lost+found/', 'mnt/', 'proc/', 'root/', 'sbin/', 'tmp/', 'usr/', 'var/', 'vm
  38. linuz']