From 038cd428d3377dbc0c4079ddc8786d94ea506fa8 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 15 Jan 2011 20:54:45 +0200 Subject: [PATCH] Use ubuntutools.archive's rmadison code in requestsync.mail --- ubuntutools/archive.py | 41 ++++++++++++++++----- ubuntutools/requestsync/mail.py | 65 ++++----------------------------- 2 files changed, 38 insertions(+), 68 deletions(-) diff --git a/ubuntutools/archive.py b/ubuntutools/archive.py index fc620f4..3c24b12 100644 --- a/ubuntutools/archive.py +++ b/ubuntutools/archive.py @@ -44,8 +44,6 @@ from ubuntutools.config import UDTConfig from ubuntutools.logger import Logger from ubuntutools.lp.lpapicache import (Launchpad, Distribution, SourcePackagePublishingHistory) -from ubuntutools.requestsync.mail import (SourcePackagePublishingHistory - as rmadison_SPPH) class DownloadError(Exception): "Unable to pull a source package" @@ -390,13 +388,12 @@ class DebianSourcePackage(SourcePackage): continue comp = record['component'] if record['version'] == self.version.full_version: - self._spph = rmadison_SPPH(record['source'], - record['version'], comp) + self._spph = FakeSPPH(record['source'], record['version'], + comp) return self._spph Logger.normal('Guessing component from most recent upload') - self._spph = rmadison_SPPH(self.source, self.version.full_version, - comp) + self._spph = FakeSPPH(self.source, self.version.full_version, comp) return self._spph def _source_urls(self, name): @@ -469,11 +466,35 @@ class UbuntuSourcePackage(SourcePackage): 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" - process = subprocess.Popen(('rmadison', '-u', url, package), - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - close_fds=True) + cmd = ['rmadison', '-u', url] + if suite: + 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] assert process.wait() == 0 for line in output.strip().splitlines(): diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index 157d6e3..21c8669 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -2,7 +2,8 @@ # # mail.py - methods used by requestsync when used in "mail" mode # -# Copyright © 2009 Michael Bienia +# Copyright © 2009 Michael Bienia , +# 2011 Stefano Rivera # # This module may contain code written by other authors/contributors to # the main requestsync script. See there for their names. @@ -25,6 +26,7 @@ import subprocess import smtplib import socket from debian.changelog import Version +from ubuntutools.archive import rmadison, FakeSPPH from ubuntutools.requestsync.common import raw_input_exit_on_ctrlc from ubuntutools.lp.udtexceptions import PackageNotFoundException @@ -36,68 +38,15 @@ __all__ = [ '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): - out = rmadison(distro, name, release) - if not out: + lines = list(rmadison(distro, name, suite=release, arch='source')) + if not lines: raise PackageNotFoundException("'%s' doesn't appear to exist " "in %s '%s'" % (name, distro.capitalize(), release)) + pkg = max(lines, key=lambda x: Version(x['version'])) - version = out[1] - component = 'main' - raw_comp = out[2].split('/') - if len(raw_comp) == 2: - component = raw_comp[1] - - return SourcePackagePublishingHistory(name, version, component) + return FakeSPPH(pkg['source'], pkg['version'], pkg['component']) def getDebianSrcPkg(name, release): return getSrcPkg('debian', name, release)