|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import datetime |
| 4 | +from datetime import timedelta |
| 5 | +from datetime import datetime |
| 6 | +import os |
| 7 | +import time |
| 8 | +import re |
| 9 | +import xmlrpc.client |
| 10 | +import sys |
| 11 | +import yaml |
| 12 | +import json |
| 13 | +import argparse |
| 14 | + |
| 15 | +# retcode 0 = job complete |
| 16 | +# 1 = icomplete |
| 17 | +# other 2 |
| 18 | +ret = 2 |
| 19 | + |
| 20 | +parser = argparse.ArgumentParser() |
| 21 | +parser.add_argument("--lavauri", "-u", type=str, help="LAVA URI", default=None) |
| 22 | +parser.add_argument("--jobid", "-j", type=str, help="jobid", default=None) |
| 23 | +parser.add_argument("--wait", "-w", action="store_true", help="jobid", default=False) |
| 24 | +args = parser.parse_args() |
| 25 | + |
| 26 | +if args.jobid == None: |
| 27 | + print("Need jobid") |
| 28 | + sys.exit(2) |
| 29 | + |
| 30 | +server = xmlrpc.client.ServerProxy(args.lavauri, allow_none=True) |
| 31 | + |
| 32 | +wait = False |
| 33 | +if args.wait: |
| 34 | + wait = True |
| 35 | + |
| 36 | +while wait: |
| 37 | + try: |
| 38 | + job_state = server.scheduler.job_details(args.jobid) |
| 39 | + if job_state["status"] == "Complete": |
| 40 | + ret = 0 |
| 41 | + wait = False |
| 42 | + print(job_state["status"]) |
| 43 | + if job_state["status"] == "Incomplete": |
| 44 | + ret = 1 |
| 45 | + wait = False |
| 46 | + print(job_state["status"]) |
| 47 | + except xmlrpc.client.Fault: |
| 48 | + print("ERROR: no details") |
| 49 | + sys.exit(2) |
| 50 | + time.sleep(10) |
| 51 | + |
| 52 | +try: |
| 53 | + job_out_raw = server.scheduler.job_output(args.jobid) |
| 54 | + job_out = yaml.unsafe_load(job_out_raw.data) |
| 55 | +except xmlrpc.client.Fault: |
| 56 | + print("ERROR: no job output") |
| 57 | + sys.exit(2) |
| 58 | + |
| 59 | +flog = open("%s.log" % args.jobid, 'w') |
| 60 | +flogh = open("%s.html" % args.jobid, 'w') |
| 61 | +flogh.write('<html><head><link rel="stylesheet" href="/lava/log.css" type="text/css" /></head><body>') |
| 62 | +for line in job_out: |
| 63 | + #if "lvl" in line and (line["lvl"] == "info" or line["lvl"] == "debug" or line["lvl"] == "target" or line["lvl"] == "feedback"): |
| 64 | + for msg in line["msg"]: |
| 65 | + flog.write(msg) |
| 66 | + flogh.write(msg) |
| 67 | + flog.write("\n") |
| 68 | + flogh.write("<br>\n") |
| 69 | +flogh.write("</body></html>") |
| 70 | +flog.close() |
| 71 | +flogh.close() |
| 72 | + |
| 73 | +sys.exit(ret) |
0 commit comments