~rbalint/ubuntu-archive-tools/retry-intermittent

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

# Copyright (C) 2012  Canonical Ltd.
# Author: Colin Watson <cjwatson@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/>.

"""Branch a set of live filesystem configurations for the next release."""

from __future__ import print_function

import argparse

from launchpadlib.launchpad import Launchpad
import lazr.restfulclient.errors


def branch_livefses(args, owner):
    for livefs in list(args.launchpad.livefses):
        if (livefs.owner == owner and
                livefs.distro_series == args.source_series):
            print("Branching %s for %s ..." % (
                livefs.web_link, args.dest_series.name))
            try:
                new_livefs = args.launchpad.livefses.getByName(
                    owner=owner, distro_series=args.dest_series,
                    name=livefs.name)
            except lazr.restfulclient.errors.NotFound:
                new_livefs = args.launchpad.livefses.new(
                    owner=owner, distro_series=args.dest_series,
                    name=livefs.name, metadata=livefs.metadata)
            new_livefs.require_virtualized = livefs.require_virtualized
            new_livefs.relative_build_score = livefs.relative_build_score
            try:
                new_livefs.lp_save()
            except lazr.restfulclient.errors.Unauthorized:
                print("Could not devirt ppa, ask Launchpad team for support.")
                pass
            print("  %s" % new_livefs.web_link)


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-l", "--launchpad", dest="launchpad_instance", default="production")
    parser.add_argument(
        "-d", "--distribution", default="ubuntu", metavar="DISTRIBUTION",
        help="branch live filesystems for DISTRIBUTION")
    parser.add_argument(
        "--source-series",
        help="source series (default: current stable release)")
    parser.add_argument(
        "--dest-series",
        help="destination series (default: series in pre-release freeze)")
    parser.add_argument("owner", help="owner of live filesystems to copy")
    args = parser.parse_args()

    args.launchpad = Launchpad.login_with(
        "branch-livefses", args.launchpad_instance, version="devel")

    distro = args.launchpad.distributions[args.distribution]
    if args.source_series is None:
        args.source_series = [
            series for series in distro.series
            if series.status == "Current Stable Release"][0]
    else:
        args.source_series = distro.getSeries(
            name_or_version=args.source_series)
    if args.dest_series is None:
        args.dest_series = [
            series for series in distro.series
            if series.status == "Pre-release Freeze"][0]
    else:
        args.dest_series = distro.getSeries(
            name_or_version=args.dest_series)

    owner = args.launchpad.people[args.owner]

    branch_livefses(args, owner)


if __name__ == '__main__':
    main()