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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#!/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
from cupstream2distro import launchpadmanager, packageinppamanager
from cupstream2distro.branchhandling import propose_branch_for_merging
from cupstream2distro.stacks import get_stack_packaging_change_status
from cupstream2distro.stack import Stack
from cupstream2distro.tools import generate_xml_artefacts, get_previous_distro_version_from_config, mark_project_as_published
from cupstream2distro.settings import PUBLISHER_ARTEFACTS_FILENAME, PACKAGE_LIST_RSYNC_FILENAME_FORMAT, SRU_PPA
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. Create a xml artefact if manual copy is needed.",
epilog="series, ppa and JOB_NAME options can be set by the corresponding long option name env variables as well")
parser.add_argument("-f", "--force", action='store_true', help="Publish even if there are packaging change. Only done after manual reviews of the diff.")
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("-d", "--destppa", help="Consider this destppa instead of {series}-proposed")
parser.add_argument("--filter", nargs='*', help="Only consider those packages (space separated list)")
args = parser.parse_args()
series = args.series
ppa = args.ppa
if not series:
series = os.getenv("series")
if not ppa:
ppa = os.getenv("ppa")
if not ppa or not series:
logging.info("ppa and series parameters are mandatory.")
sys.exit(1)
src_ppa = launchpadmanager.get_ppa(ppa)
src_pocket = 'Release'
# getting the archives and series objects
is_sru = not launchpadmanager.is_series_current(series)
if args.destppa:
dest_archive = launchpadmanager.get_ppa(args.destppa)
dest_pocket = 'Release'
logging.info("Direct copy from {src_archive} ({src_pocket}) to {dest_archive} ({dest_pocket}) for {series} series".format(
src_archive=src_ppa, src_pocket=src_pocket, dest_archive=dest_archive, dest_pocket=dest_pocket,
series=series))
else:
logging.info("Copy from {src_archive} ({src_pocket}) to {series} series in distro".format(
src_archive=src_ppa, src_pocket=src_pocket, series=series))
distro = launchpadmanager.get_ubuntu_archive()
distro_pocket = 'Proposed'
copy_from_ppa = ppa
copy_from_ppa_pocket = src_pocket
if is_sru:
logging.info("This upload is part of a SRU. The {} ppa will be used as a staging archive".format(SRU_PPA))
dest_archive = launchpadmanager.get_ppa(SRU_PPA)
copy_from_ppa = SRU_PPA
dest_pocket = 'Release'
copy_from_ppa_pocket = dest_pocket
manual_publish_cause_list = []
all_packages_uploaded = packageinppamanager.get_all_packages_uploaded()
if args.filter:
logging.info("Restricted list of publication was requested: {}".format(args.filter))
for packages_info in all_packages_uploaded.copy():
if packages_info[0] not in args.filter:
logging.info("{} was ready to be published but not in the filtered list".format(packages_info[0]))
all_packages_uploaded.remove(packages_info)
# Generate global packaging change status
manual_publish_cause_list.extend(get_stack_packaging_change_status(all_packages_uploaded))
# Generate global stack status based on rdepends
stack = Stack.get_current_stack()
manual_publish_cause_list.extend(stack.generate_dep_status_message())
if stack.forced_manualpublish:
message = "Manual publishing mode for this stack forced. Components ready for release are: {}".format(all_packages_uploaded)
logging.info(message)
manual_publish_cause_list.append(message)
# we only go on manual publishing if we have something to publish
if not args.force and all_packages_uploaded and (manual_publish_cause_list or stack.forced_manualpublish):
logging.info("Don't upload the stack automatically.")
generate_xml_artefacts("Publisher", manual_publish_cause_list, PUBLISHER_ARTEFACTS_FILENAME)
else:
package_to_copy = []
for (source, version, tip_rev, branch) in all_packages_uploaded:
logging.info("Copying {} ({})".format(source, version))
propose_branch_for_merging(source, version, tip_rev, branch)
# direct upload or SRU staging ppa copy
if args.destppa or is_sru:
dest_archive.copyPackage(from_archive=src_ppa, from_pocket=src_pocket, from_series=series,
include_binaries=True, to_pocket=dest_pocket, to_series=series,
source_name=source, version=version)
# generate a file for distro that will be rsynced from another place
if not args.destppa:
distro_version = get_previous_distro_version_from_config(source)
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))
mark_project_as_published(source, version)
if package_to_copy:
package_list_rsync_file = PACKAGE_LIST_RSYNC_FILENAME_FORMAT.format(stack.stack_name, stack.release)
logging.info("Writing {} for being able to rsync from main machine".format(package_list_rsync_file))
with open(package_list_rsync_file, 'w') as f:
f.write("\n".join(package_to_copy))
generate_xml_artefacts("Publisher", [], PUBLISHER_ARTEFACTS_FILENAME)
|