forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbiarchtool.py
executable file
·405 lines (343 loc) · 15 KB
/
biarchtool.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/python
from xml.etree import cElementTree as ET
import sys
import cmdln
import logging
try:
from urllib.error import HTTPError
except ImportError:
# python 2.x
from urllib2 import HTTPError
import osc.core
import ToolBase
logger = logging.getLogger()
FACTORY = "openSUSE:Factory"
class BiArchTool(ToolBase.ToolBase):
def __init__(self, project):
ToolBase.ToolBase.__init__(self)
self.project = project
self.biarch_packages = None
self._has_baselibs = dict()
self.packages = []
self.arch = 'i586'
self.rdeps = None
self.package_metas = dict()
self.whitelist = {
'i586': set([
'bzr',
'git',
# _link to baselibs package
'libjpeg62-turbo',
'mercurial',
'subversion',
'ovmf'
]),
}
self.blacklist = {
'i586': set([
'belle-sip',
'release-notes-openSUSE',
'openSUSE-EULAs', # translate-toolkit
'skelcd-openSUSE',
'plasma5-workspace',
'patterns-base',
'patterns-fonts',
'patterns-rpm-macros',
'patterns-yast',
'000release-packages',
]),
}
def get_filelist(self, project, package, expand = False):
query = {}
if expand:
query['expand'] = 1
root = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, package], query)))
return [ node.get('name') for node in root.findall('entry') ]
def has_baselibs(self, package):
if package in self._has_baselibs:
return self._has_baselibs[package]
is_multibuild = False
srcpkgname = package
if ':' in package:
is_multibuild = True
srcpkgname = package.split(':')[0]
ret = False
files = self.get_filelist(self.project, srcpkgname)
if 'baselibs.conf' in files:
logger.debug('%s has baselibs', package)
if is_multibuild:
logger.warn('%s is multibuild and has baselibs. canot handle that!', package)
else:
ret = True
elif '_link' in files:
files = self.get_filelist(self.project, srcpkgname, expand = True)
if 'baselibs.conf' in files:
logger.warn('%s is linked to a baselibs package', package)
elif is_multibuild:
logger.warn('%s is multibuild', package)
self._has_baselibs[package] = ret
return ret
def is_biarch_recursive(self, package):
logger.debug(package)
if package in self.blacklist[self.arch]:
logger.debug('%s is blacklisted', package)
return False
if package in self.biarch_packages:
logger.debug('%s is known biarch package', package)
return True
if package in self.whitelist[self.arch]:
logger.debug('%s is whitelisted', package)
return True
r = self.has_baselibs(package)
if r:
return r
if package in self.rdeps:
for p in self.rdeps[package]:
r = self.is_biarch_recursive(p)
if r:
break
return r
def _init_biarch_packages(self):
if self.biarch_packages is None:
if ':Rings' in self.project:
self.biarch_packages = set()
else:
self.biarch_packages = set(self.meta_get_packagelist("%s:Rings:0-Bootstrap"%self.project))
self.biarch_packages |= set(self.meta_get_packagelist("%s:Rings:1-MinimalX"%self.project))
self._init_rdeps()
self.fill_package_meta()
def fill_package_meta(self):
url = self.makeurl(['search', 'package'], "match=[@project='%s']" % self.project)
root = ET.fromstring(self.cached_GET(url))
for p in root.findall('package'):
name = p.attrib['name']
self.package_metas[name] = p
def _init_rdeps(self):
if self.rdeps is not None:
return
self.rdeps = dict()
url = self.makeurl(['build', self.project, 'standard', self.arch, '_builddepinfo' ], {'view': 'revpkgnames'})
x = ET.fromstring(self.cached_GET(url))
for pnode in x.findall('package'):
name = pnode.get('name')
for depnode in pnode.findall('pkgdep'):
depname = depnode.text
if depname == name:
logger.warn('%s requires itself for build', name)
continue
self.rdeps.setdefault(name, set()).add(depname)
def select_packages(self, packages):
if packages == '__all__':
self.packages = self.meta_get_packagelist(self.project)
elif packages == '__latest__':
# only works when called in packagelists loop
#self.packages = self._filter_packages_by_time(self.latest_packages(self.project))
self.packages = self.latest_packages(self.project)
else:
self.packages = packages
# check when 000product was last changed, eg by packagelist
# generator. Yield only packges that got checked in after that
# point in time.
def _filter_packages_by_time(self, packages):
x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, '000product', '_history'], {'limit': '1'})))
producttime = int(x.find('./revision/time').text)
for pkg in packages:
try:
x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, pkg, '_history'], {'rev': '1'})))
# catch deleted packages
except HTTPError as e:
if e.code == 404:
continue
raise e
packagetime = int(x.find('./revision/time').text)
# if producttime > packagetime:
# continue
yield pkg
def remove_explicit_enable(self):
self._init_biarch_packages()
resulturl = self.makeurl(['build', self.project, '_result'])
result = ET.fromstring(self.cached_GET(resulturl))
packages = set()
for n in result.findall("./result[@arch='{}']/status".format(self.arch)):
if n.get('code') not in ('disabled', 'excluded'):
packages.add(n.get('package'))
for pkg in sorted(packages):
changed = False
logger.debug("processing %s", pkg)
if not pkg in self.package_metas:
logger.error("%s not found", pkg)
continue
pkgmeta = self.package_metas[pkg]
for build in pkgmeta.findall("./build"):
for n in build.findall("./enable[@arch='{}']".format(self.arch)):
logger.debug("disable %s", pkg)
build.remove(n)
changed = True
if changed:
try:
pkgmetaurl = self.makeurl(['source', self.project, pkg, '_meta'])
self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta))
if self.caching:
self._invalidate__cached_GET(pkgmetaurl)
except HTTPError as e:
logger.error('failed to update %s: %s', pkg, e)
def add_explicit_disable(self, wipebinaries=False):
self._init_biarch_packages()
resulturl = self.makeurl(['source', self.project])
result = ET.fromstring(self.cached_GET(resulturl))
for pkg in self.packages:
changed = False
logger.debug("processing %s", pkg)
if not pkg in self.package_metas:
logger.error("%s not found", pkg)
continue
pkgmeta = self.package_metas[pkg]
build = pkgmeta.findall("./build")
if not build:
logger.debug('disable %s for %s', pkg, self.arch)
bn = pkgmeta.find('build')
if bn is None:
bn = ET.SubElement(pkgmeta, 'build')
ET.SubElement(bn, 'disable', { 'arch' : self.arch })
changed = True
if changed:
try:
pkgmetaurl = self.makeurl(['source', self.project, pkg, '_meta'])
self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta))
if self.caching:
self._invalidate__cached_GET(pkgmetaurl)
if wipebinaries:
self.http_POST(self.makeurl(['build', self.project], {
'cmd' : 'wipe',
'arch': self.arch,
'package' : pkg }))
except HTTPError as e:
logger.error('failed to update %s: %s', pkg, e)
def enable_baselibs_packages(self, force=False, wipebinaries=False):
self._init_biarch_packages()
todo = dict()
for pkg in self.packages:
logger.debug("processing %s", pkg)
if not pkg in self.package_metas:
logger.error("%s not found", pkg)
continue
pkgmeta = self.package_metas[pkg]
is_enabled = None
is_disabled = None
has_baselibs = None
must_disable = None
changed = None
for n in pkgmeta.findall("./build/enable[@arch='{}']".format(self.arch)):
is_enabled = True
for n in pkgmeta.findall("./build/disable[@arch='{}']".format(self.arch)):
is_disabled = True
if force:
must_disable = False
if must_disable is None:
if self.is_biarch_recursive(pkg):
must_disable = False
else:
must_disable = True
if must_disable == False:
if is_disabled:
logger.info('enabling %s for %s', pkg, self.arch)
for build in pkgmeta.findall("./build"):
for n in build.findall("./disable[@arch='{}']".format(self.arch)):
build.remove(n)
changed = True
if changed == False:
logger.error('build tag not found in %s/%s!?', pkg, self.arch)
else:
logger.debug('%s already enabled for %s', pkg, self.arch)
elif must_disable == True:
if not is_disabled:
logger.info('disabling %s for %s', pkg, self.arch)
bn = pkgmeta.find('build')
if bn is None:
bn = ET.SubElement(pkgmeta, 'build')
ET.SubElement(bn, 'disable', { 'arch' : self.arch })
changed = True
else:
logger.debug('%s already disabled for %s', pkg, self.arch)
if is_enabled:
logger.info('removing explicit enable %s for %s', pkg, self.arch)
for build in pkgmeta.findall("./build"):
for n in build.findall("./enable[@arch='{}']".format(self.arch)):
build.remove(n)
changed = True
if changed == False:
logger.error('build tag not found in %s/%s!?', pkg, self.arch)
if changed:
todo[pkg] = pkgmeta
if todo:
logger.info("applying changes")
for pkg in sorted(todo.keys()):
pkgmeta = todo[pkg]
try:
pkgmetaurl = self.makeurl(['source', self.project, pkg, '_meta'])
self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta))
if self.caching:
self._invalidate__cached_GET(pkgmetaurl)
if wipebinaries and pkgmeta.find("./build/disable[@arch='{}']".format(self.arch)) is not None:
logger.debug("wiping %s", pkg)
self.http_POST(self.makeurl(['build', self.project], {
'cmd' : 'wipe',
'arch': self.arch,
'package' : pkg }))
except HTTPError as e:
logger.error('failed to update %s: %s', pkg, e)
class CommandLineInterface(ToolBase.CommandLineInterface):
def __init__(self, *args, **kwargs):
ToolBase.CommandLineInterface.__init__(self, args, kwargs)
def get_optparser(self):
parser = ToolBase.CommandLineInterface.get_optparser(self)
parser.add_option('-p', '--project', dest='project', metavar='PROJECT',
help='project to process (default: %s)' % FACTORY,
default = FACTORY)
return parser
def setup_tool(self):
tool = BiArchTool(self.options.project)
return tool
def _select_packages(self, all, packages):
if packages:
self.tool.select_packages(packages)
elif all:
self.tool.select_packages('__all__')
else:
self.tool.select_packages('__latest__')
@cmdln.option('-n', '--interval', metavar="minutes", type="int", help="periodic interval in minutes")
@cmdln.option('-a', '--all', action='store_true', help='process all packages')
@cmdln.option('-f', '--force', action='store_true', help='enable in any case')
@cmdln.option('--wipe', action='store_true', help='also wipe binaries')
def do_enable_baselibs_packages(self, subcmd, opts, *packages):
"""${cmd_name}: enable build for packages in Ring 0 or 1 or with
baselibs.conf
${cmd_usage}
${cmd_option_list}
"""
def work():
self._select_packages(opts.all, packages)
self.tool.enable_baselibs_packages(force=opts.force, wipebinaries=opts.wipe)
self.runner(work, opts.interval)
@cmdln.option('-a', '--all', action='store_true', help='process all packages')
def do_remove_explicit_enable(self, subcmd, opts, *packages):
"""${cmd_name}: remove all explicit enable tags from packages
${cmd_usage}
${cmd_option_list}
"""
self.tool.remove_explicit_enable()
@cmdln.option('-a', '--all', action='store_true', help='process all packages')
@cmdln.option('-n', '--interval', metavar="minutes", type="int", help="periodic interval in minutes")
@cmdln.option('--wipe', action='store_true', help='also wipe binaries')
def do_add_explicit_disable(self, subcmd, opts, *packages):
"""${cmd_name}: add explicit disable to all packages
${cmd_usage}
${cmd_option_list}
"""
def work():
self._select_packages(opts.all, packages)
self.tool.add_explicit_disable(wipebinaries=opts.wipe)
self.runner(work, opts.interval)
if __name__ == "__main__":
app = CommandLineInterface()
sys.exit( app.main() )