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, 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
30
if __name__ == '__main__':
32
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
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()
38
launchpadmanager.get_launchpad(use_cred_file=None)
39
dest_archive = launchpadmanager.get_ubuntu_archive()
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))
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,
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))
55
sponsored = launchpadmanager.get_person(sponsored_name)
57
logging.error("{} isn't a valid launchpad user name. Can't copy that package".format(sponsored_name))
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))
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)
71
src_ppa = launchpadmanager.get_ppa(ppa)
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,
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')))