1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
import sys
def main():
path = sys.argv[1]
app = Application(path)
if app.run():
sys.exit(0)
else:
sys.exit(1)
class Application(object):
def __init__(self, path):
self.path = path
def run(self):
with open(self.path, 'rt') as f:
lines = [line.rstrip() for line in f if line.rstrip()]
errors = self.analyze(lines)
return errors
def analyze(self, lines):
error_sep = '======================================================================'
traceback_sep = '----------------------------------------------------------------------'
index = 0
result = True
while True:
try:
index = lines.index(error_sep, index)
except ValueError:
break
index += 1
function = lines[index]
index += 1
start = lines.index(traceback_sep, index)
end = lines.index(traceback_sep, start + 1)
index = end + 1
error = lines[end - 1]
if error != 'MemoryError':
print('%s: %s' % (function, error))
result = False
return result
if __name__ == '__main__':
main()
|