Merge branch 'pull-debian-source-edge-cases' of git+ssh://git.launchpad.net/~racb/ubuntu-dev-tools

MR: https://code.launchpad.net/~racb/ubuntu-dev-tools/+git/ubuntu-dev-tools/+merge/326608
Signed-off-by: Mattia Rizzolo <mattia@debian.org>
This commit is contained in:
Mattia Rizzolo 2019-07-20 15:10:35 +02:00
commit 3f87486de3
No known key found for this signature in database
GPG Key ID: 0816B9E18C762BAD
3 changed files with 30 additions and 15 deletions

10
debian/changelog vendored
View File

@ -1,3 +1,13 @@
ubuntu-dev-tools (0.170) UNRELEASED; urgency=medium
[ Robie Basak ]
* pull-debian-source:
+ Add a new --no-verify-signature option option, to download a source
package without checking its signature.
+ Port to Python 3.
-- Mattia Rizzolo <mattia@debian.org> Sat, 20 Jul 2019 15:09:05 +0200
ubuntu-dev-tools (0.169) unstable; urgency=medium ubuntu-dev-tools (0.169) unstable; urgency=medium
[ Colin Watson ] [ Colin Watson ]

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# pull-debian-source -- pull a source package from Launchpad # pull-debian-source -- pull a source package from Launchpad
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com> # Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
@ -19,7 +19,8 @@
import json import json
import optparse import optparse
import sys import sys
import urllib2 import urllib.request
import urllib.error
from distro_info import DebianDistroInfo, DistroDataOutdated from distro_info import DebianDistroInfo, DistroDataOutdated
@ -54,17 +55,17 @@ def source_package_for(binary, release):
"""Query DDE to find the source package for a particular binary""" """Query DDE to find the source package for a particular binary"""
try: try:
release = DebianDistroInfo().codename(release, default=release) release = DebianDistroInfo().codename(release, default=release)
except DistroDataOutdated, e: except DistroDataOutdated as e:
Logger.warn(e) Logger.warn(e)
url = ('http://dde.debian.net/dde/q/udd/dist/d:debian/r:%s/p:%s/?t=json' url = ('http://dde.debian.net/dde/q/udd/dist/d:debian/r:%s/p:%s/?t=json'
% (release, binary)) % (release, binary))
data = None data = None
try: try:
data = json.load(urllib2.urlopen(url))['r'] data = json.load(urllib.request.urlopen(url))['r']
except urllib2.URLError, e: except urllib.error.URLError as e:
Logger.error('Unable to retrieve package information from DDE: ' Logger.error('Unable to retrieve package information from DDE: '
'%s (%s)', url, str(e)) '%s (%s)', url, str(e))
except ValueError, e: except ValueError as e:
Logger.error('Unable to parse JSON response from DDE: ' Logger.error('Unable to parse JSON response from DDE: '
'%s (%s)', url, str(e)) '%s (%s)', url, str(e))
if not data: if not data:
@ -89,6 +90,10 @@ def main():
parser.add_option('--no-conf', parser.add_option('--no-conf',
dest='no_conf', default=False, action='store_true', dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables") help="Don't read config files or environment variables")
parser.add_option('--no-verify-signature',
dest='verify_signature', default=True,
action='store_false',
help="Allow signature verification failure")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if not args: if not args:
parser.error('Must specify package name') parser.error('Must specify package name')
@ -128,8 +133,8 @@ def main():
mirrors=[options.debian_mirror, mirrors=[options.debian_mirror,
options.debsec_mirror]) options.debsec_mirror])
try: try:
srcpkg.pull() srcpkg.pull(verify_signature=options.verify_signature)
except DownloadError, e: except DownloadError as e:
Logger.error('Failed to download: %s', str(e)) Logger.error('Failed to download: %s', str(e))
sys.exit(1) sys.exit(1)
if not options.download_only: if not options.download_only:

View File

@ -303,10 +303,10 @@ class SourcePackage(object):
else: else:
Logger.info(message) Logger.info(message)
def _write_dsc(self): def _write_dsc(self, verify_signature=True):
"Write dsc file to workdir" "Write dsc file to workdir"
if self._dsc is None: if self._dsc is None:
self.pull_dsc() self.pull_dsc(verify_signature=verify_signature)
with open(self.dsc_pathname, 'wb') as f: with open(self.dsc_pathname, 'wb') as f:
f.write(self.dsc.raw_text) f.write(self.dsc.raw_text)
@ -359,9 +359,9 @@ class SourcePackage(object):
return False return False
return True return True
def pull(self): def pull(self, verify_signature=True):
"Pull into workdir" "Pull into workdir"
self._write_dsc() self._write_dsc(verify_signature=verify_signature)
for entry in self.dsc['Files']: for entry in self.dsc['Files']:
name = entry['name'] name = entry['name']
for url in self._source_urls(name): for url in self._source_urls(name):
@ -471,7 +471,7 @@ class DebianSourcePackage(SourcePackage):
if self.snapshot_list: if self.snapshot_list:
yield self._snapshot_url(name) yield self._snapshot_url(name)
def pull_dsc(self): def pull_dsc(self, verify_signature=True):
"Retrieve dscfile and parse" "Retrieve dscfile and parse"
try: try:
super(DebianSourcePackage, self).pull_dsc() super(DebianSourcePackage, self).pull_dsc()
@ -489,7 +489,7 @@ class DebianSourcePackage(SourcePackage):
break break
else: else:
raise DownloadError('dsc could not be found anywhere') raise DownloadError('dsc could not be found anywhere')
self._check_dsc(verify_signature=True) self._check_dsc(verify_signature=verify_signature)
# Local methods: # Local methods:
@property @property
@ -636,7 +636,7 @@ def rmadison(url, package, suite=None, arch=None):
# pylint bug: http://www.logilab.org/ticket/46273 # pylint bug: http://www.logilab.org/ticket/46273
# pylint: disable=E1103 # pylint: disable=E1103
for line in output.strip().splitlines(): for line in output.decode().strip().splitlines():
# pylint: enable=E1103 # pylint: enable=E1103
pkg, ver, dist, archs = [x.strip() for x in line.split('|')] pkg, ver, dist, archs = [x.strip() for x in line.split('|')]
comp = 'main' comp = 'main'