~larry-e-works/uci-engine/amqp-to-kombu

« back to all changes in this revision

Viewing changes to cupstream2distro/watch-ppa

  • Committer: Francis Ginther
  • Date: 2014-06-10 20:42:46 UTC
  • mto: This revision was merged to the branch mainline in revision 571.
  • Revision ID: francis.ginther@canonical.com-20140610204246-b1bsrik7nlcolqy7
Import lp:cupstream2distro rev 605.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
# Copyright (C) 2012 Canonical
 
4
#
 
5
# Authors:
 
6
#  Didier Roche
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify it under
 
9
# the terms of the GNU General Public License as published by the Free Software
 
10
# Foundation; version 3.
 
11
#
 
12
# This program is distributed in the hope that it will be useful, but WITHOUT
 
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
15
# details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License along with
 
18
# this program; if not, write to the Free Software Foundation, Inc.,
 
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
20
 
 
21
import argparse
 
22
import logging
 
23
import os
 
24
import sys
 
25
import time
 
26
 
 
27
from cupstream2distro import launchpadmanager, packageinppamanager
 
28
from cupstream2distro.packageinppa import PackageInPPA
 
29
from cupstream2distro.packagemanager import list_packages_info_in_str
 
30
from cupstream2distro.settings import TIME_BETWEEN_PPA_CHECKS, TIME_BEFORE_STOP_LOOKING_FOR_SOURCE_PUBLISH
 
31
 
 
32
 
 
33
if __name__ == '__main__':
 
34
 
 
35
    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
 
36
 
 
37
    parser = argparse.ArgumentParser(description="Watch for published package in a ppa",
 
38
                                     epilog="series and ppa options can be set by the corresponding long option name env variables as well")
 
39
 
 
40
    parser.add_argument("-s", "--series", help="Serie used to build the package")
 
41
    parser.add_argument("-p", "--ppa", help="PPA to publish this package to (for instance: 'ubuntu-unity/daily-build')")
 
42
    parser.add_argument("-a", "--arch", default=None, help="Only consider the provided target")
 
43
    parser.add_argument("-d", "--destppa", help="Consider this destppa instead of {series}-proposed")
 
44
 
 
45
    args = parser.parse_args()
 
46
 
 
47
    series = args.series
 
48
    ppa = args.ppa
 
49
    if not series:
 
50
        series = os.getenv("series")
 
51
    if not ppa:
 
52
        ppa = os.getenv("ppa")
 
53
    instance_info = "watching: {}, series: {}".format(ppa, series)
 
54
 
 
55
    if not series or not ppa:
 
56
        logging.error("Missing compulsory environment variables (ppa, series) {}".format(instance_info))
 
57
        sys.exit(1)
 
58
 
 
59
    # Prepare launchpad connection:
 
60
    lp_series = launchpadmanager.get_series(series)
 
61
    monitored_ppa = launchpadmanager.get_ppa(ppa)
 
62
    # getting the archives and series objects
 
63
    if args.destppa:
 
64
        dest_archive = launchpadmanager.get_ppa(args.destppa)
 
65
    else:
 
66
        dest_archive = launchpadmanager.get_ubuntu_archive()
 
67
    (available_archs_in_ppa, arch_all_arch, archs_to_eventually_ignore, archs_to_unconditionally_ignore) = launchpadmanager.get_available_all_and_ignored_archs(lp_series, monitored_ppa)
 
68
 
 
69
    # Collecting all packages that have been uploaded to the ppa
 
70
    packages_not_in_ppa = set()
 
71
    packages_building = set()
 
72
    packages_failed = set()
 
73
    for (source, version, tip_rev, target_branch) in packageinppamanager.get_all_packages_uploaded():
 
74
        packages_not_in_ppa.add(PackageInPPA(source, version, monitored_ppa, dest_archive, lp_series,
 
75
                                             available_archs_in_ppa, arch_all_arch, archs_to_eventually_ignore,
 
76
                                             archs_to_unconditionally_ignore))
 
77
 
 
78
    # Check the status regularly on all packages
 
79
    time_start_watching = time.time()
 
80
    while(packages_not_in_ppa or packages_building):
 
81
        logging.info("Checking the status for {}".format(list_packages_info_in_str(packages_not_in_ppa.union(packages_building))))
 
82
        packageinppamanager.update_all_packages_status(packages_not_in_ppa, packages_building, packages_failed, args.arch)
 
83
 
 
84
        # if we have some packages failing and no more build in progress, exit
 
85
        if packages_failed and not packages_building and not packages_not_in_ppa:
 
86
            logging.info("Some of the packages failed to build: {}".format(list_packages_info_in_str(packages_failed)))
 
87
            sys.exit(1)
 
88
 
 
89
        # if we have no package building or failing and have wait for long enough to have some package appearing in the ppa, exit
 
90
        if packages_not_in_ppa and not packages_building and ((time.time() - time_start_watching) > TIME_BEFORE_STOP_LOOKING_FOR_SOURCE_PUBLISH):
 
91
            logging.info("Some source packages were never published in the ppa: {}".format(list_packages_info_in_str(packages_not_in_ppa)))
 
92
            sys.exit(1)
 
93
 
 
94
        # exit if all is fine
 
95
        if not packages_not_in_ppa and not packages_building and not packages_failed:
 
96
            break
 
97
 
 
98
        time.sleep(TIME_BETWEEN_PPA_CHECKS)