~ubuntu-archive/ubuntu-archive-tools/trunk

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
#!/usr/bin/python3

# Copyright (C) 2020  Canonical Ltd.
# Author: Steve Langasek <steve.langasek@canonical.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/>.

'''Synchronize the i386 source package whitelist in Launchpad with the output
of germinate.

USAGE:
    update-i386-whitelist [--dry-run] https://people.canonical.com/~ubuntu-archive/germinate-output/i386.focal/i386+build-depends.sources
'''

from launchpadlib.launchpad import Launchpad
import optparse
from urllib.request import urlopen
import sys
import glob

def get_sources_from_url(url):
    '''Download the germinate output and parse out the list of sources.

    Returns list of source package names.
    '''
    sources = []

    file = urlopen(url)
    for i in file:
        if i.startswith(b'Source') or i.startswith(b'---'):
            continue
        sources.append(i.decode('utf-8').split(' ',maxsplit=1)[0])
    return sources

def parse_options():
    '''Parse command line arguments.

    Return (options, source_package) tuple.
    '''
    parser = optparse.OptionParser(
        usage='Usage: %prog [--dry-run] https://people.canonical.com/~ubuntu-archive/germinate-output/i386.hirsute/i386+build-depends.sources')
    parser.add_option(
        "--dry-run", help="don't change launchpad, just report the delta",
        action="store_true")
    parser.add_option(
        "-s", dest="release", default=default_release, metavar="RELEASE",
        help="release (default: %s)" % default_release)

    (opts, args) = parser.parse_args()

    if len(args) != 1:
        parser.error('Need to specify a URL to sync from')

    return (opts, args[0])


if __name__ == '__main__':

    default_release = 'hirsute'

    (opts, url) = parse_options()

    launchpad = Launchpad.login_with('update-i386-whitelist',
                                     'production',
                                     version="devel")
    ubuntu = launchpad.distributions['ubuntu']
    series = ubuntu.getSeries(name_or_version=opts.release)
    archive = ubuntu.main_archive

    sources = get_sources_from_url(url)

    packageset = launchpad.packagesets.getByName(name='i386-whitelist',
                                                 distroseries=series)
    currentSet = set(packageset.getSourcesIncluded())
    newSet = set(sources)
    # hard-coded list of ppa-only additions; can maybe go away when
    # https://bugs.launchpad.net/launchpad/+bug/1855069 is fixed, but this is
    # also potentially useful for bootstrapping any additional packages into
    # the archive if needed.

    # needed to bootstrap openjdk-N
    newSet.update(['openjdk-12'])
    newSet.update(['openjdk-13'])
    newSet.update(['openjdk-14'])
    newSet.update(['openjdk-15'])
    newSet.update(['openjdk-16'])
    newSet.update(['openjdk-17'])
    newSet.update(['openjdk-8'])

    # part of python2.7
    newSet.update(['python-stdlib-extensions'])

    # focal-only
    newSet.update(['python3.9'])

    # hirsute-only
    newSet.update(['libpadwalker-perl'])
    newSet.update(['gcc-11', 'gcc-11-cross'])
    newSet.update(['libdeflate']) # needed by tiff
    newSet.update(['llvm-toolchain-12'])

    # bootstrap new openjdk-17
    newSet.update(['rpm','p7zip'])

    # https://discourse.ubuntu.com/t/community-process-for-32-bit-compatibility/12598/97
    if opts.release in ('focal','groovy'):
        newSet.update(['libopenaptx'])

    # we get the wrong answer from germinate about a source package's
    # whitelisting when the package provides both Arch: any and Arch: all
    # binaries but we actually only want the Arch: all ones.  Rather than
    # fix this in germinate, for now just manually exclude the packages
    # we've found that have this problem.
    for pkg in ('frei0r', 'xorg', 'ubuntu-drivers-common'):
        try:
            newSet.remove(pkg)
        except KeyError:
            pass

    nv_list = []
    for nv_flavour in range(440, 1005, 5):
        nvidia_pkg = 'nvidia-graphics-drivers-%s' % (nv_flavour)
        nv_list.append(nvidia_pkg)
        nvidia_pkg += '-server'
        nv_list.append(nvidia_pkg)
    newSet.update(nv_list)

    print("Additions:" )
    additions = list(newSet-currentSet)
    additions.sort()
    for i in additions:
        print(" * %s" % i)
    print("Removals:" )
    removals = list(currentSet-newSet)
    removals.sort()
    for i in removals:
        print(" * %s" % i)
    if opts.dry_run:
        print("--dry-run is set, doing nothing.")
        sys.exit(0)

    if additions or removals:
        print("Commit changes to the packageset? [yN] ", end="")
        sys.stdout.flush()
        response = sys.stdin.readline()
        if not response.strip().lower().startswith('y'):
            sys.exit(1)

    if additions:
        packageset.addSources(names=additions)
    if removals:
        packageset.removeSources(names=removals)