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
26
from cupstream2distro import launchpadmanager, packageinppamanager
27
from cupstream2distro.branchhandling import propose_branch_for_merging
28
from cupstream2distro.stacks import get_stack_packaging_change_status
29
from cupstream2distro.stack import Stack
30
from cupstream2distro.tools import generate_xml_artefacts, get_previous_distro_version_from_config, mark_project_as_published
31
from cupstream2distro.settings import PUBLISHER_ARTEFACTS_FILENAME, PACKAGE_LIST_RSYNC_FILENAME_FORMAT, SRU_PPA
34
if __name__ == '__main__':
36
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
38
parser = argparse.ArgumentParser(description="Watch for published package in a ppa. Create a xml artefact if manual copy is needed.",
39
epilog="series, ppa and JOB_NAME options can be set by the corresponding long option name env variables as well")
41
parser.add_argument("-f", "--force", action='store_true', help="Publish even if there are packaging change. Only done after manual reviews of the diff.")
42
parser.add_argument("-s", "--series", help="Serie used to build the package")
43
parser.add_argument("-p", "--ppa", help="PPA to publish this package to (for instance: 'ubuntu-unity/daily-build')")
44
parser.add_argument("-d", "--destppa", help="Consider this destppa instead of {series}-proposed")
45
parser.add_argument("--filter", nargs='*', help="Only consider those packages (space separated list)")
48
args = parser.parse_args()
53
series = os.getenv("series")
55
ppa = os.getenv("ppa")
57
if not ppa or not series:
58
logging.info("ppa and series parameters are mandatory.")
61
src_ppa = launchpadmanager.get_ppa(ppa)
62
src_pocket = 'Release'
64
# getting the archives and series objects
65
is_sru = not launchpadmanager.is_series_current(series)
67
dest_archive = launchpadmanager.get_ppa(args.destppa)
68
dest_pocket = 'Release'
69
logging.info("Direct copy from {src_archive} ({src_pocket}) to {dest_archive} ({dest_pocket}) for {series} series".format(
70
src_archive=src_ppa, src_pocket=src_pocket, dest_archive=dest_archive, dest_pocket=dest_pocket,
73
logging.info("Copy from {src_archive} ({src_pocket}) to {series} series in distro".format(
74
src_archive=src_ppa, src_pocket=src_pocket, series=series))
75
distro = launchpadmanager.get_ubuntu_archive()
76
distro_pocket = 'Proposed'
78
copy_from_ppa_pocket = src_pocket
80
logging.info("This upload is part of a SRU. The {} ppa will be used as a staging archive".format(SRU_PPA))
81
dest_archive = launchpadmanager.get_ppa(SRU_PPA)
82
copy_from_ppa = SRU_PPA
83
dest_pocket = 'Release'
84
copy_from_ppa_pocket = dest_pocket
86
manual_publish_cause_list = []
88
all_packages_uploaded = packageinppamanager.get_all_packages_uploaded()
90
logging.info("Restricted list of publication was requested: {}".format(args.filter))
91
for packages_info in all_packages_uploaded.copy():
92
if packages_info[0] not in args.filter:
93
logging.info("{} was ready to be published but not in the filtered list".format(packages_info[0]))
94
all_packages_uploaded.remove(packages_info)
95
# Generate global packaging change status
96
manual_publish_cause_list.extend(get_stack_packaging_change_status(all_packages_uploaded))
98
# Generate global stack status based on rdepends
99
stack = Stack.get_current_stack()
100
manual_publish_cause_list.extend(stack.generate_dep_status_message())
102
if stack.forced_manualpublish:
103
message = "Manual publishing mode for this stack forced. Components ready for release are: {}".format(all_packages_uploaded)
104
logging.info(message)
105
manual_publish_cause_list.append(message)
107
# we only go on manual publishing if we have something to publish
108
if not args.force and all_packages_uploaded and (manual_publish_cause_list or stack.forced_manualpublish):
109
logging.info("Don't upload the stack automatically.")
110
generate_xml_artefacts("Publisher", manual_publish_cause_list, PUBLISHER_ARTEFACTS_FILENAME)
113
for (source, version, tip_rev, branch) in all_packages_uploaded:
114
logging.info("Copying {} ({})".format(source, version))
115
propose_branch_for_merging(source, version, tip_rev, branch)
116
# direct upload or SRU staging ppa copy
117
if args.destppa or is_sru:
118
dest_archive.copyPackage(from_archive=src_ppa, from_pocket=src_pocket, from_series=series,
119
include_binaries=True, to_pocket=dest_pocket, to_series=series,
120
source_name=source, version=version)
121
# generate a file for distro that will be rsynced from another place
123
distro_version = get_previous_distro_version_from_config(source)
124
package_to_copy.append("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}".format(copy_from_ppa, copy_from_ppa_pocket, series, distro_pocket, series, source, version, distro_version))
125
mark_project_as_published(source, version)
127
package_list_rsync_file = PACKAGE_LIST_RSYNC_FILENAME_FORMAT.format(stack.stack_name, stack.release)
128
logging.info("Writing {} for being able to rsync from main machine".format(package_list_rsync_file))
129
with open(package_list_rsync_file, 'w') as f:
130
f.write("\n".join(package_to_copy))
131
generate_xml_artefacts("Publisher", [], PUBLISHER_ARTEFACTS_FILENAME)