1 """Read and cache directory listings.
3 The listdir() routine returns a sorted list of the files in a directory,
4 using a cache to avoid reading the directory more often than necessary.
5 The annotate() routine appends slashes to directories."""
12 """List directory contents, using cache."""
14 cached_mtime
, list = cache
[path
]
17 cached_mtime
, list = -1, []
19 mtime
= os
.stat(path
)[8]
22 if mtime
<> cached_mtime
:
24 list = os
.listdir(path
)
28 cache
[path
] = mtime
, list
31 opendir
= listdir
# XXX backward compatibility
33 def annotate(head
, list):
34 """Add '/' suffixes to directories."""
35 for i
in range(len(list)):
36 if os
.path
.isdir(os
.path
.join(head
, list[i
])):
37 list[i
] = list[i
] + '/'