621.1.1
by Luca Falavigna
Initial import of syncpackage |
1 |
#!/usr/bin/python
|
621.1.2
by Luca Falavigna
License syncpacakge under GPLv3 |
2 |
# -*- coding: utf-8 -*-
|
3 |
#
|
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
4 |
# Copyright (C) 2008-2010 Martin Pitt <martin.pitt@canonical.com>,
|
995
by Stefano Rivera
Catch DownloadErrors in ubuntutools.archive users. (LP: #708862) |
5 |
# 2010 Benjamin Drung <bdrung@ubuntu.com>,
|
6 |
# 2010-2011 Stefano Rivera <stefanor@ubuntu.com>
|
|
621.1.2
by Luca Falavigna
License syncpacakge under GPLv3 |
7 |
#
|
8 |
# ##################################################################
|
|
9 |
#
|
|
10 |
# This program is free software; you can redistribute it and/or
|
|
11 |
# modify it under the terms of the GNU General Public License
|
|
12 |
# as published by the Free Software Foundation; version 3.
|
|
820
by Benjamin Drung
Remove all trailing spaces. |
13 |
#
|
621.1.2
by Luca Falavigna
License syncpacakge under GPLv3 |
14 |
# This program is distributed in the hope that it will be useful,
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 |
# GNU General Public License for more details.
|
|
18 |
#
|
|
19 |
# See file /usr/share/common-licenses/GPL-3 for more details.
|
|
20 |
#
|
|
21 |
# ##################################################################
|
|
621.1.1
by Luca Falavigna
Initial import of syncpackage |
22 |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
23 |
import codecs |
638
by Benjamin Drung
syncpackage: add more options and allow pulling packages from Debian. |
24 |
import optparse |
25 |
import os |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
26 |
import re |
638
by Benjamin Drung
syncpackage: add more options and allow pulling packages from Debian. |
27 |
import shutil |
28 |
import sys |
|
1140
by Stefano Rivera
Wrap blacklist messages and comments |
29 |
import textwrap |
1121.1.1
by Stefano Rivera
Check the sync blacklist |
30 |
import urllib |
638
by Benjamin Drung
syncpackage: add more options and allow pulling packages from Debian. |
31 |
|
1116.2.7
by Colin Watson
better error presentation |
32 |
from lazr.restfulclient.errors import HTTPError |
33 |
||
995
by Stefano Rivera
Catch DownloadErrors in ubuntutools.archive users. (LP: #708862) |
34 |
from ubuntutools.archive import (DebianSourcePackage, UbuntuSourcePackage, |
35 |
DownloadError) |
|
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
36 |
from ubuntutools.config import UDTConfig, ubu_email |
1116.2.6
by Colin Watson
monkeypatching doesn't work right; extend Launchpad.login instead |
37 |
from ubuntutools.lp import udtexceptions |
1251.1.4
by Stefano Rivera
Add sponsorship support |
38 |
from ubuntutools.lp.lpapicache import (Distribution, Launchpad, PersonTeam, |
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
39 |
SourcePackagePublishingHistory) |
1383
by Benjamin Drung
Move devscripts.logger to ubuntutools.logger. |
40 |
from ubuntutools.logger import Logger |
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
41 |
from ubuntutools.misc import split_release_pocket |
1116.2.12
by Colin Watson
use ubuntutools.question |
42 |
from ubuntutools.question import YesNoQuestion |
1383
by Benjamin Drung
Move devscripts.logger to ubuntutools.logger. |
43 |
from ubuntutools.requestsync.mail import ( |
44 |
get_debian_srcpkg as requestsync_mail_get_debian_srcpkg) |
|
45 |
from ubuntutools.requestsync.lp import get_debian_srcpkg, get_ubuntu_srcpkg |
|
1416
by Benjamin Drung
Move Version class into ubuntutools module. |
46 |
from ubuntutools.version import Version |
1091.1.1
by Evan Broder
* ubuntutools.subprocess: |
47 |
from ubuntutools import subprocess |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
48 |
|
641
by Benjamin Drung
syncpackage: add mismatching source tarball detection (for fake syncs). |
49 |
|
895
by Benjamin Drung
syncpackage: Make pylint a little bit happier. |
50 |
def remove_signature(dscname): |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
51 |
'''Removes the signature from a .dsc file if the .dsc file is signed.'''
|
52 |
||
927
by Benjamin Drung
Make pylint a little bit happier. |
53 |
dsc_file = open(dscname) |
54 |
if dsc_file.readline().strip() == "-----BEGIN PGP SIGNED MESSAGE-----": |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
55 |
unsigned_file = [] |
56 |
# search until begin of body found
|
|
927
by Benjamin Drung
Make pylint a little bit happier. |
57 |
for line in dsc_file: |
895
by Benjamin Drung
syncpackage: Make pylint a little bit happier. |
58 |
if line.strip() == "": |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
59 |
break
|
60 |
||
61 |
# search for end of body
|
|
927
by Benjamin Drung
Make pylint a little bit happier. |
62 |
for line in dsc_file: |
895
by Benjamin Drung
syncpackage: Make pylint a little bit happier. |
63 |
if line.strip() == "": |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
64 |
break
|
895
by Benjamin Drung
syncpackage: Make pylint a little bit happier. |
65 |
unsigned_file.append(line) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
66 |
|
927
by Benjamin Drung
Make pylint a little bit happier. |
67 |
dsc_file.close() |
68 |
dsc_file = open(dscname, "w") |
|
69 |
dsc_file.writelines(unsigned_file) |
|
70 |
dsc_file.close() |
|
638
by Benjamin Drung
syncpackage: add more options and allow pulling packages from Debian. |
71 |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
72 |
|
927
by Benjamin Drung
Make pylint a little bit happier. |
73 |
def add_fixed_bugs(changes, bugs): |
895
by Benjamin Drung
syncpackage: Make pylint a little bit happier. |
74 |
'''Add additional Launchpad bugs to the list of fixed bugs in changes
|
75 |
file.'''
|
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
76 |
|
927
by Benjamin Drung
Make pylint a little bit happier. |
77 |
changes = [l for l in changes.split("\n") if l.strip() != ""] |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
78 |
# Remove duplicates
|
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
79 |
bugs = set(str(bug) for bug in bugs) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
80 |
|
81 |
for i in xrange(len(changes)): |
|
82 |
if changes[i].startswith("Launchpad-Bugs-Fixed:"): |
|
83 |
bugs.update(changes[i][22:].strip().split(" ")) |
|
84 |
changes[i] = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs)) |
|
85 |
break
|
|
86 |
elif i == len(changes) - 1: |
|
87 |
# Launchpad-Bugs-Fixed entry does not exist in changes file
|
|
88 |
line = "Launchpad-Bugs-Fixed: %s" % (" ".join(bugs)) |
|
89 |
changes.append(line) |
|
90 |
||
91 |
return "\n".join(changes + [""]) |
|
92 |
||
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
93 |
|
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
94 |
def sync_dsc(src_pkg, debian_dist, release, name, email, bugs, ubuntu_mirror, |
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
95 |
keyid=None, simulate=False, force=False, fakesync=False): |
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
96 |
'''Local sync, trying to emulate sync-source.py
|
97 |
Grabs a source package, replaces the .orig.tar with the one from Ubuntu,
|
|
98 |
if necessary, writes a sync-appropriate .changes file, and signs it.
|
|
99 |
'''
|
|
100 |
||
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
101 |
uploader = name + " <" + email + ">" |
102 |
||
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
103 |
src_pkg.pull_dsc() |
104 |
new_ver = Version(src_pkg.dsc["Version"]) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
105 |
|
106 |
try: |
|
1355
by Stefano Rivera
syncpackage: Don't throw away release pockets, returning correct errors |
107 |
ubuntu_series, ubuntu_pocket = split_release_pocket(release) |
108 |
ubuntu_source = get_ubuntu_srcpkg(src_pkg.source, ubuntu_series, |
|
109 |
ubuntu_pocket) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
110 |
ubuntu_ver = Version(ubuntu_source.getVersion()) |
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
111 |
ubu_pkg = UbuntuSourcePackage(src_pkg.source, ubuntu_ver.full_version, |
112 |
ubuntu_source.getComponent(), |
|
113 |
mirrors=[ubuntu_mirror]) |
|
114 |
ubu_pkg.pull_dsc() |
|
940.1.33
by Stefano Rivera
Move source package verification into ubuntutools.archive |
115 |
need_orig = ubuntu_ver.upstream_version != new_ver.upstream_version |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
116 |
except udtexceptions.PackageNotFoundException: |
117 |
ubuntu_ver = Version('~') |
|
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
118 |
ubu_pkg = None |
940.1.33
by Stefano Rivera
Move source package verification into ubuntutools.archive |
119 |
need_orig = True |
1138
by Stefano Rivera
Tweak log levels, use error when bailing out because of blacklisting, and normal for everything else blacklist-related |
120 |
Logger.normal('%s does not exist in Ubuntu.', name) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
121 |
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
122 |
Logger.debug('Source %s: current version %s, new version %s', |
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
123 |
src_pkg.source, ubuntu_ver, new_ver) |
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
124 |
Logger.debug('Needs source tarball: %s', str(need_orig)) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
125 |
|
126 |
cur_ver = ubuntu_ver.get_related_debian_version() |
|
127 |
if ubuntu_ver.is_modified_in_ubuntu(): |
|
1116.2.13
by Colin Watson
syncpackage: Require -f/--force option to overwrite Ubuntu changes. |
128 |
if not force: |
129 |
Logger.error('--force is required to discard Ubuntu changes.') |
|
130 |
sys.exit(1) |
|
131 |
||
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
132 |
Logger.warn('Overwriting modified Ubuntu version %s, ' |
133 |
'setting current version to %s', |
|
134 |
ubuntu_ver.full_version, cur_ver.full_version) |
|
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
135 |
if simulate: |
136 |
return
|
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
137 |
|
995
by Stefano Rivera
Catch DownloadErrors in ubuntutools.archive users. (LP: #708862) |
138 |
try: |
139 |
src_pkg.pull() |
|
140 |
except DownloadError, e: |
|
141 |
Logger.error('Failed to download: %s', str(e)) |
|
142 |
sys.exit(1) |
|
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
143 |
src_pkg.unpack() |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
144 |
|
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
145 |
needs_fakesync = not (need_orig or ubu_pkg.verify_orig()) |
146 |
||
147 |
if needs_fakesync and fakesync: |
|
148 |
Logger.warn('Performing a fakesync') |
|
149 |
elif not needs_fakesync and fakesync: |
|
150 |
Logger.error('Fakesync not required, aborting.') |
|
151 |
sys.exit(1) |
|
152 |
elif needs_fakesync and not fakesync: |
|
153 |
Logger.error('The checksums of the Debian and Ubuntu packages ' |
|
154 |
'mismatch. A fake sync using --fakesync is required.') |
|
155 |
sys.exit(1) |
|
940.1.33
by Stefano Rivera
Move source package verification into ubuntutools.archive |
156 |
|
157 |
if fakesync: |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
158 |
# Download Ubuntu files (override Debian source tarballs)
|
995
by Stefano Rivera
Catch DownloadErrors in ubuntutools.archive users. (LP: #708862) |
159 |
try: |
160 |
ubu_pkg.pull() |
|
161 |
except DownloadError, e: |
|
162 |
Logger.error('Failed to download: %s', str(e)) |
|
163 |
sys.exit(1) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
164 |
|
165 |
# change into package directory
|
|
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
166 |
directory = src_pkg.source + '-' + new_ver.upstream_version |
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
167 |
Logger.command(('cd', directory)) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
168 |
os.chdir(directory) |
169 |
||
170 |
# read Debian distribution from debian/changelog if not specified
|
|
171 |
if debian_dist is None: |
|
172 |
line = open("debian/changelog").readline() |
|
173 |
debian_dist = line.split(" ")[2].strip(";") |
|
174 |
||
940.1.33
by Stefano Rivera
Move source package verification into ubuntutools.archive |
175 |
if not fakesync: |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
176 |
# create the changes file
|
927
by Benjamin Drung
Make pylint a little bit happier. |
177 |
changes_filename = "%s_%s_source.changes" % \ |
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
178 |
(src_pkg.source, new_ver.strip_epoch()) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
179 |
cmd = ["dpkg-genchanges", "-S", "-v" + cur_ver.full_version, |
180 |
"-DDistribution=" + release, |
|
181 |
"-DOrigin=debian/" + debian_dist, |
|
182 |
"-e" + uploader] |
|
183 |
if need_orig: |
|
184 |
cmd.append("-sa") |
|
185 |
else: |
|
186 |
cmd.append("-sd") |
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
187 |
if not Logger.verbose: |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
188 |
cmd += ["-q"] |
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
189 |
Logger.command(cmd + ['>', '../' + changes_filename]) |
1251.1.5
by Stefano Rivera
Break up some long lines into multiple statements |
190 |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
1251.1.12
by Stefano Rivera
Typo |
191 |
changes = process.communicate()[0] |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
192 |
|
193 |
# Add additional bug numbers
|
|
194 |
if len(bugs) > 0: |
|
927
by Benjamin Drung
Make pylint a little bit happier. |
195 |
changes = add_fixed_bugs(changes, bugs) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
196 |
|
197 |
# remove extracted (temporary) files
|
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
198 |
Logger.command(('cd', '..')) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
199 |
os.chdir('..') |
200 |
shutil.rmtree(directory, True) |
|
201 |
||
202 |
# write changes file
|
|
927
by Benjamin Drung
Make pylint a little bit happier. |
203 |
changes_file = open(changes_filename, "w") |
204 |
changes_file.writelines(changes) |
|
205 |
changes_file.close() |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
206 |
|
207 |
# remove signature and sign package
|
|
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
208 |
remove_signature(src_pkg.dsc_name) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
209 |
if keyid is not False: |
927
by Benjamin Drung
Make pylint a little bit happier. |
210 |
cmd = ["debsign", changes_filename] |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
211 |
if not keyid is None: |
212 |
cmd.insert(1, "-k" + keyid) |
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
213 |
Logger.command(cmd) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
214 |
subprocess.check_call(cmd) |
215 |
else: |
|
216 |
# Create fakesync changelog entry
|
|
217 |
new_ver = Version(new_ver.full_version + "fakesync1") |
|
927
by Benjamin Drung
Make pylint a little bit happier. |
218 |
changes_filename = "%s_%s_source.changes" % \ |
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
219 |
(src_pkg.source, new_ver.strip_epoch()) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
220 |
if len(bugs) > 0: |
221 |
message = "Fake sync due to mismatching orig tarball (LP: %s)." % \ |
|
895
by Benjamin Drung
syncpackage: Make pylint a little bit happier. |
222 |
(", ".join(["#" + str(b) for b in bugs])) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
223 |
else: |
224 |
message = "Fake sync due to mismatching orig tarball." |
|
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
225 |
cmd = ['dch', '-v', new_ver.full_version, '--force-distribution', |
226 |
'-D', release, message] |
|
227 |
env = {'DEBFULLNAME': name, 'DEBEMAIL': email} |
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
228 |
Logger.command(cmd) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
229 |
subprocess.check_call(cmd, env=env) |
230 |
||
231 |
# update the Maintainer field
|
|
232 |
cmd = ["update-maintainer"] |
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
233 |
if not Logger.verbose: |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
234 |
cmd.append("-q") |
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
235 |
Logger.command(cmd) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
236 |
subprocess.check_call(cmd) |
820
by Benjamin Drung
Remove all trailing spaces. |
237 |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
238 |
# Build source package
|
1270
by Stefano Rivera
syncpackage, backportpackage, sponsor-patch: Use -nc when building source |
239 |
cmd = ["debuild", "--no-lintian", "-nc", "-S", |
240 |
"-v" + cur_ver.full_version] |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
241 |
if need_orig: |
242 |
cmd += ['-sa'] |
|
243 |
if keyid: |
|
244 |
cmd += ["-k" + keyid] |
|
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
245 |
Logger.command(cmd) |
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
246 |
returncode = subprocess.call(cmd) |
786
by Benjamin Drung
syncpackage: Print an error message if the source-only build fails (LP: #668749). |
247 |
if returncode != 0: |
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
248 |
Logger.error('Source-only build with debuild failed. ' |
249 |
'Please check build log above.') |
|
786
by Benjamin Drung
syncpackage: Print an error message if the source-only build fails (LP: #668749). |
250 |
sys.exit(1) |
641
by Benjamin Drung
syncpackage: add mismatching source tarball detection (for fake syncs). |
251 |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
252 |
|
253 |
def fetch_source_pkg(package, dist, version, component, ubuntu_release, |
|
254 |
mirror): |
|
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
255 |
"""Download the specified source package.
|
256 |
dist, version, component, mirror can all be None.
|
|
257 |
"""
|
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
258 |
if mirror is None: |
259 |
mirrors = [] |
|
260 |
else: |
|
261 |
mirrors = [mirror] |
|
262 |
||
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
263 |
if package.endswith('.dsc'): |
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
264 |
return DebianSourcePackage(dscfile=package, mirrors=mirrors) |
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
265 |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
266 |
if dist is None: |
1400
by Dmitrijs Ledkovs
Since Britney migration was introduced in Ubuntu, automatic syncing is |
267 |
dist = 'unstable' |
1309.1.10
by Stefano Rivera
pbuilder-dist, pull-debian-source, pull-lp-source, requestsync, |
268 |
|
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
269 |
requested_version = version |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
270 |
if type(version) == str: |
271 |
version = Version(version) |
|
272 |
||
273 |
if version is None or component is None: |
|
940.1.26
by Stefano Rivera
Improve error handling |
274 |
try: |
1167
by Benjamin Drung
ubuntutools/requestsync: Follow PEP 8 naming conventions. |
275 |
debian_srcpkg = get_debian_srcpkg(package, dist) |
940.1.26
by Stefano Rivera
Improve error handling |
276 |
except (udtexceptions.PackageNotFoundException, |
277 |
udtexceptions.SeriesNotFoundException), e: |
|
278 |
Logger.error(str(e)) |
|
279 |
sys.exit(1) |
|
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
280 |
if version is None: |
281 |
version = Version(debian_srcpkg.getVersion()) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
282 |
try: |
1355
by Stefano Rivera
syncpackage: Don't throw away release pockets, returning correct errors |
283 |
ubuntu_series, ubuntu_pocket = split_release_pocket(ubuntu_release) |
284 |
ubuntu_srcpkg = get_ubuntu_srcpkg(package, ubuntu_series, |
|
285 |
ubuntu_pocket) |
|
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
286 |
ubuntu_version = Version(ubuntu_srcpkg.getVersion()) |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
287 |
except udtexceptions.PackageNotFoundException: |
288 |
ubuntu_version = Version('~') |
|
940.1.26
by Stefano Rivera
Improve error handling |
289 |
except udtexceptions.SeriesNotFoundException, e: |
290 |
Logger.error(str(e)) |
|
291 |
sys.exit(1) |
|
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
292 |
if ubuntu_version >= version: |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
293 |
# The LP importer is maybe out of date
|
1167
by Benjamin Drung
ubuntutools/requestsync: Follow PEP 8 naming conventions. |
294 |
debian_srcpkg = requestsync_mail_get_debian_srcpkg(package, dist) |
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
295 |
if requested_version is None: |
296 |
version = Version(debian_srcpkg.getVersion()) |
|
297 |
if ubuntu_version >= version: |
|
298 |
Logger.error("Version in Debian %s (%s) isn't newer than " |
|
299 |
"Ubuntu %s (%s)", |
|
300 |
version, dist, ubuntu_version, ubuntu_release) |
|
301 |
sys.exit(1) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
302 |
if component is None: |
303 |
component = debian_srcpkg.getComponent() |
|
304 |
||
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
305 |
assert component in ('main', 'contrib', 'non-free') |
306 |
||
940.1.11
by Stefano Rivera
Use *SourcePackage in syncpackage |
307 |
return DebianSourcePackage(package, version.full_version, component, |
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
308 |
mirrors=mirrors) |
638
by Benjamin Drung
syncpackage: add more options and allow pulling packages from Debian. |
309 |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
310 |
|
1251.1.4
by Stefano Rivera
Add sponsorship support |
311 |
def copy(src_pkg, release, bugs, sponsoree=None, simulate=False, force=False): |
1116.2.27
by Colin Watson
docstring for copy() |
312 |
"""Copy a source package from Debian to Ubuntu using the Launchpad API."""
|
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
313 |
ubuntu = Distribution('ubuntu') |
1116.2.23
by Colin Watson
avoid shadowing global "debian" name |
314 |
debian_archive = Distribution('debian').getArchive() |
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
315 |
ubuntu_archive = ubuntu.getArchive() |
316 |
if release is None: |
|
317 |
ubuntu_series = ubuntu.getDevelopmentSeries().name |
|
318 |
ubuntu_pocket = 'Release' |
|
319 |
else: |
|
320 |
ubuntu_series, ubuntu_pocket = split_release_pocket(release) |
|
321 |
||
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
322 |
# Ensure that the provided Debian version actually exists.
|
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
323 |
try: |
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
324 |
debian_spph = SourcePackagePublishingHistory( |
325 |
debian_archive.getPublishedSources( |
|
326 |
source_name=src_pkg.source, |
|
327 |
version=src_pkg.version.full_version, |
|
328 |
exact_match=True)[0] |
|
329 |
)
|
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
330 |
except IndexError: |
1274
by Stefano Rivera
Improve error message when LP's package importer is out of date |
331 |
Logger.error('Debian version %s has not been picked up by LP yet. ' |
332 |
'Please try again later.', |
|
333 |
src_pkg.version) |
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
334 |
sys.exit(1) |
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
335 |
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
336 |
try: |
1167
by Benjamin Drung
ubuntutools/requestsync: Follow PEP 8 naming conventions. |
337 |
ubuntu_spph = get_ubuntu_srcpkg(src_pkg.source, |
338 |
ubuntu_series, ubuntu_pocket) |
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
339 |
ubuntu_pkg = UbuntuSourcePackage(src_pkg.source, |
340 |
ubuntu_spph.getVersion(), |
|
341 |
ubuntu_spph.getComponent(), |
|
342 |
mirrors=[]) |
|
1116.2.13
by Colin Watson
syncpackage: Require -f/--force option to overwrite Ubuntu changes. |
343 |
|
1116.2.4
by Colin Watson
more logging by default |
344 |
Logger.normal('Source %s -> %s/%s: current version %s, new version %s', |
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
345 |
src_pkg.source, ubuntu_series, ubuntu_pocket, |
346 |
ubuntu_pkg.version, src_pkg.version) |
|
1116.2.13
by Colin Watson
syncpackage: Require -f/--force option to overwrite Ubuntu changes. |
347 |
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
348 |
ubuntu_version = Version(ubuntu_pkg.version.full_version) |
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
349 |
base_version = ubuntu_version.get_related_debian_version() |
1116.2.13
by Colin Watson
syncpackage: Require -f/--force option to overwrite Ubuntu changes. |
350 |
if not force and ubuntu_version.is_modified_in_ubuntu(): |
351 |
Logger.error('--force is required to discard Ubuntu changes.') |
|
352 |
sys.exit(1) |
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
353 |
|
354 |
# Check whether a fakesync would be required.
|
|
1116.2.29
by Colin Watson
drop quiet download stuff, not worth an API debate |
355 |
src_pkg.pull_dsc() |
356 |
ubuntu_pkg.pull_dsc() |
|
1116.2.26
by Colin Watson
factor out dsc comparison into a method on ubuntutools.archive.Dsc |
357 |
if not src_pkg.dsc.compare_dsc(ubuntu_pkg.dsc): |
358 |
Logger.error('The checksums of the Debian and Ubuntu packages ' |
|
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
359 |
'mismatch. A fake sync using --fakesync is required.') |
1116.2.26
by Colin Watson
factor out dsc comparison into a method on ubuntutools.archive.Dsc |
360 |
sys.exit(1) |
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
361 |
except udtexceptions.PackageNotFoundException: |
1121.2.2
by Stefano Rivera
Close bugs after syncing |
362 |
base_version = Version('~') |
1116.2.4
by Colin Watson
more logging by default |
363 |
Logger.normal('Source %s -> %s/%s: not in Ubuntu, new version %s', |
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
364 |
src_pkg.source, ubuntu_series, ubuntu_pocket, |
365 |
src_pkg.version) |
|
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
366 |
|
1210
by Stefano Rivera
Add changelog retrieval to lpapicache, and use this in syncpackage and |
367 |
changes = debian_spph.getChangelog(since_version=base_version) |
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
368 |
if changes: |
1185
by Stefano Rivera
syncpackge: Gracefully deal with no available changelog from Debian (PTS |
369 |
changes = changes.strip() |
1139
by Benjamin Drung
Fix typo. |
370 |
Logger.normal("New changes:\n%s", changes) |
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
371 |
|
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
372 |
if simulate: |
373 |
return
|
|
374 |
||
1251.1.4
by Stefano Rivera
Add sponsorship support |
375 |
if sponsoree: |
376 |
Logger.normal("Sponsoring this sync for %s (%s)", |
|
377 |
sponsoree.display_name, sponsoree.name) |
|
1116.2.12
by Colin Watson
use ubuntutools.question |
378 |
answer = YesNoQuestion().ask("Sync this package", "no") |
379 |
if answer != "yes": |
|
1116.2.5
by Colin Watson
add explicit confirmation step |
380 |
return
|
381 |
||
1116.2.7
by Colin Watson
better error presentation |
382 |
try: |
383 |
ubuntu_archive.copyPackage( |
|
1116.2.17
by Colin Watson
make better use of ubuntutools.archive, allowing us to detect when fakesyncs are required in LP mode |
384 |
source_name=src_pkg.source, |
1116.2.19
by Colin Watson
use version.full_version rather than str(version) |
385 |
version=src_pkg.version.full_version, |
1116.2.10
by Colin Watson
move copyPackage into lpapicache for better encapsulation |
386 |
from_archive=debian_archive, |
1116.2.7
by Colin Watson
better error presentation |
387 |
to_series=ubuntu_series, |
388 |
to_pocket=ubuntu_pocket, |
|
1251.1.4
by Stefano Rivera
Add sponsorship support |
389 |
include_binaries=False, |
1251.1.15
by Stefano Rivera
The parameter is sponsored |
390 |
sponsored=sponsoree) |
1116.2.7
by Colin Watson
better error presentation |
391 |
except HTTPError, error: |
1120
by Benjamin Drung
* syncpackage: Convert to new LP API, with --no-lp available for the old |
392 |
Logger.error("HTTP Error %s: %s", error.response.status, |
393 |
error.response.reason) |
|
1116.2.7
by Colin Watson
better error presentation |
394 |
Logger.error(error.content) |
395 |
sys.exit(1) |
|
396 |
||
1116.2.4
by Colin Watson
more logging by default |
397 |
Logger.normal('Request succeeded; you should get an e-mail once it is ' |
398 |
'processed.') |
|
1121.2.5
by Stefano Rivera
Don't look for bugs closed in Debian changes, only close bugs mentioned on the command line |
399 |
bugs = sorted(set(bugs)) |
400 |
if bugs: |
|
1124
by Benjamin Drung
syncpackage: |
401 |
Logger.normal("Launchpad bugs to be closed: %s", |
1121.2.5
by Stefano Rivera
Don't look for bugs closed in Debian changes, only close bugs mentioned on the command line |
402 |
', '.join(str(bug) for bug in bugs)) |
1124
by Benjamin Drung
syncpackage: |
403 |
Logger.normal('Please wait for the sync to be successful before ' |
404 |
'closing bugs.') |
|
405 |
answer = YesNoQuestion().ask("Close bugs", "yes") |
|
1121.2.5
by Stefano Rivera
Don't look for bugs closed in Debian changes, only close bugs mentioned on the command line |
406 |
if answer == "yes": |
1124
by Benjamin Drung
syncpackage: |
407 |
close_bugs(bugs, src_pkg.source, src_pkg.version.full_version, |
1268
by Stefano Rivera
syncpackage: Mention sponsorship when closing bugs (LP: #904288) |
408 |
changes, sponsoree) |
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
409 |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
410 |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
411 |
def is_blacklisted(query): |
1121.1.2
by Stefano Rivera
Docstring |
412 |
""""Determine if package "query" is in the sync blacklist
|
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
413 |
Returns tuple of (blacklisted, comments)
|
414 |
blacklisted is one of False, 'CURRENT', 'ALWAYS'
|
|
1121.1.2
by Stefano Rivera
Docstring |
415 |
"""
|
1121.1.3
by Stefano Rivera
Check the +localpackagediffs blacklist too |
416 |
series = Launchpad.distributions['ubuntu'].current_series |
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
417 |
lp_comments = series.getDifferenceComments(source_package_name=query) |
418 |
blacklisted = False |
|
1195
by Stefano Rivera
* syncpackage: |
419 |
comments = [u'%s\n -- %s %s' |
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
420 |
% (c.body_text, c.comment_author.name, |
421 |
c.comment_date.strftime('%a, %d %b %Y %H:%M:%S +0000')) |
|
1140
by Stefano Rivera
Wrap blacklist messages and comments |
422 |
for c in lp_comments] |
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
423 |
|
1176
by Stefano Rivera
syncpackage: Looks like we can't expect exactly one DSD record for every |
424 |
for diff in series.getDifferencesTo(source_package_name_filter=query): |
425 |
if (diff.status == 'Blacklisted current version' |
|
426 |
and blacklisted != 'ALWAYS'): |
|
427 |
blacklisted = 'CURRENT' |
|
428 |
if diff.status == 'Blacklisted always': |
|
429 |
blacklisted = 'ALWAYS' |
|
1121.1.3
by Stefano Rivera
Check the +localpackagediffs blacklist too |
430 |
|
431 |
# Old blacklist:
|
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
432 |
url = 'http://people.canonical.com/~ubuntu-archive/sync-blacklist.txt' |
433 |
with codecs.EncodedFile(urllib.urlopen(url), 'UTF-8') as f: |
|
1195
by Stefano Rivera
* syncpackage: |
434 |
applicable_lines = [] |
1121.1.1
by Stefano Rivera
Check the sync blacklist |
435 |
for line in f: |
436 |
if not line.strip(): |
|
1195
by Stefano Rivera
* syncpackage: |
437 |
applicable_lines = [] |
1121.1.1
by Stefano Rivera
Check the sync blacklist |
438 |
continue
|
1195
by Stefano Rivera
* syncpackage: |
439 |
m = re.match(r'^\s*([a-z0-9.+-]+)?', line) |
440 |
source = m.group(0) |
|
441 |
applicable_lines.append(line) |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
442 |
if source and query == source: |
1195
by Stefano Rivera
* syncpackage: |
443 |
comments += ["From sync-blacklist.txt:"] + applicable_lines |
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
444 |
blacklisted = 'ALWAYS' |
445 |
break
|
|
446 |
||
447 |
return (blacklisted, comments) |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
448 |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
449 |
|
1268
by Stefano Rivera
syncpackage: Mention sponsorship when closing bugs (LP: #904288) |
450 |
def close_bugs(bugs, package, version, changes, sponsoree): |
1121.2.2
by Stefano Rivera
Close bugs after syncing |
451 |
"""Close the correct task on all bugs, with changes"""
|
452 |
ubuntu = Launchpad.distributions['ubuntu'] |
|
453 |
message = ("This bug was fixed in the package %s - %s" |
|
1185
by Stefano Rivera
syncpackge: Gracefully deal with no available changelog from Debian (PTS |
454 |
% (package, version)) |
1268
by Stefano Rivera
syncpackage: Mention sponsorship when closing bugs (LP: #904288) |
455 |
if sponsoree: |
456 |
message += '\nSponsored for %s (%s)' % (sponsoree.display_name, |
|
457 |
sponsoree.name) |
|
1185
by Stefano Rivera
syncpackge: Gracefully deal with no available changelog from Debian (PTS |
458 |
if changes: |
459 |
message += "\n\n---------------\n" + changes |
|
1121.2.2
by Stefano Rivera
Close bugs after syncing |
460 |
for bug in bugs: |
461 |
bug = Launchpad.bugs[bug] |
|
462 |
if bug.duplicate_of is not None: |
|
463 |
bug = bug.duplicate_of |
|
464 |
for task in bug.bug_tasks: |
|
465 |
target = task.target |
|
1124
by Benjamin Drung
syncpackage: |
466 |
if target == ubuntu or (target.name == package and |
467 |
getattr(target, 'distribution', None) == ubuntu): |
|
1121.2.2
by Stefano Rivera
Close bugs after syncing |
468 |
if task.status != 'Fix Released': |
469 |
Logger.normal("Closed bug %s", task.web_link) |
|
470 |
task.status = 'Fix Released' |
|
471 |
task.lp_save() |
|
472 |
bug.newMessage(content=message) |
|
473 |
break
|
|
474 |
else: |
|
1124
by Benjamin Drung
syncpackage: |
475 |
Logger.error(u"Cannot find any tasks on LP: #%i to close.", bug.id) |
1121.2.2
by Stefano Rivera
Close bugs after syncing |
476 |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
477 |
|
1183
by Benjamin Drung
syncpackage: Put command-line parsing in separate function. |
478 |
def parse(): |
479 |
"""Parse given command-line parameters."""
|
|
480 |
||
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
481 |
usage = "%prog [options] <.dsc URL/path or package name>" |
482 |
epilog = "See %s(1) for more info." % os.path.basename(sys.argv[0]) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
483 |
parser = optparse.OptionParser(usage=usage, epilog=epilog) |
484 |
||
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
485 |
parser.add_option("-d", "--distribution", |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
486 |
help="Debian distribution to sync from.") |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
487 |
parser.add_option("-r", "--release", |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
488 |
help="Specify target Ubuntu release.") |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
489 |
parser.add_option("-V", "--debian-version", |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
490 |
help="Specify the version to sync from.") |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
491 |
parser.add_option("-c", "--component", |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
492 |
help="Specify the Debian component to sync from.") |
1251.1.1
by Stefano Rivera
move --no-lp options into their own group |
493 |
parser.add_option("-b", "--bug", metavar="BUG", |
494 |
dest="bugs", action="append", default=list(), |
|
495 |
help="Mark Launchpad bug BUG as being fixed by this " |
|
496 |
"upload.") |
|
1251.1.4
by Stefano Rivera
Add sponsorship support |
497 |
parser.add_option("-s", "--sponsor", metavar="USERNAME", |
498 |
dest="sponsoree", default=None, |
|
1251.1.8
by Stefano Rivera
Spelling |
499 |
help="Sponsor the sync for USERNAME (a Launchpad " |
1251.1.4
by Stefano Rivera
Add sponsorship support |
500 |
"username).") |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
501 |
parser.add_option("-v", "--verbose", |
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
502 |
action="store_true", default=False, |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
503 |
help="Display more progress information.") |
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
504 |
parser.add_option("-F", "--fakesync", |
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
505 |
action="store_true", default=False, |
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
506 |
help="Perform a fakesync (a sync where Debian and " |
1251.1.6
by Stefano Rivera
Clarify --no-lp |
507 |
"Ubuntu have a .orig.tar mismatch). "
|
508 |
"This implies --no-lp and will leave a signed "
|
|
509 |
".changes file for you to upload.") |
|
1116.2.13
by Colin Watson
syncpackage: Require -f/--force option to overwrite Ubuntu changes. |
510 |
parser.add_option("-f", "--force", |
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
511 |
action="store_true", default=False, |
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
512 |
help="Force sync over the top of Ubuntu changes.") |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
513 |
parser.add_option('--no-conf', |
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
514 |
default=False, action='store_true', |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
515 |
help="Don't read config files or environment variables.") |
1251.1.1
by Stefano Rivera
move --no-lp options into their own group |
516 |
parser.add_option('-l', '--lpinstance', metavar='INSTANCE', |
517 |
help='Launchpad instance to connect to ' |
|
518 |
'(default: production).') |
|
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
519 |
parser.add_option('--simulate', |
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
520 |
default=False, action='store_true', |
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
521 |
help="Show what would be done, but don't actually do " |
522 |
"it.") |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
523 |
|
1251.1.8
by Stefano Rivera
Spelling |
524 |
no_lp = optparse.OptionGroup(parser, "Local sync preparation options", |
1251.1.1
by Stefano Rivera
move --no-lp options into their own group |
525 |
"Options that only apply when using --no-lp. "
|
526 |
"WARNING: The use of --no-lp is not recommended for uploads "
|
|
1251.1.8
by Stefano Rivera
Spelling |
527 |
"targeted at Ubuntu. "
|
1251.1.6
by Stefano Rivera
Clarify --no-lp |
528 |
"The archive-admins discourage its use, except for fakesyncs.") |
1251.1.1
by Stefano Rivera
move --no-lp options into their own group |
529 |
no_lp.add_option("--no-lp", |
530 |
dest="lp", action="store_false", default=True, |
|
1251.1.7
by Stefano Rivera
--no-lp *itself* could get some love, too |
531 |
help="Construct sync locally, rather than letting " |
532 |
"Launchpad copy the package directly. "
|
|
533 |
"It will leave a signed .changes file for you to "
|
|
534 |
"upload.") |
|
1251.1.1
by Stefano Rivera
move --no-lp options into their own group |
535 |
no_lp.add_option("-n", "--uploader-name", |
536 |
help="Use UPLOADER_NAME as the name of the maintainer " |
|
537 |
"for this upload.") |
|
538 |
no_lp.add_option("-e", "--uploader-email", |
|
539 |
help="Use UPLOADER_EMAIL as email address of the " |
|
540 |
"maintainer for this upload.") |
|
541 |
no_lp.add_option("-k", "--key", |
|
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
542 |
dest="keyid", |
1251.1.1
by Stefano Rivera
move --no-lp options into their own group |
543 |
help="Specify the key ID to be used for signing.") |
544 |
no_lp.add_option('--dont-sign', |
|
545 |
dest='keyid', action='store_false', |
|
546 |
help='Do not sign the upload.') |
|
547 |
no_lp.add_option('-D', '--debian-mirror', metavar='DEBIAN_MIRROR', |
|
548 |
help='Preferred Debian mirror ' |
|
549 |
'(default: %s)' |
|
550 |
% UDTConfig.defaults['DEBIAN_MIRROR']) |
|
551 |
no_lp.add_option('-U', '--ubuntu-mirror', metavar='UBUNTU_MIRROR', |
|
552 |
help='Preferred Ubuntu mirror ' |
|
553 |
'(default: %s)' |
|
554 |
% UDTConfig.defaults['UBUNTU_MIRROR']) |
|
555 |
parser.add_option_group(no_lp) |
|
556 |
||
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
557 |
(options, args) = parser.parse_args() |
558 |
||
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
559 |
if options.fakesync: |
560 |
options.lp = False |
|
561 |
||
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
562 |
if len(args) == 0: |
940.1.1
by Stefano Rivera
Use ubuntutools.logger in syncpackage |
563 |
parser.error('No .dsc URL/path or package name specified.') |
564 |
if len(args) > 1: |
|
565 |
parser.error('Multiple .dsc URLs/paths or package names specified: ' |
|
566 |
+ ', '.join(args)) |
|
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
567 |
|
1121.2.1
by Stefano Rivera
Detect bugs to be closed (but don't do anything with the list yet) |
568 |
try: |
1167
by Benjamin Drung
ubuntutools/requestsync: Follow PEP 8 naming conventions. |
569 |
options.bugs = [int(b) for b in options.bugs] |
1121.2.2
by Stefano Rivera
Close bugs after syncing |
570 |
except TypeError: |
1124
by Benjamin Drung
syncpackage: |
571 |
parser.error('Invalid bug number(s) specified.') |
780
by Benjamin Drung
syncpackage: Convert style to PEP 8. |
572 |
|
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
573 |
if options.component not in (None, "main", "contrib", "non-free"): |
574 |
parser.error('%s is not a valid Debian component. ' |
|
575 |
'It should be one of main, contrib, or non-free.'
|
|
576 |
% options.component) |
|
577 |
||
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
578 |
if options.lp and options.uploader_name: |
579 |
parser.error('Uploader name can only be overridden using --no-lp.') |
|
580 |
if options.lp and options.uploader_email: |
|
581 |
parser.error('Uploader email address can only be overridden using ' |
|
582 |
'--no-lp.') |
|
583 |
# --key, --dont-sign, --debian-mirror, and --ubuntu-mirror are just
|
|
584 |
# ignored with options.lp, and do not require warnings.
|
|
585 |
||
1183
by Benjamin Drung
syncpackage: Put command-line parsing in separate function. |
586 |
if options.lp: |
587 |
if args[0].endswith('.dsc'): |
|
588 |
parser.error('.dsc files can only be synced using --no-lp.') |
|
589 |
||
590 |
return (options, args[0]) |
|
591 |
||
592 |
||
593 |
def main(): |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
594 |
'''Handle parameters and get the ball rolling'''
|
1183
by Benjamin Drung
syncpackage: Put command-line parsing in separate function. |
595 |
(options, package) = parse() |
596 |
||
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
597 |
Logger.verbose = options.verbose |
940.1.2
by Stefano Rivera
Add UDTConfig and tidy OptParser |
598 |
config = UDTConfig(options.no_conf) |
940.1.6
by Stefano Rivera
Mirror support in syncpackage |
599 |
if options.debian_mirror is None: |
600 |
options.debian_mirror = config.get_value('DEBIAN_MIRROR') |
|
601 |
if options.ubuntu_mirror is None: |
|
602 |
options.ubuntu_mirror = config.get_value('UBUNTU_MIRROR') |
|
781
by Benjamin Drung
syncpackage: Don't crash if environment variables aren't set (LP: #665202). |
603 |
|
1279.1.1
by Evan Broder
sponsor-patch, requestsync, syncpackage: Add a config variable for -k arguments |
604 |
if options.keyid is None: |
605 |
options.keyid = config.get_value('KEYID') |
|
606 |
||
1121.1.1
by Stefano Rivera
Check the sync blacklist |
607 |
if options.lpinstance is None: |
608 |
options.lpinstance = config.get_value('LPINSTANCE') |
|
1306
by Stefano Rivera
syncpackage: Log into Launchpad anonymously with --no-lp |
609 |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
610 |
try: |
1210
by Stefano Rivera
Add changelog retrieval to lpapicache, and use this in syncpackage and |
611 |
# devel for copyPackage and changelogUrl
|
1306
by Stefano Rivera
syncpackage: Log into Launchpad anonymously with --no-lp |
612 |
kwargs = {'service': options.lpinstance, |
613 |
'api_version': 'devel'} |
|
614 |
if options.lp: |
|
615 |
Launchpad.login(**kwargs) |
|
616 |
else: |
|
617 |
Launchpad.login_anonymously(**kwargs) |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
618 |
except IOError: |
619 |
sys.exit(1) |
|
620 |
||
621 |
if options.release is None: |
|
622 |
ubuntu = Launchpad.distributions["ubuntu"] |
|
1352
by Colin Watson
syncpackage: Default to <current_series>-proposed. |
623 |
options.release = "%s-proposed" % ubuntu.current_series.name |
1121.1.1
by Stefano Rivera
Check the sync blacklist |
624 |
|
1251.1.13
by Stefano Rivera
Make syncpackage print a warning when --no-lp is used |
625 |
if not options.fakesync and not options.lp: |
626 |
Logger.warn("The use of --no-lp is not recommended for uploads " |
|
627 |
"targeted at Ubuntu. "
|
|
628 |
"The archive-admins discourage its use, except for "
|
|
629 |
"fakesyncs.") |
|
630 |
||
1251.1.4
by Stefano Rivera
Add sponsorship support |
631 |
sponsoree = None |
632 |
if options.sponsoree: |
|
633 |
try: |
|
634 |
sponsoree = PersonTeam(options.sponsoree) |
|
635 |
except KeyError: |
|
636 |
Logger.error('Cannot find the username "%s" in Launchpad.', |
|
637 |
options.sponsoree) |
|
638 |
sys.exit(1) |
|
639 |
||
640 |
if sponsoree and options.uploader_name is None: |
|
641 |
options.uploader_name = sponsoree.display_name |
|
642 |
elif options.uploader_name is None: |
|
643 |
options.uploader_name = ubu_email(export=False)[0] |
|
644 |
||
645 |
if sponsoree and options.uploader_email is None: |
|
646 |
try: |
|
647 |
options.uploader_email = sponsoree.preferred_email_address.email |
|
648 |
except ValueError: |
|
1251.1.11
by Stefano Rivera
Correct logic for obtaining email address for --no-lp sponsorship syncs |
649 |
if not options.lp: |
650 |
Logger.error("%s doesn't have a publicly visible e-mail " |
|
651 |
"address in LP, please provide one "
|
|
652 |
"--uploader-email option", sponsoree.display_name) |
|
653 |
sys.exit(1) |
|
1251.1.4
by Stefano Rivera
Add sponsorship support |
654 |
elif options.uploader_email is None: |
655 |
options.uploader_email = ubu_email(export=False)[1] |
|
656 |
||
1251.1.2
by Stefano Rivera
Remove unecessary optparse clutter |
657 |
src_pkg = fetch_source_pkg(package, options.distribution, |
658 |
options.debian_version, |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
659 |
options.component, |
1355
by Stefano Rivera
syncpackage: Don't throw away release pockets, returning correct errors |
660 |
options.release, |
1121.1.1
by Stefano Rivera
Check the sync blacklist |
661 |
options.debian_mirror) |
662 |
||
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
663 |
blacklisted, comments = is_blacklisted(src_pkg.source) |
1195
by Stefano Rivera
* syncpackage: |
664 |
blacklist_fail = False |
1121.1.1
by Stefano Rivera
Check the sync blacklist |
665 |
if blacklisted: |
1140
by Stefano Rivera
Wrap blacklist messages and comments |
666 |
messages = [] |
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
667 |
|
668 |
if blacklisted == 'CURRENT': |
|
1195
by Stefano Rivera
* syncpackage: |
669 |
Logger.debug("Source package %s is temporarily blacklisted " |
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
670 |
"(blacklisted_current). "
|
671 |
"Ubuntu ignores these for now. "
|
|
1195
by Stefano Rivera
* syncpackage: |
672 |
"See also LP: #841372", src_pkg.source) |
1121.1.7
by Stefano Rivera
Allow --force ing a blacklist override, when doing a non-native sync |
673 |
else: |
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
674 |
if options.fakesync: |
675 |
messages += ["Doing a fakesync, overriding blacklist."] |
|
1130
by Stefano Rivera
Make CURRENT DSD Blacklisting overrideable |
676 |
else: |
1195
by Stefano Rivera
* syncpackage: |
677 |
blacklist_fail = True |
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
678 |
messages += ["If this package needs a fakesync, " |
679 |
"use --fakesync", |
|
1196
by Stefano Rivera
Add --fakesync option, relegating --no-lp to really crazy corner cases. |
680 |
"If you think this package shouldn't be "
|
681 |
"blacklisted, please file a bug explaining your "
|
|
682 |
"reasoning and subscribe ~ubuntu-archive."] |
|
1138
by Stefano Rivera
Tweak log levels, use error when bailing out because of blacklisting, and normal for everything else blacklist-related |
683 |
|
1195
by Stefano Rivera
* syncpackage: |
684 |
if blacklist_fail: |
1138
by Stefano Rivera
Tweak log levels, use error when bailing out because of blacklisting, and normal for everything else blacklist-related |
685 |
Logger.error(u"Source package %s is blacklisted.", src_pkg.source) |
1195
by Stefano Rivera
* syncpackage: |
686 |
elif blacklisted == 'ALWAYS': |
1138
by Stefano Rivera
Tweak log levels, use error when bailing out because of blacklisting, and normal for everything else blacklist-related |
687 |
Logger.normal(u"Source package %s is blacklisted.", src_pkg.source) |
1140
by Stefano Rivera
Wrap blacklist messages and comments |
688 |
if messages: |
689 |
for message in messages: |
|
690 |
for line in textwrap.wrap(message): |
|
691 |
Logger.normal(line) |
|
1195
by Stefano Rivera
* syncpackage: |
692 |
|
693 |
if comments: |
|
694 |
Logger.normal("Blacklist Comments:") |
|
695 |
for comment in comments: |
|
696 |
for line in textwrap.wrap(comment): |
|
697 |
Logger.normal(u" " + line) |
|
698 |
||
699 |
if blacklist_fail: |
|
700 |
sys.exit(1) |
|
1121.1.1
by Stefano Rivera
Check the sync blacklist |
701 |
|
702 |
if options.lp: |
|
1251.1.4
by Stefano Rivera
Add sponsorship support |
703 |
copy(src_pkg, options.release, options.bugs, sponsoree, |
704 |
options.simulate, options.force) |
|
1116.2.1
by Colin Watson
syncpackage: Convert to new LP API, with --no-lp available for the old |
705 |
else: |
706 |
os.environ['DEB_VENDOR'] = 'Ubuntu' |
|
1251.1.3
by Stefano Rivera
Pyflakes & PEP-8 fine-tooth comb applied |
707 |
sync_dsc(src_pkg, options.distribution, options.release, |
708 |
options.uploader_name, options.uploader_email, options.bugs, |
|
709 |
options.ubuntu_mirror, options.keyid, options.simulate, |
|
710 |
options.force, options.fakesync) |
|
711 |
||
927
by Benjamin Drung
Make pylint a little bit happier. |
712 |
|
713 |
if __name__ == "__main__": |
|
1190
by Benjamin Drung
syncpackage: Catch user abort. |
714 |
try: |
715 |
main() |
|
716 |
except KeyboardInterrupt: |
|
717 |
Logger.normal('User abort.') |