From 5e3e368bb83e952e1185a8e4bf003cda057af804 Mon Sep 17 00:00:00 2001 From: Michael Bienia Date: Thu, 6 Aug 2009 00:23:58 +0200 Subject: [PATCH] requestsync: some more refactoring --- requestsync | 14 +++-------- ubuntutools/requestsync/common.py | 10 ++++++++ ubuntutools/requestsync/lp.py | 6 +++++ ubuntutools/requestsync/mail.py | 42 ++++++++++++++++++++++--------- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/requestsync b/requestsync index 67d7272..edce8a0 100755 --- a/requestsync +++ b/requestsync @@ -40,8 +40,8 @@ from ubuntutools.lp.lpapicache import Launchpad, LpApiWrapper, Distribution, Per import ubuntutools.common import ubuntutools.packages -from ubuntutools.requestsync.mail import getDebianSrcPkg -from ubuntutools.requestsync.common import getDebianChangelog +from ubuntutools.requestsync.mail import * +from ubuntutools.requestsync.common import * def checkNeedsSponsorship(srcpkg): """ @@ -121,7 +121,7 @@ def checkExistingReports(package): def cur_version_component(sourcepkg, release): try: - src = Distribution('ubuntu').getArchive().getSourcePackage(sourcepkg, release) + src = getUbuntuSrcPkg(sourcepkg, release) return (src.getVersion(), src.getComponent()) except udtexceptions.PackageNotFoundException: @@ -129,14 +129,6 @@ def cur_version_component(sourcepkg, release): print "%s doesn't appear to exist in %s, specify -n for a package not in Ubuntu." % (sourcepkg, release) sys.exit(1) -def raw_input_exit_on_ctrlc(*args, **kwargs): - """A wrapper around raw_input() to exit with a normalized message on Control-C""" - try: - return raw_input(*args, **kwargs) - except KeyboardInterrupt: - print 'Abort requested. No sync request filed.' - sys.exit(1) - def get_email_address(): '''Get the DEBEMAIL environment variable or give an error.''' myemailaddr = os.getenv('DEBEMAIL') diff --git a/ubuntutools/requestsync/common.py b/ubuntutools/requestsync/common.py index 80b029b..2eb305b 100644 --- a/ubuntutools/requestsync/common.py +++ b/ubuntutools/requestsync/common.py @@ -23,6 +23,16 @@ import sys import urllib2 from debian_bundle.changelog import Changelog +def raw_input_exit_on_ctrlc(*args, **kwargs): + ''' + A wrapper around raw_input() to exit with a normalized message on Control-C + ''' + try: + return raw_input(*args, **kwargs) + except KeyboardInterrupt: + print 'Abort requested. No sync request filed.' + sys.exit(1) + def getDebianChangelog(srcpkg, version): ''' Return the new changelog entries upto 'version'. diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py index 19ca82b..f69080e 100644 --- a/ubuntutools/requestsync/lp.py +++ b/ubuntutools/requestsync/lp.py @@ -32,3 +32,9 @@ def getDebianSrcPkg(name, release): release = 'sid' return debian_archive.getSourcePackage(name, release) + +def getUbuntuSrcPkg(name, release): + ubuntu = Distribution('ubuntu') + ubuntu_archive = ubuntu.getArchive() + + return ubuntu_archive.getSourcePackage(name, release) diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py index a70684f..3410034 100644 --- a/ubuntutools/requestsync/mail.py +++ b/ubuntutools/requestsync/mail.py @@ -19,9 +19,11 @@ # Please see the /usr/share/common-licenses/GPL-2 file for the full text # of the GNU General Public License license. -from ..packages import checkIsInDebian +import subprocess from ..lp.udtexceptions import PackageNotFoundException +__all__ = ['getDebianSrcPkg', 'getUbuntuSrcPkg'] + # Simulate the SourcePackage class from lpapiwrapper class SourcePackage(object): ''' @@ -41,23 +43,39 @@ class SourcePackage(object): def getComponent(self): return self.component -def getDebianSrcPkg(name, release): - out = checkIsInDebian(name, release) - if not out: - raise PackageNotFoundException( - "'%s' doesn't appear to exist in Debian '%s'" % \ - (name, release)) +def rmadison(distro, package, 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) # Work-around for a bug in Debians madison.php script not returning # only the source line - for line in out.splitlines(): + for line in rmadison_out.splitlines(): if line.find('source') > 0: - out = line.split('|') + return map(lambda x: x.strip(), line.split('|')) - version = out[1].strip() + return None + +def getSrcPkg(distro, name, release): + out = rmadison(distro, name, release) + if not out: + raise PackageNotFoundException( + "'%s' doesn't appear to exist in %s '%s'" % \ + (name, distro.capitalize(), release)) + + version = out[1] component = 'main' raw_comp = out[2].split('/') if len(raw_comp) == 2: - component = raw_comp[1].strip() - + component = raw_comp[1] + return SourcePackage(name, version, component) + +def getDebianSrcPkg(name, release): + return getSrcPkg('debian', name, release) + +def getUbuntuSrcPkg(name, release): + return getSrcPkg('ubuntu', name, release)