Richard Barnette | 9aec693 | 2016-06-03 13:31:46 -0700 | [diff] [blame] | 1 | # pylint: disable=missing-docstring |
| 2 | |
jadmanski | cefe265 | 2008-10-08 21:02:27 +0000 | [diff] [blame] | 3 | import sys, re, traceback |
mbligh | b05a6ac | 2007-11-26 21:46:54 +0000 | [diff] [blame] | 4 | |
Eric Li | 6f27d4f | 2010-09-29 10:55:17 -0700 | [diff] [blame] | 5 | # 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) |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 8 | job_statuses = ["TEST_NA", "ABORT", "ERROR", "FAIL", "WARN", "GOOD", "ALERT", |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 9 | "RUNNING", "NOSTATUS"] |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 10 | |
| 11 | def is_valid_status(status): |
Eric Li | 6f27d4f | 2010-09-29 10:55:17 -0700 | [diff] [blame] | 12 | if not re.match(r'(START|INFO|(END )?(' + '|'.join(job_statuses) + '))$', |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 13 | status): |
| 14 | return False |
| 15 | else: |
| 16 | return True |
mbligh | 302482e | 2008-05-01 20:06:16 +0000 | [diff] [blame] | 17 | |
| 18 | |
jadmanski | cefe265 | 2008-10-08 21:02:27 +0000 | [diff] [blame] | 19 | def 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 Sosa | c64fe51 | 2012-10-02 19:02:14 -0700 | [diff] [blame] | 27 | print >> sys.stderr, msg |
| 28 | traceback.print_exc(file=sys.stderr) |
jadmanski | cefe265 | 2008-10-08 21:02:27 +0000 | [diff] [blame] | 29 | return decorated_func |
| 30 | return decorator |