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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#!/usr/bin/env python
#
# Script to copy sources from one PPA to another.
#
# Copyright (C) 2011-2013 Philip Muskovac <yofel@kubuntu.org>
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import sys
import os
from lazr.restfulclient.errors import HTTPError
from optparse import OptionParser
from launchpadlib.launchpad import Launchpad
sys.path.append(os.path.abspath(os.path.join('..', 'pylib')))
from KubuntuDevTools.launchpad import KDTLaunchpad
parser = OptionParser("%prog [options] " +
"ppa:fromPPA (<release>|all) ppa:toPPA (<release>|all)")
parser.add_option('-n', '--nobinaries', dest='nobin', action='store_true',
help="Don't copy binary packages")
parser.add_option('-q', '--quiet', dest='quiet', action='store_true',
help="Be quiet and don't print anything on success")
parser.add_option('-c', '--credentials', dest='credentials_file',
help="use the specified credentials file for authentication with " +
"launchpad instead of the keyring")
parser.add_option('-a', '--all', dest='all', action='store_true',
help="Copy all packages in the ppa")
parser.add_option('-p', '--package', dest='pkg', default=None, action='append',
help="Source package to copy, may be be given multiple times")
parser.add_option('-b', '--batch', dest='batchfile', default=None,
help="File with source packages to copy (newline seperated list)")
parser.add_option('--sync', dest='sync', default=False, action='store_true',
help="Do a synchronous copy")
(options, args) = parser.parse_args()
if len(args) < 4:
parser.error("Missing parameter")
elif len(args) > 4:
parser.error("Too many parameters")
if KDTLaunchpad:
lp = KDTLaunchpad.login_with(credentials_file=options.credentials_file, version="devel")
else:
lp = Launchpad.login_with("kubuntu-dev-tools", "production", version="devel")
# parse PPA names, need to be in ppa:owner/ppa form
ppa = args[0]
if not ppa.find(':') > 0 or not ppa.find('/') > 0:
parser.error("Invalid ppa syntax [%s], needs to be in ppa:<owner>/<ppa> form." % ppa)
owner = ppa[ppa.find(':') + 1:ppa.find('/')]
PPA = ppa[ppa.find('/') + 1:]
fromPPA = lp.people[owner].getPPAByName(name=PPA)
ppa = args[2]
if not ppa.find(':') > 0 or not ppa.find('/') > 0:
parser.error("Invalid ppa syntax [%s], needs to be in ppa:<owner>/<ppa> form." % ppa)
owner = ppa[ppa.find(':') + 1:ppa.find('/')]
PPA = ppa[ppa.find('/') + 1:]
toPPA = lp.people[owner].getPPAByName(name=PPA)
def from_release(source):
return source.distro_series_link[source.distro_series_link.rfind('/') +1:]
def is_right_release(source):
# TODO: check if release is valid ?
if args[1].lower() == 'all':
return True
else:
return args[1].lower() == from_release(source)
def to_release(source):
# TODO: check if release is valid ?
if args[3].lower() == 'all':
return from_release(source)
else:
return args[3].lower()
def copy_package(source, target, include_binaries, package, from_series, to_series, version):
message_prefix = "Requesting copy of"
if options.sync:
message_prefix = "Copying"
if not options.quiet:
sys.stdout.write("%s %s from %s [%s] to %s [%s]..."
% (message_prefix,
package + ' ' + version,
args[0],
from_series,
args[2],
to_series))
sys.stdout.flush()
try:
if options.sync:
target.syncSource(from_archive=source,
include_binaries=include_binaries,
source_name=package,
to_pocket='Release',
to_series=to_series,
version=version)
else:
target.copyPackage(from_archive=source,
include_binaries=include_binaries,
source_name=package,
to_pocket='Release',
to_series=to_series,
version=version,
unembargo=True)
except HTTPError, e:
print(" FAILED:")
print("[HTTP %s]: %s" % (e.response['status'], e.content[e.content.find('(') + 1:e.content.find(')')]))
else:
print(" done.")
for source in fromPPA.getPublishedSources(status='Published'):
if options.all:
if is_right_release(source):
copy_package(fromPPA, toPPA, not options.nobin,
source.source_package_name,
from_release(source),
to_release(source),
source.source_package_version)
elif options.pkg:
for package in options.pkg:
if (source.source_package_name == package and
is_right_release(source)):
copy_package(fromPPA, toPPA, not options.nobin,
source.source_package_name,
from_release(source),
to_release(source),
source.source_package_version)
elif options.batchfile:
batchfile = open(os.path.expanduser(options.batchfile), 'r')
package = batchfile.readline()
while (package):
if (source.source_package_name == package.strip() and
is_right_release(source)):
copy_package(fromPPA, toPPA, not options.nobin,
source.source_package_name,
from_release(source),
to_release(source),
source.source_package_version)
package = batchfile.readline()
batchfile.close()
else:
parser.error("Either -a, -p or -b is required")
sys.exit(1)
|