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

« back to all changes in this revision

Viewing changes to cupstream2distro/publisher

  • 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
 
 
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
 
32
 
 
33
 
 
34
if __name__ == '__main__':
 
35
 
 
36
    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
 
37
 
 
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")
 
40
 
 
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)")
 
46
 
 
47
 
 
48
    args = parser.parse_args()
 
49
 
 
50
    series = args.series
 
51
    ppa = args.ppa
 
52
    if not series:
 
53
        series = os.getenv("series")
 
54
    if not ppa:
 
55
        ppa = os.getenv("ppa")
 
56
 
 
57
    if not ppa or not series:
 
58
        logging.info("ppa and series parameters are mandatory.")
 
59
        sys.exit(1)
 
60
 
 
61
    src_ppa = launchpadmanager.get_ppa(ppa)
 
62
    src_pocket = 'Release'
 
63
 
 
64
    # getting the archives and series objects
 
65
    is_sru = not launchpadmanager.is_series_current(series)
 
66
    if args.destppa:
 
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,
 
71
                      series=series))
 
72
    else:
 
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'
 
77
        copy_from_ppa = ppa
 
78
        copy_from_ppa_pocket = src_pocket
 
79
        if is_sru:
 
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
 
85
 
 
86
    manual_publish_cause_list = []
 
87
 
 
88
    all_packages_uploaded = packageinppamanager.get_all_packages_uploaded()
 
89
    if args.filter:
 
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))
 
97
 
 
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())
 
101
 
 
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)
 
106
 
 
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)
 
111
    else:
 
112
        package_to_copy = []
 
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
 
122
            if not args.destppa:
 
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)
 
126
        if package_to_copy:
 
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)