mirror of
https://git.rtems.org/rtems-source-builder
synced 2024-10-09 07:15:10 +08:00
Add tail support to the log. Email the log tail in a failure.
This commit is contained in:
parent
3c69de0831
commit
c914e1d306
@ -88,7 +88,9 @@ def flush(log = None):
|
|||||||
|
|
||||||
class log:
|
class log:
|
||||||
"""Log output to stdout or a file."""
|
"""Log output to stdout or a file."""
|
||||||
def __init__(self, streams = None):
|
def __init__(self, streams = None, tail_size = 100):
|
||||||
|
self.tail = []
|
||||||
|
self.tail_size = tail_size
|
||||||
self.fhs = [None, None]
|
self.fhs = [None, None]
|
||||||
if streams:
|
if streams:
|
||||||
for s in streams:
|
for s in streams:
|
||||||
@ -107,6 +109,19 @@ class log:
|
|||||||
for f in range(2, len(self.fhs)):
|
for f in range(2, len(self.fhs)):
|
||||||
self.fhs[f].close()
|
self.fhs[f].close()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
t = ''
|
||||||
|
for tl in self.tail:
|
||||||
|
t += tl + os.linesep
|
||||||
|
return t[:-len(os.linesep)]
|
||||||
|
|
||||||
|
def _tail(self, text):
|
||||||
|
if type(text) is not list:
|
||||||
|
text = text.splitlines()
|
||||||
|
self.tail += text
|
||||||
|
if len(self.tail) > self.tail_size:
|
||||||
|
self.tail = self.tail[-self.tail_size:]
|
||||||
|
|
||||||
def has_stdout(self):
|
def has_stdout(self):
|
||||||
return self.fhs[0] is not None
|
return self.fhs[0] is not None
|
||||||
|
|
||||||
@ -116,8 +131,10 @@ class log:
|
|||||||
def output(self, text):
|
def output(self, text):
|
||||||
"""Output the text message to all the logs."""
|
"""Output the text message to all the logs."""
|
||||||
# Reformat the text to have local line types.
|
# Reformat the text to have local line types.
|
||||||
|
text = text.replace(chr(13), '').splitlines()
|
||||||
|
self._tail(text)
|
||||||
out = ''
|
out = ''
|
||||||
for l in text.replace(chr(13), '').splitlines():
|
for l in text:
|
||||||
out += l + os.linesep
|
out += l + os.linesep
|
||||||
for f in range(0, len(self.fhs)):
|
for f in range(0, len(self.fhs)):
|
||||||
if self.fhs[f] is not None:
|
if self.fhs[f] is not None:
|
||||||
@ -131,12 +148,23 @@ class log:
|
|||||||
self.fhs[f].flush()
|
self.fhs[f].flush()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
l = log(['stdout', 'log.txt'])
|
l = log(['stdout', 'log.txt'], tail_size = 20)
|
||||||
for i in range(0, 10):
|
for i in range(0, 10):
|
||||||
l.output('log: hello world: %d\n' % (i))
|
l.output('log: hello world: %d\n' % (i))
|
||||||
l.output('log: hello world CRLF\r\n')
|
l.output('log: hello world CRLF\r\n')
|
||||||
l.output('log: hello world NONE')
|
l.output('log: hello world NONE')
|
||||||
l.flush()
|
l.flush()
|
||||||
|
print '=-' * 40
|
||||||
|
print 'tail: %d' % (len(l.tail))
|
||||||
|
print l
|
||||||
|
print '=-' * 40
|
||||||
|
for i in range(0, 10):
|
||||||
|
l.output('log: hello world 2: %d\n' % (i))
|
||||||
|
l.flush()
|
||||||
|
print '=-' * 40
|
||||||
|
print 'tail: %d' % (len(l.tail))
|
||||||
|
print l
|
||||||
|
print '=-' * 40
|
||||||
for i in [0, 1]:
|
for i in [0, 1]:
|
||||||
quiet = False
|
quiet = False
|
||||||
tracing = False
|
tracing = False
|
||||||
@ -159,4 +187,8 @@ if __name__ == "__main__":
|
|||||||
trace('trace with quiet on and trace on')
|
trace('trace with quiet on and trace on')
|
||||||
notice('notice with quiet on and trace on')
|
notice('notice with quiet on and trace on')
|
||||||
default = l
|
default = l
|
||||||
|
print '=-' * 40
|
||||||
|
print 'tail: %d' % (len(l.tail))
|
||||||
|
print l
|
||||||
|
print '=-' * 40
|
||||||
del l
|
del l
|
||||||
|
@ -60,7 +60,17 @@ class buildset:
|
|||||||
self.macros = copy.copy(macros)
|
self.macros = copy.copy(macros)
|
||||||
self.bset = bset
|
self.bset = bset
|
||||||
self.bset_pkg = '%s-%s-set' % (self.macros.expand('%{_target}'), self.bset)
|
self.bset_pkg = '%s-%s-set' % (self.macros.expand('%{_target}'), self.bset)
|
||||||
|
self.mail_header = ''
|
||||||
self.mail_report = ''
|
self.mail_report = ''
|
||||||
|
self.build_failed = False
|
||||||
|
|
||||||
|
def write_mail_header(self, text, prepend = False):
|
||||||
|
if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r':
|
||||||
|
text += os.linesep
|
||||||
|
if prepend:
|
||||||
|
self.mail_header = text + self.mail_header
|
||||||
|
else:
|
||||||
|
self.mail_header += text
|
||||||
|
|
||||||
def write_mail_report(self, text, prepend = False):
|
def write_mail_report(self, text, prepend = False):
|
||||||
if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r':
|
if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r':
|
||||||
@ -124,7 +134,7 @@ class buildset:
|
|||||||
r.setup()
|
r.setup()
|
||||||
r.introduction(_build.config.file_name())
|
r.introduction(_build.config.file_name())
|
||||||
r.config(_build.config, _build.opts, _build.macros)
|
r.config(_build.config, _build.opts, _build.macros)
|
||||||
self.mail_report += r.out
|
self.write_mail_report(r.out)
|
||||||
del r
|
del r
|
||||||
|
|
||||||
def root_copy(self, src, dst):
|
def root_copy(self, src, dst):
|
||||||
@ -278,7 +288,7 @@ class buildset:
|
|||||||
|
|
||||||
if self.opts.get_arg('--mail'):
|
if self.opts.get_arg('--mail'):
|
||||||
mail_report_subject = \
|
mail_report_subject = \
|
||||||
'Build Set: %s %s (%s)' % (self.bset,
|
'%s %s (%s)' % (self.bset,
|
||||||
self.macros.expand('%{_host}'),
|
self.macros.expand('%{_host}'),
|
||||||
datetime.datetime.now().ctime())
|
datetime.datetime.now().ctime())
|
||||||
|
|
||||||
@ -320,7 +330,13 @@ class buildset:
|
|||||||
else:
|
else:
|
||||||
raise error.general('invalid config type: %s' % (configs[s]))
|
raise error.general('invalid config type: %s' % (configs[s]))
|
||||||
except error.general, gerr:
|
except error.general, gerr:
|
||||||
self.write_mail_report(str(gerr))
|
self.build_failed = True
|
||||||
|
self.write_mail_header('')
|
||||||
|
self.write_mail_header('= ' * 40)
|
||||||
|
self.write_mail_header('Build FAILED: %s' % (b.name()))
|
||||||
|
self.write_mail_header('- ' * 40)
|
||||||
|
self.write_mail_header(str(log.default))
|
||||||
|
self.write_mail_header('- ' * 40)
|
||||||
if self.opts.keep_going():
|
if self.opts.keep_going():
|
||||||
print gerr
|
print gerr
|
||||||
if self.opts.always_clean():
|
if self.opts.always_clean():
|
||||||
@ -340,15 +356,12 @@ class buildset:
|
|||||||
for b in builds:
|
for b in builds:
|
||||||
del b
|
del b
|
||||||
except:
|
except:
|
||||||
os.environ['PATH'] = current_path
|
self.build_failed = True
|
||||||
raise
|
raise
|
||||||
|
finally:
|
||||||
end = datetime.datetime.now()
|
end = datetime.datetime.now()
|
||||||
|
|
||||||
os.environ['PATH'] = current_path
|
os.environ['PATH'] = current_path
|
||||||
|
|
||||||
build_time = str(end - start)
|
build_time = str(end - start)
|
||||||
|
|
||||||
if self.opts.get_arg('--mail'):
|
if self.opts.get_arg('--mail'):
|
||||||
to_addr = self.opts.get_arg('--mail-to')
|
to_addr = self.opts.get_arg('--mail-to')
|
||||||
if to_addr is not None:
|
if to_addr is not None:
|
||||||
@ -356,11 +369,16 @@ class buildset:
|
|||||||
else:
|
else:
|
||||||
to_addr = self.macros.expand('%{_mail_tools_to}')
|
to_addr = self.macros.expand('%{_mail_tools_to}')
|
||||||
log.notice('Mailing report: %s' % (to_addr))
|
log.notice('Mailing report: %s' % (to_addr))
|
||||||
self.write_mail_report('Build Time %s' % (build_time), True)
|
self.write_mail_header('Build Time %s' % (build_time), True)
|
||||||
|
self.write_mail_header('')
|
||||||
m = mailer.mail(self.opts)
|
m = mailer.mail(self.opts)
|
||||||
|
if self.build_failed:
|
||||||
|
pass_fail = 'FAILED '
|
||||||
|
else:
|
||||||
|
pass_fail = ''
|
||||||
|
mail_report_subject = 'Build: %s%s' % (pass_fail, mail_report_subject)
|
||||||
if not self.opts.dry_run():
|
if not self.opts.dry_run():
|
||||||
m.send(to_addr, mail_report_subject, self.mail_report)
|
m.send(to_addr, mail_report_subject, self.mail_header + self.mail_report)
|
||||||
|
|
||||||
log.notice('Build Set: Time %s' % (build_time))
|
log.notice('Build Set: Time %s' % (build_time))
|
||||||
|
|
||||||
def list_bset_cfg_files(opts, configs):
|
def list_bset_cfg_files(opts, configs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user