• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# pylint: disable=missing-docstring
2
3import sys, re, traceback
4
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)
8job_statuses = ["TEST_NA", "ABORT", "ERROR", "FAIL", "WARN", "GOOD", "ALERT",
9                "RUNNING", "NOSTATUS"]
10
11def is_valid_status(status):
12    if not re.match(r'(START|INFO|(END )?(' + '|'.join(job_statuses) + '))$',
13                    status):
14        return False
15    else:
16        return True
17
18
19def 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:
27                print >> sys.stderr, msg
28                traceback.print_exc(file=sys.stderr)
29        return decorated_func
30    return decorator
31