~costamagnagianfranco/ubuntu-archive-tools/sync

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
#!/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

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.focal/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 = 'focal'

    (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.
    newSet.update(['gcc-10',])
    newSet.update(['gcc-10-cross',])
    newSet.update(['gcc-10-cross-ports',])
    # bootstrap for new lintian
    newSet.update(['libclass-xsaccessor-perl', 'libdigest-sha-perl'])
    # bootstrap for new glslang
    newSet.update(['spirv-tools',])
    # changed source package name for linux-libc-dev (ugh)
    newSet.update(['linux-5.4'])
    # 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
    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)