forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
biarchtool.py
executable file
·150 lines (126 loc) · 5.59 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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2015 SUSE Linux GmbH
# Copyright (c) 2016 SUSE LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from xml.etree import cElementTree as ET
import sys
import cmdln
import logging
import urllib2
import osc.core
import ToolBase
makeurl = osc.core.makeurl
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
def _init_biarch_packages(self):
if self.biarch_packages is None:
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))
def enable_baselibs_packages(self, packages, force=False):
self._init_biarch_packages()
for pkg in packages:
logger.debug("processing %s", pkg)
pkgmetaurl = makeurl(self.apiurl, ['source', self.project, pkg, '_meta'])
pkgmeta = ET.fromstring(self.cached_GET(pkgmetaurl))
is_enabled = None
is_disabled = None
has_baselibs = None
must_enable = None
changed = None
if force:
must_enable = True
for n in pkgmeta.findall("./build/enable[@arch='i586']"):
is_enabled = True
break
for n in pkgmeta.findall("./build/disable[@arch='i586']"):
is_disabled = True
break
if pkg in self.biarch_packages:
logger.debug('%s is known biarch package', pkg)
must_enable = True
else:
files = ET.fromstring(self.cached_GET(makeurl(self.apiurl, ['source', self.project, pkg])))
for n in files.findall("./entry[@name='baselibs.conf']"):
has_baselibs = True
logger.debug('%s has baselibs', pkg)
break
if has_baselibs:
must_enable = True
if must_enable:
if is_disabled:
logger.warn('%s should be enabled but is disabled', pkg)
if not is_enabled:
logger.info('enabling %s for biarch', pkg)
bn = pkgmeta.find('build')
if bn is None:
bn = ET.SubElement(pkgmeta, 'build')
ET.SubElement(bn, 'enable', { 'arch' : 'i586' })
changed = True
else:
if is_enabled:
logger.warn("%s enabled or biarch without need", pkg)
if changed:
try:
self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta))
if self.caching:
self._invalidate__cached_GET(pkgmetaurl)
except urllib2.HTTPError, 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 _packages(self, all, packages):
if not packages:
if all:
packages = self.tool.meta_get_packagelist(self.tool.project)
else:
packages = self.tool.latest_packages(self.tool.project)
return packages
@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')
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.tool.enable_baselibs_packages(self._packages(opts.all, packages), opts.force)
self.runner(work, opts.interval)
if __name__ == "__main__":
app = CommandLineInterface()
sys.exit( app.main() )
# vim: sw=4 et