~costamagnagianfranco/ubuntu-archive-tools/sync

« back to all changes in this revision

Viewing changes to update-i386-whitelist

  • Committer: Steve Langasek
  • Date: 2019-12-05 18:31:49 UTC
  • mfrom: (1251.1.3 update-i386-whitelist)
  • Revision ID: vorlon@debian.org-20191205183149-qpirxg8nzhpeqfpf
MergeĀ lp:~vorlon/ubuntu-archive-tools/update-i386-whitelist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
# Copyright (C) 2020  Canonical Ltd.
 
4
# Author: Steve Langasek <steve.langasek@canonical.com>
 
5
 
 
6
# This program is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; version 3 of the License.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
'''Synchronize the i386 source package whitelist in Launchpad with the output
 
19
of germinate.
 
20
 
 
21
USAGE:
 
22
    update-i386-whitelist [--dry-run] https://people.canonical.com/~ubuntu-archive/germinate-output/i386.focal/i386+build-depends.sources
 
23
'''
 
24
 
 
25
from launchpadlib.launchpad import Launchpad
 
26
import optparse
 
27
from urllib.request import urlopen
 
28
import sys
 
29
 
 
30
def get_sources_from_url(url):
 
31
    '''Download the germinate output and parse out the list of sources.
 
32
 
 
33
    Returns list of source package names.
 
34
    '''
 
35
    sources = []
 
36
 
 
37
    file = urlopen(url)
 
38
    for i in file:
 
39
        if i.startswith(b'Source') or i.startswith(b'---'):
 
40
            continue
 
41
        sources.append(i.decode('utf-8').split(' ',maxsplit=1)[0])
 
42
    return sources
 
43
 
 
44
def parse_options():
 
45
    '''Parse command line arguments.
 
46
 
 
47
    Return (options, source_package) tuple.
 
48
    '''
 
49
    parser = optparse.OptionParser(
 
50
        usage='Usage: %prog [--dry-run] https://people.canonical.com/~ubuntu-archive/germinate-output/i386.focal/i386+build-depends.sources')
 
51
    parser.add_option(
 
52
        "--dry-run", help="don't change launchpad, just report the delta",
 
53
        action="store_true")
 
54
    parser.add_option(
 
55
        "-s", dest="release", default=default_release, metavar="RELEASE",
 
56
        help="release (default: %s)" % default_release)
 
57
 
 
58
    (opts, args) = parser.parse_args()
 
59
 
 
60
    if len(args) != 1:
 
61
        parser.error('Need to specify a URL to sync from')
 
62
 
 
63
    return (opts, args[0])
 
64
 
 
65
 
 
66
if __name__ == '__main__':
 
67
 
 
68
    default_release = 'focal'
 
69
 
 
70
    (opts, url) = parse_options()
 
71
 
 
72
    launchpad = Launchpad.login_with('update-i386-whitelist',
 
73
                                     'production',
 
74
                                     version="devel")
 
75
    ubuntu = launchpad.distributions['ubuntu']
 
76
    series = ubuntu.getSeries(name_or_version=opts.release)
 
77
    archive = ubuntu.main_archive
 
78
 
 
79
    sources = get_sources_from_url(url)
 
80
 
 
81
    packageset = launchpad.packagesets.getByName(name='i386-whitelist',
 
82
                                                 distroseries=series)
 
83
    currentSet = set(packageset.getSourcesIncluded())
 
84
    newSet = set(sources)
 
85
    # hard-coded list of ppa-only additions; can maybe go away when
 
86
    # https://bugs.launchpad.net/launchpad/+bug/1855069 is fixed, but this is
 
87
    # also potentially useful for bootstrapping any additional packages into
 
88
    # the archive if needed.
 
89
    newSet.add(('gcc-10',))
 
90
    print("Additions:" )
 
91
    additions = list(newSet-currentSet)
 
92
    additions.sort()
 
93
    for i in additions:
 
94
        print(" * %s" % i)
 
95
    print("Removals:" )
 
96
    removals = list(currentSet-newSet)
 
97
    removals.sort()
 
98
    for i in removals:
 
99
        print(" * %s" % i)
 
100
    if opts.dry_run:
 
101
        print("--dry-run is set, doing nothing.")
 
102
        sys.exit(0)
 
103
 
 
104
    if additions:
 
105
        packageset.addSources(names=additions)
 
106
    if removals:
 
107
        packageset.removeSources(names=removals)