-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdbc.py
151 lines (114 loc) · 5.89 KB
/
dbc.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from components.db import MySQLDatabase
from components.providerbase import BaseProvider, INeedsLoggingProvider
from components.logging import LogLevel, logEntryExit
class DatabaseProvider(BaseProvider, INeedsLoggingProvider):
def __init__(self, database_config):
self.config = database_config
self.db = MySQLDatabase(self.config)
def _update_config(self, config):
self.db.update_config(config)
def updatebot_is_enabled(self):
return self.db.updatebot_is_enabled()
def check_database(self):
return self.db.check_database()
def delete_database(self):
return self.db.delete_database()
def get_configuration(self):
return self.db.get_configuration()
def get_all_statuses(self):
return self.db.get_all_statuses()
def get_all_outcomes(self):
return self.db.get_all_outcomes()
def get_all_jobs(self):
return self.db.get_all_jobs()
def get_all_try_runs(self):
return self.db.get_all_try_runs()
def get_all_phabricator_revisions(self):
return self.db.get_all_phabricator_revisions()
def get_all_jobs_for_library(self, library, jobtype):
jobs = self.db.get_all_jobs_for_library(library)
return [j for j in jobs if j.type == jobtype]
def get_all_jobs_for_library_by_name(self, library_name):
jobs = self.db.get_all_jobs()
return [j for j in jobs if library_name in j.library_shortname]
def get_job(self, library, new_version):
return self.db.get_job(library, new_version)
# Only used for testing purposes, in the real database, we don't delete records.
def delete_job(self, library=None, version=None, job_id=None):
return self.db.delete_job(library=library, version=version, job_id=job_id)
def create_job(self, jobtype, library, new_version, status, outcome, bug_id=0):
assert self.config['General']['ff-version'], "Called create_job but self.config['General']['ff-version'] was not provided"
return self.db.create_job(jobtype, library, new_version, self.config['General']['ff-version'], status, outcome, bug_id)
@logEntryExit
def update_job_status(self, existing_job, newstatus=None, newoutcome=None):
if newstatus:
existing_job.status = newstatus
if newoutcome:
existing_job.outcome = newoutcome
return self.db.update_job_status(existing_job)
def update_job_relinquish(self, existing_job):
existing_job.relinquished = True
return self.db.update_job_relinquish(existing_job)
def update_job_add_bug_id(self, existing_job, bug_id):
return self.db.update_job_add_bug_id(existing_job, bug_id)
def update_job_ff_versions(self, existing_job, ff_version_to_add):
return self.db.update_job_ff_versions(existing_job, ff_version_to_add)
def add_try_run(self, existing_job, try_revision, try_run_type):
return self.db.add_try_run(existing_job, try_revision, try_run_type)
def add_phab_revision(self, existing_job, phab_revision, phab_revision_type):
return self.db.add_phab_revision(existing_job, phab_revision, phab_revision_type)
def print(self, library_filter=None):
def get_column_widths(objects, columns):
widths = []
for c in columns:
thiswidth = len(c) + 2
for o in objects:
thislen = len(str(getattr(o, c))) + 2
if thislen > thiswidth:
thiswidth = thislen
widths.append(thiswidth)
return widths
def print_line(widths):
line = "+"
for w in widths:
line += "-" * w + "+"
self.logger.log(line, level=LogLevel.Debug)
def print_values(values, widths):
assert(len(values) == len(widths))
line = "| "
for i in range(len(values)):
line += str(values[i]).ljust(widths[i] - 2) + " | "
self.logger.log(line, level=LogLevel.Debug)
def print_object_values(obj, columns, widths):
print_values([getattr(obj, c) for c in columns], widths)
def print_objects(name, objects, columns):
widths = get_column_widths(objects, columns)
self.logger.log("", level=LogLevel.Debug)
self.logger.log("", level=LogLevel.Debug)
self.logger.log(name, level=LogLevel.Debug)
print_line(widths)
print_values(columns, widths)
print_line(widths)
for o in objects:
print_object_values(o, columns, widths)
print_line(widths)
config_columns = ['k', 'v']
print_objects("CONFIGURATION", self.get_configuration(), config_columns)
status_columns = ['id', 'name']
print_objects("STATUSES", self.get_all_statuses(), status_columns)
print_objects("OUTCOMES", self.get_all_outcomes(), status_columns)
job_columns = ['id', 'type', 'created', 'library_shortname', 'version',
'status', 'outcome', 'relinquished', 'bugzilla_id', 'ff_versions']
if library_filter:
jobs = self.get_all_jobs_for_library_by_name(library_filter)
else:
jobs = self.get_all_jobs()
print_objects("JOBS", jobs, job_columns)
try_run_columns = ['id', 'revision', 'job_id', 'purpose']
print_objects("TRY RUNS", [t for t in self.get_all_try_runs() if t.job_id in [j.id for j in jobs]], try_run_columns)
phab_revision_columns = ['id', 'revision', 'job_id', 'purpose']
print_objects("PHABRICATOR REVISIONS", [r for r in self.get_all_phabricator_revisions() if r.job_id in [j.id for j in jobs]], phab_revision_columns)