-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcopr-rebuild
executable file
·137 lines (106 loc) · 4.57 KB
/
copr-rebuild
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
#!/usr/bin/python
from __future__ import print_function
import os
import datetime
import backends
from copr_rebuild_tools import config
from copr_rebuild_tools import Query, CoprQuery
from copr_rebuild_tools.copr_backend import package_version
from copr_rebuild_tools.args import parser
from configparser import NoSectionError
from copr.exceptions import CoprRequestException
class Actions(object):
def _query(self):
query = Query(backend.get_all()).valid()
chroots = self._chroots()
if conf["set"]:
print("Filter: set of input packages")
with open(os.path.join(os.path.dirname(args.config), conf["set"]), "r") as f:
query = query.values(f.read().split("\n")[:-1], key="name")
if args.new_packages or args.new_versions or args.based_on:
packagesq = CoprQuery(copr_backend.get_all())
if args.based_on:
print("Filter: only packages based on {0}".format(args.based_on))
based_on = packagesq.successful([args.based_on]).get()
query = query.succeeded(based_on)
packages = packagesq.successful(chroots).get()
if args.new_packages:
print("Filter: only new packages")
query = query.unsucessful(packages)
if args.new_versions:
print("Filter: only new versions of packages")
query = query.newer({package.name: package_version(package, chroots)
for package in packages})
if args.previous:
print("Filter: set offset to {}".format(args.previous))
if args.limit:
print("Filter: set limit to {}".format(args.limit))
print("------")
return query.order().offset(args.previous).limit(args.limit)
def _chroots(self):
enabled = copr_backend.enabled_chroots
if not copr_backend.chroots:
return enabled
chroots = copr_backend.chroots
wrong = [x for x in chroots if x not in enabled]
if not wrong:
return chroots
raise RuntimeError("Chroot {0} is not enabled in the {1} project"
.format(wrong[0], copr_backend.copr_full_name))
def action_submit(self):
copr_backend.submit_all(
self._query().get(),
sleep=conf["sleep"],
batch=conf["batch"],
batch_sleep=conf["batch-sleep"],
callback=lambda p: print("Submitting package: {}".format(p.name))
)
def action_print(self):
for entity in self._query().get():
print(entity.name)
def action_successful(self):
cquery = CoprQuery(copr_backend.get_all()).successful()
for package in cquery.get():
print(package.name)
def action_stats(self):
cquery = CoprQuery(copr_backend.get_all())
upstream = len(Query(backend.get_all()).get())
packages = len(cquery.get())
succeeded = len(cquery.successful().get())
last_package = cquery.successful().get()[-1]
last_build = last_package["builds"]["latest_succeeded"]
last_build_time = datetime.datetime.fromtimestamp(
last_build["started_on"]).strftime('%Y-%m-%d')
print("Project: {}".format(copr_backend.copr_full_name))
print("Copr config: {}".format(copr_backend.copr_config))
print("Total packages in upstream: {}".format(upstream))
print("Total packages in Copr: {}".format(packages))
print("Succeeded packages: {0} ({1:.1f}% of imported, "
"{2:.1f}% of total upstream)".format(
succeeded,
float(succeeded) / packages * 100,
float(succeeded) / upstream * 100))
print("Last successful package: {}".format(last_build_time))
args = conf = None
try:
args = parser.parse_args()
conf = config.read(args.config, args.backend)
factory = backends.get(backends.name(args, conf))
backend = factory[0](conf)
copr_backend = factory[1](conf)
actions = Actions()
getattr(actions, args.func)()
except NoSectionError:
print("No section [{}] in {} config".format(args.backend, args.config))
except backends.NoSuchBackend:
print("No such backend: {}".format(backends.name(args, conf)))
except CoprRequestException as ex:
print(ex)
print("Copr instance might be down?")
except RuntimeError as ex:
print("Error: {0}".format(ex))
except NotImplementedError as ex:
print("Backend {} is not implemented correctly".format(backends.name(args, conf)))
print(ex)
except KeyboardInterrupt:
pass