forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_baselibs.py
executable file
·138 lines (116 loc) · 5.57 KB
/
scan_baselibs.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
#!/usr/bin/python3
import argparse
import logging
import os
import re
import sys
from xml.etree import cElementTree as ET
from urllib.error import HTTPError
import osc.conf
import osc.core
from osclib.conf import Config
OPENSUSE = 'openSUSE:Factory'
PACKAGEFILE = 'packagelist_without_32bitRPMs_imported'
makeurl = osc.core.makeurl
http_GET = osc.core.http_GET
http_POST = osc.core.http_POST
class ScanBaselibs(object):
def __init__(self, project, repository, verbose, wipebinaries):
self.project = project
self.verbose = verbose
self.repo = repository
self.wipebinaries = wipebinaries
self.apiurl = osc.conf.config['apiurl']
self.debug = osc.conf.config['debug']
Config(self.apiurl, OPENSUSE)
self.config = osc.conf.config[OPENSUSE]
# TODO: would be better to parse baselibs.conf to know which arch was blocked
self.package_whitelist = list(set(self.config.get('allowed-missing-32bit-binaries-importing', '').split(' ')))
def get_packages(self, project):
"""Return the list of packages in a project."""
query = {'expand': 1}
root = ET.parse(http_GET(makeurl(self.apiurl, ['source', project], query=query))).getroot()
packages = [i.get('name') for i in root.findall('entry')]
return packages
def package_has_baselibs(self, project, package):
query = {'expand': 1}
root = ET.parse(http_GET(makeurl(self.apiurl, ['source', project, package], query=query))).getroot()
files = [i.get('name') for i in root.findall('entry') if i.get('name') == 'baselibs.conf']
if len(files):
return True
return False
def package_has_32bit_binaries(self, project, repo, package):
query = { 'package': package,
'repository': repo,
'arch': 'x86_64',
'multibuild': 1,
'view': 'binarylist' }
root = ET.parse(http_GET(makeurl(self.apiurl, ['build', project, '_result'], query = query))).getroot()
# assume 32bit importing RPMs can be appeared in multibuild-ed package
for binarylist in root.findall('./result/binarylist'):
binaries = [i.get('filename') for i in binarylist.findall('binary') if i.get('filename').startswith('::import::i586::')]
if len(binaries):
return True
return False
def check_package_baselibs(self, project, repo, wipebinaries):
"""Main method"""
# get souce packages from target
if self.verbose:
print('Gathering the package list from %s' % project)
packages = self.get_packages(project)
with open(os.getcwd() + '/' + PACKAGEFILE, "a") as f:
for pkg in packages:
if self.package_has_baselibs(project, pkg) and pkg not in self.package_whitelist:
if not self.package_has_32bit_binaries(project, repo, pkg):
f.write("%s\n" % pkg)
if self.verbose:
print('%s has baselibs.conf but 32bit RPMs does not exist on 64bit\'s build result.' % pkg)
if wipebinaries:
http_POST(makeurl(self.apiurl, ['build', project], {
'cmd': 'wipe',
'repository': repo,
'package': pkg,
'arch': 'i586' }))
f.close()
def scan(self):
"""Main method"""
try:
osc.core.show_project_meta(self.apiurl, self.project)
except HTTPError as e:
if e.code == 404:
print("Project %s does not exist!" % self.project)
return
print('Scanning...')
if os.path.isfile(os.getcwd() + '/' + PACKAGEFILE):
os.remove(os.getcwd() + '/' + PACKAGEFILE)
self.check_package_baselibs(self.project, self.repo, self.wipebinaries)
print('Done')
def main(args):
# Configure OSC
osc.conf.get_config(override_apiurl=args.apiurl)
osc.conf.config['debug'] = args.debug
uc = ScanBaselibs(args.project, args.repository, args.verbose, args.wipebinaries)
uc.scan()
if __name__ == '__main__':
description = 'Verifying 32bit binaries has imported properly towards a project, ' \
'if the 32bit binaries were not exist then wipes 32bit build result.' \
'This script is now only works on x86_64/i586'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-A', '--apiurl', metavar='URL', help='API URL')
parser.add_argument('-d', '--debug', action='store_true',
help='print the information useful for debugging')
parser.add_argument('-p', '--project', dest='project', metavar='PROJECT',
help='the project to check (default: %s)' % OPENSUSE,
default=OPENSUSE)
parser.add_argument('-r', '--repository', dest='repository', metavar='REPOSITORY',
help='the repository of binaries (default: %s)' % 'standard',
default='standard')
parser.add_argument('-v', '--verbose', action='store_true',
help='show the verbose information')
parser.add_argument('-w', '--wipebinaries', action='store_true', default=False,
help='wipe binaries found without imported 32bit RPMs')
args = parser.parse_args()
# Set logging configuration
logging.basicConfig(level=logging.DEBUG if args.debug
else logging.INFO)
sys.exit(main(args))