blob: f79f7de403cd9d61cea07492760c6aa0f4115e0e [file] [log] [blame]
Richard Barnette9aec6932016-06-03 13:31:46 -07001# pylint: disable=missing-docstring
2
jadmanskicefe2652008-10-08 21:02:27 +00003import sys, re, traceback
mblighb05a6ac2007-11-26 21:46:54 +00004
Eric Li6f27d4f2010-09-29 10:55:17 -07005# these statuses are ordered such that a status earlier in the list will
6# override a status later in a list (e.g. ERROR during a test will override
7# prior GOOD results, but WARN will not override a FAIL)
mbligh302482e2008-05-01 20:06:16 +00008job_statuses = ["TEST_NA", "ABORT", "ERROR", "FAIL", "WARN", "GOOD", "ALERT",
jadmanski74eebf32008-07-15 20:04:42 +00009 "RUNNING", "NOSTATUS"]
mbligh302482e2008-05-01 20:06:16 +000010
11def is_valid_status(status):
Eric Li6f27d4f2010-09-29 10:55:17 -070012 if not re.match(r'(START|INFO|(END )?(' + '|'.join(job_statuses) + '))$',
jadmanski0afbb632008-06-06 21:10:57 +000013 status):
14 return False
15 else:
16 return True
mbligh302482e2008-05-01 20:06:16 +000017
18
jadmanskicefe2652008-10-08 21:02:27 +000019def log_and_ignore_errors(msg):
20 """ A decorator for wrapping functions in a 'log exception and ignore'
21 try-except block. """
22 def decorator(fn):
23 def decorated_func(*args, **dargs):
24 try:
25 fn(*args, **dargs)
26 except Exception:
Chris Sosac64fe512012-10-02 19:02:14 -070027 print >> sys.stderr, msg
28 traceback.print_exc(file=sys.stderr)
jadmanskicefe2652008-10-08 21:02:27 +000029 return decorated_func
30 return decorator