3
class MakeError(Exception):
4
def __init__(self, message, loc=None):
10
if self.loc is not None:
11
locstr = "%s:" % (self.loc,)
13
return "%s%s" % (locstr, self.msg)
15
def normaljoin(path, suffix):
17
Combine the given path with the suffix, and normalize if necessary to shrink the path to avoid hitting path length limits
19
result = os.path.join(path, suffix)
21
result = os.path.normpath(result)
26
Given an iterator that returns strings, write the words with a space in between each.
38
def checkmsyscompat():
39
"""For msys compatibility on windows, honor the SHELL environment variable,
40
and if $MSYSTEM == MINGW32, run commands through $SHELL -c instead of
41
letting Python use the system shell."""
42
if 'SHELL' in os.environ:
43
shell = os.environ['SHELL']
44
elif 'MOZILLABUILD' in os.environ:
45
shell = os.environ['MOZILLABUILD'] + '/msys/bin/sh.exe'
46
elif 'COMSPEC' in os.environ:
47
shell = os.environ['COMSPEC']
49
raise DataError("Can't find a suitable shell!")
52
if 'MSYSTEM' in os.environ and os.environ['MSYSTEM'] == 'MINGW32':
54
if not shell.lower().endswith(".exe"):
58
if hasattr(str, 'partition'):
59
def strpartition(str, token):
60
return str.partition(token)
62
def strrpartition(str, token):
63
return str.rpartition(token)
66
def strpartition(str, token):
67
"""Python 2.4 compatible str.partition"""
69
offset = str.find(token)
73
return str[:offset], token, str[offset + len(token):]
75
def strrpartition(str, token):
76
"""Python 2.4 compatible str.rpartition"""
78
offset = str.rfind(token)
82
return str[:offset], token, str[offset + len(token):]
85
from __builtin__ import any
93
class _MostUsedItem(object):
94
__slots__ = ('key', 'o', 'count')
96
def __init__(self, key):
102
return "MostUsedItem(key=%r, count=%i, o=%r)" % (self.key, self.count, self.o)
104
class MostUsedCache(object):
105
def __init__(self, capacity, creationfunc, verifyfunc):
106
self.capacity = capacity
107
self.cfunc = creationfunc
108
self.vfunc = verifyfunc
111
self.active = [] # lazily sorted!
113
def setactive(self, item):
114
if item in self.active:
117
if len(self.active) == self.capacity:
118
self.active.sort(key=lambda i: i.count)
119
old = self.active.pop(0)
121
# print "Evicting %s" % old.key
123
self.active.append(item)
126
item = self.d.get(key, None)
128
item = _MostUsedItem(key)
133
if item.o is not None and self.vfunc(key, item.o):
136
item.o = self.cfunc(key)
141
for k, v in self.d.iteritems():
143
assert v in self.active
145
assert v not in self.active
147
def debugitems(self):
148
l = [i.key for i in self.active]