-
Notifications
You must be signed in to change notification settings - Fork 96
/
abichecker-dbcli.py
executable file
·131 lines (104 loc) · 4.11 KB
/
abichecker-dbcli.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python3
from pprint import pprint
import os, sys, re
import logging
import cmdln
import abichecker_dbmodel as DB
from abichecker_common import Config, CACHEDIR
from datetime import datetime, timedelta
class BoilderPlate(cmdln.Cmdln):
def __init__(self, *args, **kwargs):
cmdln.Cmdln.__init__(self, args, kwargs)
self.session = None
def get_optparser(self):
parser = cmdln.CmdlnOptionParser(self)
parser.add_option("--dry", action="store_true", help="dry run")
parser.add_option("--debug", action="store_true", help="debug output")
parser.add_option("--verbose", action="store_true", help="verbose")
return parser
def postoptparse(self):
logging.basicConfig()
self.logger = logging.getLogger(self.optparser.prog)
if (self.options.debug):
self.logger.setLevel(logging.DEBUG)
elif (self.options.verbose):
self.logger.setLevel(logging.INFO)
DB.Base.metadata.create_all(DB.db_engine())
self.session = DB.db_session()
def do_list(self, subcmd, opts, *args):
"""${cmd_name}: foo bar
${cmd_usage}
${cmd_option_list}
"""
for req in self.session.query(DB.Request).all():
print(f'{req.id} {req.state}')
for a in req.abichecks:
print(f' {a.dst_project} {a.dst_package} {a.result}')
for r in a.reports:
print(' %s %10s %-25s %s'%(r.id, r.arch, r.dst_lib, r.result))
def do_prune(self, subcmd, opts, days):
"""${cmd_name}: prune old records
${cmd_usage}
${cmd_option_list}
"""
oldest = datetime.today() - timedelta(days = 365)
requests = self.session.query(DB.Request).filter(DB.Request.t_updated < oldest)
for req in requests:
for a in req.abichecks:
self.logger.info('prune %s %s %s', req.id, a.dst_project, a.dst_package)
for r in a.reports:
fn = os.path.join(CACHEDIR, r.htmlreport)
if os.path.exists(fn):
self.logger.info('removing %s', r.htmlreport)
os.unlink(fn)
self.session.delete(req)
self.session.commit()
def do_log(self, subcmd, opts, request_id):
"""${cmd_name}: foo bar
${cmd_usage}
${cmd_option_list}
"""
request = self.session.query(DB.Request).filter(DB.Request.id == request_id).one()
for log in request.log:
print(log.line)
def do_delete(self, subcmd, opts, request_id):
"""${cmd_name}: foo bar
${cmd_usage}
${cmd_option_list}
"""
request = self.session.query(DB.Request).filter(DB.Request.id == request_id).one()
self.session.delete(request)
self.session.commit()
def do_recheck(self, subcmd, opts, request_id):
"""${cmd_name}: set request id to seen
${cmd_usage}
${cmd_option_list}
"""
request = self.session.query(DB.Request).filter(DB.Request.id == request_id).one()
logentry = DB.Log(request_id = request_id,
line = f'manually setting state to seen. previous state: {request.state} ({request.result})')
request.state = 'seen'
request.result = None
self.session.add(logentry)
self.session.commit()
@cmdln.option("--get", action="store_true", help="get some values")
@cmdln.option("--set", action="store_true", help="set some values")
@cmdln.option("--delete", action="store_true", help="delete some values")
def do_config(self, subcmd, opts, *args):
"""${cmd_name}: manage config file
${cmd_usage}
${cmd_option_list}
"""
config = Config(self.session)
if opts.set:
config.set(args[0], args[1])
elif opts.get:
print(config.get(args[0]))
elif opts.delete:
config.delete(args[0])
else:
for entry in config.settings():
print("%s=%s"%entry)
if __name__ == "__main__":
app = BoilderPlate()
sys.exit( app.main() )