1 """Maintain a cache of stat() information on files.
3 There are functions to reset the cache or to selectively remove items.
10 # Keys are pathnames, values are `os.stat' outcomes.
16 """Stat a file, possibly out of the cache."""
17 if cache
.has_key(path
):
19 cache
[path
] = ret
= os
.stat(path
)
24 """Reset the cache completely."""
30 """Remove a given item from the cache, if it exists."""
31 if cache
.has_key(path
):
35 def forget_prefix(prefix
):
36 """Remove all pathnames with a given prefix."""
38 for path
in cache
.keys():
39 if path
[:n
] == prefix
:
43 def forget_dir(prefix
):
44 """Forget about a directory and all entries in it, but not about
45 entries in subdirectories."""
46 if prefix
[-1:] == '/' and prefix
<> '/':
49 if prefix
[-1:] <> '/':
52 for path
in cache
.keys():
53 if path
[:n
] == prefix
:
55 if rest
[-1:] == '/': rest
= rest
[:-1]
60 def forget_except_prefix(prefix
):
61 """Remove all pathnames except with a given prefix.
62 Normally used with prefix = '/' after a chdir()."""
64 for path
in cache
.keys():
65 if path
[:n
] <> prefix
:
70 """Check for directory."""
75 return S_ISDIR(st
[ST_MODE
])