/
fetch_openqa_bugs
executable file
·63 lines (49 loc) · 2.01 KB
/
fetch_openqa_bugs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + "/.."))
import json
import simplejson
import configparser
import requests
from openqa_client.client import OpenQA_Client
from openqa_bugfetcher.issues import IssueFetcher
CONFIGFILE = "/etc/openqa/bugfetcher.conf"
FORCE_BUGID = None
if len(sys.argv) in (2, 3):
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
print("Usage: %s [config] [bugid]" % sys.argv[0])
print("config will default to %s" % CONFIGFILE)
print("if bugid is specified, only update this bug (even before the time)")
sys.exit()
else:
CONFIGFILE = sys.argv[1]
if len(sys.argv) == 3:
FORCE_BUGID = sys.argv[2]
config = configparser.ConfigParser()
assert config.read(CONFIGFILE), "Config file '%s' can't be read" % CONFIGFILE
issue_fetcher = IssueFetcher(config)
client = OpenQA_Client(config["main"]["server"])
if FORCE_BUGID:
config["main"]["refresh_interval"] = "1"
bugs = client.openqa_request("GET", "bugs", {"refreshable": 1, "delta": config["main"]["refresh_interval"]})["bugs"]
if FORCE_BUGID:
bugs = {k: v for k, v in bugs.items() if v == FORCE_BUGID}
print("Found %i bugs to update" % len(bugs))
for bug_dbid, bugid in bugs.items():
print("%03s: %s" % (bug_dbid, bugid))
try:
issue = issue_fetcher.get_issue(bugid)
print(" -> title: %s" % issue.title)
print(" -> existing: %s" % issue.existing)
if FORCE_BUGID:
from pprint import pprint
pprint(issue.get_dict())
client.openqa_request("PUT", "bugs/%s" % bug_dbid, data=issue.get_dict())
except (AssertionError, requests.exceptions.ReadTimeout) as e:
print(" -> ERROR: %s" % e)
except (json.decoder.JSONDecodeError, simplejson.errors.JSONDecodeError) as e:
print(" -> ERROR: %s: JSON: %s…" % e, sys.last_value.doc[:50])
except Exception as e:
print(f"Exception occured while fetching {bugid}", file=sys.stderr)
raise e