Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
statcache Namespace Reference

Functions

def stat
 
def reset
 
def forget
 
def forget_prefix
 
def forget_dir
 
def forget_except_prefix
 
def isdir
 

Variables

list __all__
 
dictionary cache = {}
 

Detailed Description

Maintain a cache of stat() information on files.

There are functions to reset the cache or to selectively remove items.

Function Documentation

def statcache.forget (   path)
Remove a given item from the cache, if it exists.

Definition at line 31 of file statcache.py.

31 
32 def forget(path):
33  """Remove a given item from the cache, if it exists."""
34  try:
35  del cache[path]
36  except KeyError:
37  pass
def statcache.forget_dir (   prefix)
Forget a directory and all entries except for entries in subdirs.

Definition at line 44 of file statcache.py.

References forget(), dospath.join(), and dospath.split().

44 
45 def forget_dir(prefix):
46  """Forget a directory and all entries except for entries in subdirs."""
47 
48  # Remove trailing separator, if any. This is tricky to do in a
49  # x-platform way. For example, Windows accepts both / and \ as
50  # separators, and if there's nothing *but* a separator we want to
51  # preserve that this is the root. Only os.path has the platform
52  # knowledge we need.
53  from os.path import split, join
54  prefix = split(join(prefix, "xxx"))[0]
55  forget(prefix)
56  for path in cache.keys():
57  # First check that the path at least starts with the prefix, so
58  # that when it doesn't we can avoid paying for split().
59  if path.startswith(prefix) and split(path)[0] == prefix:
60  forget(path)
def statcache.forget_except_prefix (   prefix)
Remove all pathnames except with a given prefix.

Normally used with prefix = '/' after a chdir().

Definition at line 61 of file statcache.py.

References forget().

61 
62 def forget_except_prefix(prefix):
63  """Remove all pathnames except with a given prefix.
64 
65  Normally used with prefix = '/' after a chdir().
66  """
67 
68  for path in cache.keys():
69  if not path.startswith(prefix):
70  forget(path)
def statcache.forget_prefix (   prefix)
Remove all pathnames with a given prefix.

Definition at line 38 of file statcache.py.

References forget().

38 
39 def forget_prefix(prefix):
40  """Remove all pathnames with a given prefix."""
41  for path in cache.keys():
42  if path.startswith(prefix):
43  forget(path)
def statcache.isdir (   path)
Return 1 if directory, else 0.

Definition at line 71 of file statcache.py.

References stat.S_ISDIR().

71 
72 def isdir(path):
73  """Return 1 if directory, else 0."""
74  try:
75  st = stat(path)
76  except _os.error:
77  return 0
78  return S_ISDIR(st[ST_MODE])
def statcache.reset ( )
Clear the cache.

Definition at line 26 of file statcache.py.

26 
27 def reset():
28  """Clear the cache."""
29  cache.clear()
30 
# For thread saftey, always use forget() internally too.
def statcache.stat (   path)
Stat a file, possibly out of the cache.

Definition at line 19 of file statcache.py.

19 
20 def stat(path):
21  """Stat a file, possibly out of the cache."""
22  ret = cache.get(path, None)
23  if ret is None:
24  cache[path] = ret = _os.stat(path)
25  return ret

Variable Documentation

list __all__
Initial value:
1 = ["stat","reset","forget","forget_prefix","forget_dir",
2  "forget_except_prefix","isdir"]

Definition at line 9 of file statcache.py.

dictionary cache = {}

Definition at line 17 of file statcache.py.