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

« back to all changes in this revision

Viewing changes to cupstream2distro/copy2distro

  • 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 time
 
25
 
 
26
from cupstream2distro import launchpadmanager, packagemanager
 
27
from cupstream2distro.stacks import get_stack_files_to_sync, get_allowed_projects
 
28
from cupstream2distro.settings import OLD_STACK_DIR, SILO_NAME_LIST, SILO_BUILDPPA_SCHEME
 
29
 
 
30
if __name__ == '__main__':
 
31
 
 
32
    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
 
33
 
 
34
    parser = argparse.ArgumentParser(description="Rsync all availables packages to be copied to the ubuntu archive from a ppa")
 
35
    parser.add_argument("--no-filter", action='store_true', help="Don't filter list (case coming from silos where there is no more filtering needed)")
 
36
    args = parser.parse_args()
 
37
 
 
38
    launchpadmanager.get_launchpad(use_cred_file=None)
 
39
    dest_archive = launchpadmanager.get_ubuntu_archive()
 
40
 
 
41
    logging.debug("Check if there are some stacks to synchronize")
 
42
    for (file, release) in get_stack_files_to_sync():
 
43
        logging.info("Found {}".format(file))
 
44
        with open(file) as f:
 
45
            for line in f.readlines():
 
46
                (ppa, src_pocket, from_series, dest_pocket, to_series, source, version, distro_version_at_prepare_time, sponsored_name) = line.strip().split("\t")
 
47
                logging.debug("Received copy request for {} ({}), from {} ({}, {}), to Ubuntu ({}, {}) by {}".format(source, version, ppa, from_series,
 
48
                                                                                                                     src_pocket, to_series, dest_pocket,
 
49
                                                                                                                     sponsored_name))
 
50
                if ppa not in [SILO_BUILDPPA_SCHEME.format(ppa_name) for ppa_name in SILO_NAME_LIST]:
 
51
                    logging.error("Rejecting {} as {} isn't in the allowed ppa list.".format(source, ppa))
 
52
                    continue
 
53
 
 
54
                try:
 
55
                    sponsored = launchpadmanager.get_person(sponsored_name)
 
56
                except KeyError:
 
57
                    logging.error("{} isn't a valid launchpad user name. Can't copy that package".format(sponsored_name))
 
58
                    continue
 
59
 
 
60
                if not args.no_filter and not source in get_allowed_projects(release):
 
61
                    logging.error("The project {} is not in the allowed stack to be copied to distro. Rejecting.".format(source))
 
62
                    continue
 
63
 
 
64
                distro_version = packagemanager.get_current_version_for_series(source, to_series)
 
65
                if distro_version != distro_version_at_prepare_time:
 
66
                    message = ("A manual upload of {} ({}) to distro has been done after the current daily release was prepared (it was at {}) at this time."
 
67
                               "Ignore uploading {}.".format(source, distro_version, distro_version_at_prepare_time, version))
 
68
                    logging.error(message)
 
69
                    continue
 
70
 
 
71
                src_ppa = launchpadmanager.get_ppa(ppa)
 
72
 
 
73
                dest_archive.copyPackage(from_archive=src_ppa, from_pocket=src_pocket, from_series=from_series,
 
74
                                         include_binaries=True, to_pocket=dest_pocket, to_series=to_series,
 
75
                                         source_name=source, version=version,
 
76
                                         sponsored=sponsored)
 
77
            if not os.path.isdir("../" + OLD_STACK_DIR):
 
78
                os.makedirs("../" + OLD_STACK_DIR)
 
79
            os.rename(file, "../{}/{}_{}".format(OLD_STACK_DIR, file, time.strftime('%Y%m%d-%H%M%S')))