~jocave/checkbox/snappy-layout-hacks

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
#!/usr/bin/python
# This file is part of Checkbox.
#
# Copyright 2014 Canonical Ltd.
# Written by:
#   Brendan Donegan <brendan.donegan@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.

#
# Checkbox 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 Checkbox.  If not, see <http://www.gnu.org/licenses/>.

# Manage release of Checkbox packages
# ===================================
from __future__ import absolute_import, print_function

import sys

from argparse import ArgumentParser
from launchpadlib.launchpad import Launchpad
from lazr.restfulclient.errors import BadRequest

COPY_PACKAGES = ['checkbox', 'checkbox-certification', 'fwts']
COPY_SERIES = ['precise', 'quantal', 'raring', 'saucy', 'trusty']


def _get_distro_series(distro):
    # For now just get from precise forward but later on this
    # could be made more intelligent
    distro_series = []
    for series in COPY_SERIES:
        try:
            distro_series.append(distro.getSeries(name_or_version=series))
        except BadRequest:
            raise SystemExit("Unable to get info on series '{}' from "
                             "Launchpad - make sure this is a valid "
                             "series name.".format(series))
    return distro_series


def publish(args):
    lp = Launchpad.login_with(sys.argv[0], 'production')
    # Get all the series we want to publish for
    ubuntu = lp.distributions['ubuntu']
    distro_series = _get_distro_series(ubuntu)
    # Get the testing PPA and the stable PPA to copy packages
    testing_ppa = lp.people['checkbox-dev'].getPPAByName(name='testing')
    stable_ppa = (lp.people['hardware-certification']
                  .getPPAByName(name='public'))

    packages = (COPY_PACKAGES if not args.package else args.package)
    for package in packages:
        for series in distro_series:
            source_package = testing_ppa.getPublishedSources(
                source_name=package,
                distro_series=series)
            if source_package:
                src = source_package[0]
                try:
                    stable_ppa.syncSource(from_archive=testing_ppa.self_link,
                                          include_binaries=True,
                                          source_name=src.source_package_name,
                                          to_pocket='Release',
                                          version=src.source_package_version)
                except BadRequest as error:
                    raise SystemExit("Copy failed because {}".format(error))
                print("Copied {} version {} to stable PPA.".format(
                      src.source_package_name,
                      src.source_package_version))
            else:
                print("{} not published in testing PPA.".format(package))


def main():
    parser = ArgumentParser("Tool for managing the release of packages, "
                            "to the terms of the Canonical Hardware "
                            "Certification team.")
    subparsers = parser.add_subparsers()
    publish_parser = subparsers.add_parser('publish', help='Publish release')
    publish_parser.set_defaults(func=publish)
    publish_parser.add_argument('-p', '--package',
                                action='append',
                                help='Package to copy from testing to stable')

    args = parser.parse_args()
    return args.func(args)

if __name__ == "__main__":
    sys.exit(main())