-
Notifications
You must be signed in to change notification settings - Fork 95
/
cli.py
113 lines (87 loc) · 3.56 KB
/
cli.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
# standard library
import logging
import os.path as opa
import json
import sys
# external dependency
from openqa_client.client import OpenQA_Client
# from package itself
import osc
from oqamaint.openqabot import OpenQABot
from oqamaint.opensuse import openSUSEUpdate
import ReviewBot
from oqamaint.suse import SUSEUpdate
class CommandLineInterface(ReviewBot.CommandLineInterface):
def __init__(self, *args, **kwargs):
ReviewBot.CommandLineInterface.__init__(self, *args, **kwargs)
self.clazz = OpenQABot
def get_optparser(self):
parser = ReviewBot.CommandLineInterface.get_optparser(self)
parser.add_option("--force", action="store_true",
help="recheck requests that are already considered done")
parser.add_option("--no-comment", dest='comment', action="store_false",
default=True, help="don't actually post comments to obs")
parser.add_option("--openqa", metavar='HOST', help="openqa api host")
parser.add_option(
"--data",
default=opa.abspath(
opa.dirname(
sys.argv[0])),
help="Path to metadata dir (data/*.json)")
return parser
def _load_metadata(self):
path = self.options.data
project = {}
with open(opa.join(path, "data/repos.json"), 'r') as f:
target = json.load(f)
with open(opa.join(path, "data/apimap.json"), 'r') as f:
api = json.load(f)
with open(opa.join(path, "data/incidents.json"), 'r') as f:
for i, j in json.load(f).items():
if i.startswith('SUSE'):
project[i] = SUSEUpdate(j)
elif i.startswith('openSUSE'):
project[i] = openSUSEUpdate(j)
else:
raise Exception("Unknown openQA", i)
return project, target, api
def postoptparse(self):
# practically quiet
level = logging.WARNING
if (self.options.debug):
level = logging.DEBUG
elif (self.options.verbose):
# recomended variant
level = logging.INFO
self.logger = logging.getLogger(self.optparser.prog)
self.logger.setLevel(level)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(levelname)-2s: %(message)s')
handler.setFormatter(formatter)
self.logger.addHandler(handler)
osc.conf.get_config(override_apiurl=self.options.apiurl)
if (self.options.osc_debug):
osc.conf.config['debug'] = 1
self.checker = self.setup_checker()
if self.options.config:
self.checker.load_config(self.options.config)
if self.options.review_mode:
self.checker.review_mode = self.options.review_mode
if self.options.fallback_user:
self.checker.fallback_user = self.options.fallback_user
if self.options.fallback_group:
self.checker.fallback_group = self.options.fallback_group
def setup_checker(self):
bot = ReviewBot.CommandLineInterface.setup_checker(self)
if self.options.force:
bot.force = True
bot.do_comments = self.options.comment
if not self.options.openqa:
raise osc.oscerr.WrongArgs("missing openqa url")
bot.openqa = OpenQA_Client(server=self.options.openqa)
project, target, api = self._load_metadata()
bot.api_map = api
bot.tgt_repo = target
bot.project_settings = project
return bot