2
# -*- coding: utf-8 -*-
3
# Copyright (C) 2012 Canonical
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.
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
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
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
33
if __name__ == '__main__':
35
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
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")
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")
45
args = parser.parse_args()
50
series = os.getenv("series")
52
ppa = os.getenv("ppa")
53
instance_info = "watching: {}, series: {}".format(ppa, series)
55
if not series or not ppa:
56
logging.error("Missing compulsory environment variables (ppa, series) {}".format(instance_info))
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
64
dest_archive = launchpadmanager.get_ppa(args.destppa)
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)
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))
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)
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)))
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)))
95
if not packages_not_in_ppa and not packages_building and not packages_failed:
98
time.sleep(TIME_BETWEEN_PPA_CHECKS)