~xnox/ubuntu-archive-tools/sru-report-autopkgtest-vomit

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
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2010, 2011, 2012  Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Look at the ISO tracker for currently tested builds, and generate
# publish-release commands for them.

# publish-release needs to be called as follows:

# for-project <derivative> publish-release <dir> <buildstamp> <type>
#   <releaseflag> <name>
#
#  <derivative>: ubuntu/kubuntu/edubuntu/xubuntu
#  <dir>: daily or daily-live, dir on cdimage.u.c./
#  <buildstamp>: e. g. 20070605.3; ubuntu-server/daily/<timestamp> for
#    server/netbook/etc.
#  <type>: desktop/alternate/server/serveraddon/src
#  <releaseflag>: yes/no/poolonly/named (should appear on releases.u.c.?)
#  <name>: name of the release (alpha-2, beta, etc.)

from __future__ import print_function

from collections import defaultdict
import optparse
import re
import sys

# See isotracker.py for setup instructions.
from isotracker import ISOTracker

milestone_name_re = re.compile('(Alpha|Beta|RC|Final|Pre-release)(?: (\d))?')
stable_name_re = re.compile('(Trusty|Xenial) (14|16)\.04\.\d+')

# do not warn about not being able to handle those
ignore_product_re = re.compile(
    'Netboot |Upgrade |Server EC2|Server Windows Azure|line-through')
# this identifies known builds
product_re = re.compile(
    '((?:|u|lu|ku|edu|xu|myth)buntu(?: studio|kylin| kylin| gnome| mate| budgie| next)?) '
    '(alternate|desktop|dvd|server(?: subiquity)?|mobile|base|active|wubi)(?: preinstalled)? '
    '(i386|amd64$|amd64\+mac|armel$|armel\+dove|armel\+omap$|armel\+omap4|'
    'armel\+ac100|armel\+mx5|armhf$|armhf\+omap$|armhf\+omap4|armhf\+ac100|'
    'armhf\+mx5|armhf\+nexus7|armhf\+raspi2|arm64|powerpc|ppc64el|s390x)', re.I)

# map an image type from the ISO tracker to a source directory for
# publish-release
type_map = {
    'desktop': 'daily-live',
    'alternate': 'daily',
    'src': 'source',
    'dvd': 'dvd',
    'mobile': 'daily-live',
    'active': 'daily-live',
    'server': 'daily',
    'base': 'daily',
    'wubi': 'wubi',
    'preinstalled-desktop': 'daily-preinstalled',
    'preinstalled-mobile': 'daily-preinstalled',
    'preinstalled-active': 'daily-preinstalled',
    'preinstalled-server': 'ubuntu-server/daily-preinstalled',
    'live-server': 'ubuntu-server/daily-live',
}


def parse_iso_tracker(opts):
    '''Get release builds information from ISO tracker.

    Return an info dictionary with the following keys:
    - build_map: projectname -> type -> build_stamp -> set(arches)
    - milestone_name: Milestone name (e. g. "Alpha 3")
    - milestone_code: publish-release milestone code (e. g. "alpha-3")
    - stable (optional): stable release name (e. g. "lucid")
    '''
    build_map = defaultdict(lambda: defaultdict(lambda: defaultdict(set)))
    ret = {'build_map': build_map, 'stable': None}

    # access the ISO tracker
    isotracker = ISOTracker(target=opts.target)

    # get current milestone
    if opts.milestone:
        ms = isotracker.get_milestone_by_name(opts.milestone)
    else:
        ms = isotracker.default_milestone()

    if ms.status_string != 'Testing':
        sys.stderr.write(
            'ERROR: Current milestone is not marked as "Testing"\n')
        sys.exit(1)

    m = milestone_name_re.search(ms.title)
    if m:
        # require number for alphas
        if m.group(1) != 'Alpha' or m.group(2):
            ret['milestone_name'] = ' '.join(
                [g for g in m.groups() if g is not None])
            ret['milestone_code'] = (
                ret['milestone_name'].lower().replace(' ', '-'))

        if 'milestone_name' not in ret:
            sys.stderr.write(
                "ERROR: Milestone '%s' isn't a valid target for publishing.\n"
                % ms.title)
            sys.exit(1)

        if ret['milestone_code'] == 'pre-release':
            ret['milestone_code'] = 'final'
    else:
        m = stable_name_re.search(ms.title)
        if not m:
            sys.stderr.write(
                "ERROR: Milestone '%s' isn't a valid target for publishing.\n"
                % ms.title)
            sys.exit(1)

        ret['milestone_name'] = m.group(0)
        ret['milestone_code'] = 'final'
        ret['stable'] = m.group(1).lower()

    # product name lookup
    products = {}
    for product in isotracker.tracker_products:
        products[product.id] = product.title

    # builds
    for build in isotracker.get_builds(ms):
        product = products[build.productid]

        # Start by skipping anything in the ignore list
        if ignore_product_re.search(product):
            continue

        if opts.prepublish or opts.include_active:
            ready_states = ('Active', 'Ready')
        else:
            ready_states = ('Ready',)
        if build.status_string not in ready_states:
            print('Ignoring %s which has status %s' %
                  (product, build.status_string))
            continue

        # Fail when finding an unknown product
        m = product_re.match(product)
        if not m:
            sys.stderr.write('ERROR: Cannot handle product %s\n' % product)
            sys.exit(1)

        project = m.group(1).lower().replace(' ', '')
        type = m.group(2).lower()
        arch = m.group(3).lower()

        if 'Server armhf+raspi2' in product:
            # This product is mislabeled in the tracker:
            type = 'preinstalled-%s' % type
        if 'Server Subiquity' in product:
            type = 'live-server'
            project = 'ubuntu'
        if 'Preinstalled' in product:
            type = 'preinstalled-%s' % type
        if project == 'kubuntu' and type == 'mobile':
            project = 'kubuntu-mobile'
        if project == 'kubuntu' and type == 'active':
            project = 'kubuntu-active'
            type = 'desktop'
        if project == 'ubuntu' and type == 'base':
            project = 'ubuntu-base'
        if project == 'ubuntugnome':
            project = 'ubuntu-gnome'
        if project == 'ubuntumate':
            project = 'ubuntu-mate'
        if project == 'ubuntubudgie':
            project = 'ubuntu-budgie'
        if project == 'lubuntunext':
            project = 'lubuntu-next'

        build_map[project][type][build.version].add(arch)

    return ret


def do_publish_release(opts, project, type, buildstamp, arches, milestone,
                       stable):
    '''Process a particular build publishing'''

    primary = set(('amd64', 'i386'))

    primary_arches = arches & primary
    ports_arches = arches - primary

    if 'alpha' in milestone:
        official = 'no'
    else:
        official = 'named'
        if (project in ('ubuntu',) and
                type in ('desktop', 'alternate', 'netbook', 'server',
                         'wubi') and
                primary_arches):
            official = 'yes'
    if opts.prepublish:
        if official == 'named':
            # no prepublication needed
            return
        elif official == 'yes':
            official = 'poolonly'

    # For pre-Natty: remove "official in ('yes', 'poolonly') and"
    if official in ('yes', 'poolonly') and primary_arches and ports_arches:
        do_publish_release(
            opts, project, type, buildstamp, primary_arches, milestone, stable)
        do_publish_release(
            opts, project, type, buildstamp, ports_arches, milestone, stable)
        return

    cmd = ['for-project', project, 'publish-release']
    if type != 'src':
        cmd.insert(0, "ARCHES='%s'" % ' '.join(sorted(arches)))
    if stable is not None:
        cmd.insert(0, "DIST=%s" % stable)

    if opts.dryrun:
        cmd.append('--dry-run')

    # dir and buildstamp arguments
    try:
        dir = type_map[type]
        # For pre-Natty: uncomment next two lines
        #if ports_arches:
        #    dir = re.sub(r'daily', 'ports/daily', dir)
        # Sometimes a daily build is treated as being one project (e.g.
        # ubuntu-netbook) but should be published under the auspices of
        # another project (e.g. ubuntu).  This is of course NOT AT ALL
        # CONFUSING.
        if project == 'ubuntu' and type == 'server':
            dir = 'ubuntu-server/%s' % dir
        elif project == 'ubuntu' and type == 'netbook' and primary_arches:
            dir = 'ubuntu-netbook/%s' % dir
        cmd.append(dir)
        cmd.append(buildstamp)
    except KeyError:
        print('ERROR: Cannot handle type', type, 'for', project,
              file=sys.stderr)
        return

    # type argument
    cmd.append(type)

    # releaseflag argument
    cmd.append(official)

    # name argument
    if milestone != 'final':
        cmd.append(milestone)

    print(' '.join(cmd))


def main():
    parser = optparse.OptionParser(usage='Usage: %prog [options]')
    parser.add_option('-m', '--milestone',
                      help='post to MILESTONE rather than the default')
    parser.add_option('-n', '--dry-run', dest='dryrun',
                      action='store_true', default=False,
                      help='Generate dry-run commands')
    parser.add_option('-p', '--prepublish', dest='prepublish',
                      action='store_true', default=False,
                      help='Pre-publish images to .pool')
    parser.add_option('-t', '--target', help='post to an alternate QATracker')
    parser.add_option('--include-active', action='store_true', default=False,
                      help='Always include Active (not Ready) images')
    opts, args = parser.parse_args()

    info = parse_iso_tracker(opts)

    print('\n## make backup:')
    print('cd ~/cdimage/; rm -rf www.prev; cp -al www www.prev; cd www')

    print('\n## publish images:')
    source_milestone = None
    for project, builds in info['build_map'].items():
        for type, buildstamps in builds.items():
            for buildstamp, arches in buildstamps.items():
                do_publish_release(opts, project, type, buildstamp, arches,
                                   info['milestone_code'], info['stable'])
                source_milestone = info['milestone_code']
        print()

    if source_milestone:
        do_publish_release(opts, 'ubuntu', 'src', 'current', set(),
                           source_milestone, info['stable'])

    if not opts.prepublish:
        print('\n## fix name in headers:')
        print("find full -path '*/%s*HEADER.html' | "
              "xargs sed -i 's/Daily Build/%s/'" %
              (info['milestone_code'], info['milestone_name']))

    print('\n## check changes against www.prev:')
    print('diff -u <(cd ../www.prev/full && find | sort) '
          '<(cd full && find | sort) | less')


if __name__ == '__main__':
    main()