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
98
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Canonical
#
# Authors:
# Didier Roche
#
# 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.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import argparse
import logging
import os
import sys
import time
from cupstream2distro import launchpadmanager, packageinppamanager
from cupstream2distro.packageinppa import PackageInPPA
from cupstream2distro.packagemanager import list_packages_info_in_str
from cupstream2distro.settings import TIME_BETWEEN_PPA_CHECKS, TIME_BEFORE_STOP_LOOKING_FOR_SOURCE_PUBLISH
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
parser = argparse.ArgumentParser(description="Watch for published package in a ppa",
epilog="series and ppa options can be set by the corresponding long option name env variables as well")
parser.add_argument("-s", "--series", help="Serie used to build the package")
parser.add_argument("-p", "--ppa", help="PPA to publish this package to (for instance: 'ubuntu-unity/daily-build')")
parser.add_argument("-a", "--arch", default=None, help="Only consider the provided target")
parser.add_argument("-d", "--destppa", help="Consider this destppa instead of {series}-proposed")
args = parser.parse_args()
series = args.series
ppa = args.ppa
if not series:
series = os.getenv("series")
if not ppa:
ppa = os.getenv("ppa")
instance_info = "watching: {}, series: {}".format(ppa, series)
if not series or not ppa:
logging.error("Missing compulsory environment variables (ppa, series) {}".format(instance_info))
sys.exit(1)
# Prepare launchpad connection:
lp_series = launchpadmanager.get_series(series)
monitored_ppa = launchpadmanager.get_ppa(ppa)
# getting the archives and series objects
if args.destppa:
dest_archive = launchpadmanager.get_ppa(args.destppa)
else:
dest_archive = launchpadmanager.get_ubuntu_archive()
(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)
# Collecting all packages that have been uploaded to the ppa
packages_not_in_ppa = set()
packages_building = set()
packages_failed = set()
for (source, version, tip_rev, target_branch) in packageinppamanager.get_all_packages_uploaded():
packages_not_in_ppa.add(PackageInPPA(source, version, monitored_ppa, dest_archive, lp_series,
available_archs_in_ppa, arch_all_arch, archs_to_eventually_ignore,
archs_to_unconditionally_ignore))
# Check the status regularly on all packages
time_start_watching = time.time()
while(packages_not_in_ppa or packages_building):
logging.info("Checking the status for {}".format(list_packages_info_in_str(packages_not_in_ppa.union(packages_building))))
packageinppamanager.update_all_packages_status(packages_not_in_ppa, packages_building, packages_failed, args.arch)
# if we have some packages failing and no more build in progress, exit
if packages_failed and not packages_building and not packages_not_in_ppa:
logging.info("Some of the packages failed to build: {}".format(list_packages_info_in_str(packages_failed)))
sys.exit(1)
# if we have no package building or failing and have wait for long enough to have some package appearing in the ppa, exit
if packages_not_in_ppa and not packages_building and ((time.time() - time_start_watching) > TIME_BEFORE_STOP_LOOKING_FOR_SOURCE_PUBLISH):
logging.info("Some source packages were never published in the ppa: {}".format(list_packages_info_in_str(packages_not_in_ppa)))
sys.exit(1)
# exit if all is fine
if not packages_not_in_ppa and not packages_building and not packages_failed:
break
time.sleep(TIME_BETWEEN_PPA_CHECKS)
|