~allanlesage/uci-engine/coverage-extractor

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
#!/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 time

from cupstream2distro import launchpadmanager, packagemanager
from cupstream2distro.stacks import get_stack_files_to_sync, get_allowed_projects
from cupstream2distro.settings import OLD_STACK_DIR, SILO_NAME_LIST, SILO_BUILDPPA_SCHEME

if __name__ == '__main__':

    logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")

    parser = argparse.ArgumentParser(description="Rsync all availables packages to be copied to the ubuntu archive from a ppa")
    parser.add_argument("--no-filter", action='store_true', help="Don't filter list (case coming from silos where there is no more filtering needed)")
    args = parser.parse_args()

    launchpadmanager.get_launchpad(use_cred_file=None)
    dest_archive = launchpadmanager.get_ubuntu_archive()

    logging.debug("Check if there are some stacks to synchronize")
    for (file, release) in get_stack_files_to_sync():
        logging.info("Found {}".format(file))
        with open(file) as f:
            for line in f.readlines():
                (ppa, src_pocket, from_series, dest_pocket, to_series, source, version, distro_version_at_prepare_time, sponsored_name) = line.strip().split("\t")
                logging.debug("Received copy request for {} ({}), from {} ({}, {}), to Ubuntu ({}, {}) by {}".format(source, version, ppa, from_series,
                                                                                                                     src_pocket, to_series, dest_pocket,
                                                                                                                     sponsored_name))
                if ppa not in [SILO_BUILDPPA_SCHEME.format(ppa_name) for ppa_name in SILO_NAME_LIST]:
                    logging.error("Rejecting {} as {} isn't in the allowed ppa list.".format(source, ppa))
                    continue

                try:
                    sponsored = launchpadmanager.get_person(sponsored_name)
                except KeyError:
                    logging.error("{} isn't a valid launchpad user name. Can't copy that package".format(sponsored_name))
                    continue

                if not args.no_filter and not source in get_allowed_projects(release):
                    logging.error("The project {} is not in the allowed stack to be copied to distro. Rejecting.".format(source))
                    continue

                distro_version = packagemanager.get_current_version_for_series(source, to_series)
                if distro_version != distro_version_at_prepare_time:
                    message = ("A manual upload of {} ({}) to distro has been done after the current daily release was prepared (it was at {}) at this time."
                               "Ignore uploading {}.".format(source, distro_version, distro_version_at_prepare_time, version))
                    logging.error(message)
                    continue

                src_ppa = launchpadmanager.get_ppa(ppa)

                dest_archive.copyPackage(from_archive=src_ppa, from_pocket=src_pocket, from_series=from_series,
                                         include_binaries=True, to_pocket=dest_pocket, to_series=to_series,
                                         source_name=source, version=version,
                                         sponsored=sponsored)
            if not os.path.isdir("../" + OLD_STACK_DIR):
                os.makedirs("../" + OLD_STACK_DIR)
            os.rename(file, "../{}/{}_{}".format(OLD_STACK_DIR, file, time.strftime('%Y%m%d-%H%M%S')))