OLD | NEW |
1 import sys, re, traceback | 1 import sys, re, traceback |
2 | 2 |
3 # these statuses are ordered such that a status earlier in the list will | 3 |
4 # override a status later in a list (e.g. ERROR during a test will override | |
5 # prior GOOD results, but WARN will not override a FAIL) | |
6 job_statuses = ["TEST_NA", "ABORT", "ERROR", "FAIL", "WARN", "GOOD", "ALERT", | 4 job_statuses = ["TEST_NA", "ABORT", "ERROR", "FAIL", "WARN", "GOOD", "ALERT", |
7 "RUNNING", "NOSTATUS"] | 5 "RUNNING", "NOSTATUS"] |
8 | 6 |
9 def is_valid_status(status): | 7 def is_valid_status(status): |
10 if not re.match(r'(START|INFO|(END )?(' + '|'.join(job_statuses) + '))$', | 8 if not re.match(r'(START|INFO|(END )?('+'|'.join(job_statuses)+'))$', |
11 status): | 9 status): |
12 return False | 10 return False |
13 else: | 11 else: |
14 return True | 12 return True |
15 | 13 |
16 | 14 |
17 def is_failure(status): | |
18 if not is_valid_status(status): | |
19 return False | |
20 if status in ('START', 'INFO'): | |
21 return False | |
22 if status.startswith('END '): | |
23 status = status[len('END '):] | |
24 return job_statuses.index(status) <= job_statuses.index("FAIL") | |
25 | |
26 | |
27 def record(fn): | 15 def record(fn): |
28 """ | 16 """ |
29 Generic method decorator for logging calls under the | 17 Generic method decorator for logging calls under the |
30 assumption that return=GOOD, exception=FAIL. The method | 18 assumption that return=GOOD, exception=FAIL. The method |
31 determines parameters as: | 19 determines parameters as: |
32 subdir = self.subdir if it exists, or None | 20 subdir = self.subdir if it exists, or None |
33 operation = "class name"."method name" | 21 operation = "class name"."method name" |
34 status = None on GOOD, str(exception) on FAIL | 22 status = None on GOOD, str(exception) on FAIL |
35 The object using this method must have a job attribute | 23 The object using this method must have a job attribute |
36 for the logging to actually occur, otherwise the logging | 24 for the logging to actually occur, otherwise the logging |
(...skipping 29 matching lines...) Expand all Loading... |
66 try-except block. """ | 54 try-except block. """ |
67 def decorator(fn): | 55 def decorator(fn): |
68 def decorated_func(*args, **dargs): | 56 def decorated_func(*args, **dargs): |
69 try: | 57 try: |
70 fn(*args, **dargs) | 58 fn(*args, **dargs) |
71 except Exception: | 59 except Exception: |
72 print msg | 60 print msg |
73 traceback.print_exc(file=sys.stdout) | 61 traceback.print_exc(file=sys.stdout) |
74 return decorated_func | 62 return decorated_func |
75 return decorator | 63 return decorator |
OLD | NEW |