Use ubuntutools.archive's rmadison code in requestsync.mail

This commit is contained in:
Stefano Rivera 2011-01-15 20:54:45 +02:00
parent b1b1c9a91a
commit 038cd428d3
2 changed files with 38 additions and 68 deletions

View File

@ -44,8 +44,6 @@ from ubuntutools.config import UDTConfig
from ubuntutools.logger import Logger from ubuntutools.logger import Logger
from ubuntutools.lp.lpapicache import (Launchpad, Distribution, from ubuntutools.lp.lpapicache import (Launchpad, Distribution,
SourcePackagePublishingHistory) SourcePackagePublishingHistory)
from ubuntutools.requestsync.mail import (SourcePackagePublishingHistory
as rmadison_SPPH)
class DownloadError(Exception): class DownloadError(Exception):
"Unable to pull a source package" "Unable to pull a source package"
@ -390,13 +388,12 @@ class DebianSourcePackage(SourcePackage):
continue continue
comp = record['component'] comp = record['component']
if record['version'] == self.version.full_version: if record['version'] == self.version.full_version:
self._spph = rmadison_SPPH(record['source'], self._spph = FakeSPPH(record['source'], record['version'],
record['version'], comp) comp)
return self._spph return self._spph
Logger.normal('Guessing component from most recent upload') Logger.normal('Guessing component from most recent upload')
self._spph = rmadison_SPPH(self.source, self.version.full_version, self._spph = FakeSPPH(self.source, self.version.full_version, comp)
comp)
return self._spph return self._spph
def _source_urls(self, name): def _source_urls(self, name):
@ -469,11 +466,35 @@ class UbuntuSourcePackage(SourcePackage):
distribution = 'ubuntu' distribution = 'ubuntu'
def rmadison(url, package): class FakeSPPH(object):
"""Provide the same interface as
ubuntutools.lpapicache.SourcePackagePublishingHistory
"""
def __init__(self, name, version, component):
self.name = name
self.version = version
self.component = component
def getPackageName(self):
return self.name
def getVersion(self):
return self.version
def getComponent(self):
return self.component
def rmadison(url, package, suite=None, arch=None):
"Call rmadison and parse the result" "Call rmadison and parse the result"
process = subprocess.Popen(('rmadison', '-u', url, package), cmd = ['rmadison', '-u', url]
stdout=subprocess.PIPE, stderr=subprocess.PIPE, if suite:
close_fds=True) cmd += ['-s', suite]
if arch:
cmd += ['-a', arch]
cmd.append(package)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
output = process.communicate()[0] output = process.communicate()[0]
assert process.wait() == 0 assert process.wait() == 0
for line in output.strip().splitlines(): for line in output.strip().splitlines():

View File

@ -2,7 +2,8 @@
# #
# mail.py - methods used by requestsync when used in "mail" mode # mail.py - methods used by requestsync when used in "mail" mode
# #
# Copyright © 2009 Michael Bienia <geser@ubuntu.com> # Copyright © 2009 Michael Bienia <geser@ubuntu.com>,
# 2011 Stefano Rivera <stefanor@ubuntu.com>
# #
# This module may contain code written by other authors/contributors to # This module may contain code written by other authors/contributors to
# the main requestsync script. See there for their names. # the main requestsync script. See there for their names.
@ -25,6 +26,7 @@ import subprocess
import smtplib import smtplib
import socket import socket
from debian.changelog import Version from debian.changelog import Version
from ubuntutools.archive import rmadison, FakeSPPH
from ubuntutools.requestsync.common import raw_input_exit_on_ctrlc from ubuntutools.requestsync.common import raw_input_exit_on_ctrlc
from ubuntutools.lp.udtexceptions import PackageNotFoundException from ubuntutools.lp.udtexceptions import PackageNotFoundException
@ -36,68 +38,15 @@ __all__ = [
'mailBug', 'mailBug',
] ]
class SourcePackagePublishingHistory(object):
'''
Simulate a SourcePackagePublishingHistory class from the LP API caching
module.
'''
def __init__(self, name, version, component):
self.name = name
self.version = version
self.component = component
def getPackageName(self):
return self.name
def getVersion(self):
return self.version
def getComponent(self):
return self.component
def rmadison(distro, package, release):
# Map 'sid' and 'squeeze' to their releasenames else rmadison gets a python
# traceback back from the remote script
releasenames = {
'sid': 'unstable',
'squeeze': 'testing', # Needs updating after each Debian release
}
release = releasenames.get(release, release)
rmadison_cmd = subprocess.Popen(['rmadison', '-u', distro, '-a', 'source',
'-s', release, package],
stdout=subprocess.PIPE)
rmadison_out = rmadison_cmd.communicate()[0]
assert (rmadison_cmd.returncode == 0)
# Return the most recent source line
lines = rmadison_out.splitlines()
if not lines:
# no output
return None
lines = [map(lambda x: x.strip(), line.split('|')) for line in lines]
lines = [line for line in lines if line[3].find('source') != -1]
if lines:
return max(lines, key = lambda x: Version(x[1]))
else:
# no source line
return None
def getSrcPkg(distro, name, release): def getSrcPkg(distro, name, release):
out = rmadison(distro, name, release) lines = list(rmadison(distro, name, suite=release, arch='source'))
if not out: if not lines:
raise PackageNotFoundException("'%s' doesn't appear to exist " raise PackageNotFoundException("'%s' doesn't appear to exist "
"in %s '%s'" "in %s '%s'"
% (name, distro.capitalize(), release)) % (name, distro.capitalize(), release))
pkg = max(lines, key=lambda x: Version(x['version']))
version = out[1] return FakeSPPH(pkg['source'], pkg['version'], pkg['component'])
component = 'main'
raw_comp = out[2].split('/')
if len(raw_comp) == 2:
component = raw_comp[1]
return SourcePackagePublishingHistory(name, version, component)
def getDebianSrcPkg(name, release): def getDebianSrcPkg(name, release):
return getSrcPkg('debian', name, release) return getSrcPkg('debian', name, release)