| """Read and cache directory listings. |
| The listdir() routine returns a sorted list of the files in a directory, |
| using a cache to avoid reading the directory more often than necessary. |
| The annotate() routine appends slashes to directories.""" |
| __all__ = ["listdir", "opendir", "annotate", "reset"] |
| """Reset the cache completely.""" |
| """List directory contents, using cache.""" |
| cached_mtime, list = cache[path] |
| cached_mtime, list = -1, [] |
| mtime = os.stat(path).st_mtime |
| if mtime != cached_mtime: |
| cache[path] = mtime, list |
| opendir = listdir # XXX backward compatibility |
| def annotate(head, list): |
| """Add '/' suffixes to directories.""" |
| for i in range(len(list)): |
| if os.path.isdir(os.path.join(head, list[i])): |