|
| 1 | +import os |
| 2 | +import httplib |
| 3 | +import re |
| 4 | +import time |
| 5 | + |
| 6 | +host = 'wsgi-tests.example.com' |
| 7 | +port = '11111' |
| 8 | + |
| 9 | +host = os.environ.get('WSGI_TESTS_HOST', host) |
| 10 | +port = int(os.environ.get('WSGI_TESTS_PORT', port)) |
| 11 | + |
| 12 | +log_file = '/var/log/apache2/%s-error_log' % host |
| 13 | +log_delay = '0.1' |
| 14 | + |
| 15 | +log_file = os.environ.get('WSGI_TEST_LOG_FILE', log_file) |
| 16 | +log_delay = float(os.environ.get('WSGI_TEST_LOG_DELAY', log_delay)) |
| 17 | + |
| 18 | +def connection(): |
| 19 | + connection = httplib.HTTPConnection(host, port) |
| 20 | + connection.connect() |
| 21 | + return connection |
| 22 | + |
| 23 | +class Log(object): |
| 24 | + |
| 25 | + def __init__(self, filename): |
| 26 | + self.__filename = filename |
| 27 | + self.__fp = open(self.__filename, 'r') |
| 28 | + self.__fp.seek(0, os.SEEK_END) |
| 29 | + self.__errors = None |
| 30 | + |
| 31 | + def output(self, index): |
| 32 | + if not self.__errors is None: |
| 33 | + return self.__errors[index] |
| 34 | + time.sleep(1) |
| 35 | + self.__errors = [] |
| 36 | + for line in self.__fp.readlines(): |
| 37 | + match = re.match(r'(\[[^]]*\]) (\[[^]]*\]) (\[[^]]*\]) (.*)', line) |
| 38 | + if match: |
| 39 | + groups = match.groups() |
| 40 | + line = groups[1] + ' ' + groups[3] |
| 41 | + else: |
| 42 | + match = re.match(r'(\[[^]]*\]) (.*)', line) |
| 43 | + if match: |
| 44 | + groups = match.groups() |
| 45 | + line = groups[1] |
| 46 | + self.__errors.append(line) |
| 47 | + return self.__errors[index] |
| 48 | + |
| 49 | +def messages(): |
| 50 | + return Log(log_file) |
0 commit comments