diff --git a/requestsync b/requestsync index 98ef6f2..4c99203 100755 --- a/requestsync +++ b/requestsync @@ -41,6 +41,8 @@ from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper import ubuntutools.common import ubuntutools.packages +from ubuntutools.requestsync.mail import getDebianSrcPkg + def checkNeedsSponsorship(srcpkg): """ Check that the user has the appropriate permissions by checking what @@ -127,21 +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 cur_deb_version(sourcepkg, distro): - '''Return the current debian version of a package in a Debian distro.''' - out = ubuntutools.packages.checkIsInDebian(sourcepkg, distro) - if not out: - print "%s doesn't appear to exist in Debian." % sourcepkg - sys.exit(0) - - # Work-around for a bug in Debians madison.php script not returning - # only the source line - for line in out.splitlines(): - if line.find('source') > 0: - out = line - - return out.split('|')[1].rstrip('[]''').strip() - def debian_changelog(sourcepkg, component, version): '''Return the Debian changelog from the latest up to the given version (exclusive).''' @@ -171,24 +158,6 @@ def debian_changelog(sourcepkg, component, version): return ch -def debian_component(sourcepkg, distro): - '''Return the Debian component for the source package.''' - madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', '-s', distro, \ - sourcepkg], stdout=subprocess.PIPE) - out = madison.communicate()[0] - assert (madison.returncode == 0) - - try: - assert out - except AssertionError: - print "%s doesn't appear to exist in Debian." % sourcepkg - sys.exit(1) - raw_comp = out.split('|')[2].split('/') - component = 'main' - if len(raw_comp) == 2: - component = raw_comp[1].strip() - return component - def raw_input_exit_on_ctrlc(*args, **kwargs): """A wrapper around raw_input() to exit with a normalized message on Control-C""" try: @@ -489,9 +458,10 @@ if __name__ == '__main__': # Find Ubuntu release's package version. if not newsource: (cur_ver, component) = cur_version_component(srcpkg, release) - debiancomponent = debian_component(srcpkg, distro) + debsrcpkg = getDebianSrcPkg(srcpkg, distro) + debiancomponent = debsrcpkg.getComponent() # Find Debian release's package version. - deb_version = cur_deb_version(srcpkg, distro) + deb_version = debsrcpkg.getVersion() # Debian and Ubuntu versions are the same - stop. if deb_version == cur_ver: diff --git a/ubuntutools/requestsync/__init__.py b/ubuntutools/requestsync/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ubuntutools/requestsync/common.py b/ubuntutools/requestsync/common.py new file mode 100644 index 0000000..ecfcbe4 --- /dev/null +++ b/ubuntutools/requestsync/common.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# +# common.py - common methods used by requestsync +# +# Copyright © 2009 Michael Bienia +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Please see the /usr/share/common-licenses/GPL file for the full text +# of the GNU General Public License license. + +import sys +import urllib2 +from debian_bundle.changelog import Changelog + +def debian_changelog(srcpkg, version): + ''' + Return the new changelog entries upto 'version'. + ''' + pkgname = srcpkg.getPackageName() + component = srcpkg.getComponent() + if pkgname.startswith('lib'): + subdir = 'lib%s' % pkgname[3] + else: + subdir = pkgname[0] + + # Get the debian changelog file from packages.debian.org + try: + changelog = urllib2.urlopen( + 'http://packages.debian.org/changelogs/pool/%s/%s/%s/current/changelog.txt' % \ + (component, subdir, pkgname)) + except urllib2.HTTPError, error: + print >> sys.stderr, 'Unable to connect to packages.debian.org: %s' % error + return None + + new_entries = '' + changelog = Changelog(changelog.read()) + for block in changelog._blocks: + if block.version > version: + new_entries += str(block) + + return new_entries diff --git a/ubuntutools/requestsync/lp.py b/ubuntutools/requestsync/lp.py new file mode 100644 index 0000000..c093650 --- /dev/null +++ b/ubuntutools/requestsync/lp.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# +# lp.py - methods used by requestsync while interacting +# directly with Launchpad +# +# Copyright © 2009 Michael Bienia +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Please see the /usr/share/common-licenses/GPL file for the full text +# of the GNU General Public License license. + +from ..lp.lpapiwrapper import Distribution +from ..lp.udtexceptions import * + +def getDebianSrcPkg(name, release): + debian = Distribution('debian') + debian_archive = debian.getArchive() + + # Map 'unstable' to 'sid' as LP doesn't know 'unstable' but only 'sid' + if release == 'unstable': + release = 'sid' + + return debian_archive.getSourcePackage(name, release) diff --git a/ubuntutools/requestsync/mail.py b/ubuntutools/requestsync/mail.py new file mode 100644 index 0000000..1723066 --- /dev/null +++ b/ubuntutools/requestsync/mail.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# mail.py - methods used by requestsync when used in "mail" mode +# +# Copyright © 2009 Michael Bienia +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Please see the /usr/share/common-licenses/GPL file for the full text +# of the GNU General Public License license. + +from ..packages import checkIsInDebian +from ..lp.udtexceptions import PackageNotFoundException + +# Simulate the SourcePackage class from lpapiwrapper +class SourcePackage(object): + ''' + Simulate a SourcePackage class from the LP API wrapper 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 getDebianSrcPkg(name, release): + out = checkIsInDebian(name, release) + if not out: + raise PackageNotFoundException( + "'%s' doesn't appear to exist in Debian '%s'" % \ + (name, release)) + + # Work-around for a bug in Debians madison.php script not returning + # only the source line + for line in out.splitlines(): + if line.find('source') > 0: + out = line.split('|') + + version = out[1].strip() + component = 'main' + raw_comp = out[2].split('/') + if len(raw_comp) == 2: + component = raw_comp[1].strip() + + return SourcePackage(name, version, component)