mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-12 23:51:08 +00:00
requestsync: refactor some code into its own module
and provide versions of the methods w/ and w/o LP API usage
This commit is contained in:
parent
4779d7b1a7
commit
df881ec2da
40
requestsync
40
requestsync
@ -41,6 +41,8 @@ from ubuntutools.lp.lpapiwrapper import Launchpad, LpApiWrapper
|
|||||||
import ubuntutools.common
|
import ubuntutools.common
|
||||||
import ubuntutools.packages
|
import ubuntutools.packages
|
||||||
|
|
||||||
|
from ubuntutools.requestsync.mail import getDebianSrcPkg
|
||||||
|
|
||||||
def checkNeedsSponsorship(srcpkg):
|
def checkNeedsSponsorship(srcpkg):
|
||||||
"""
|
"""
|
||||||
Check that the user has the appropriate permissions by checking what
|
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)
|
print "%s doesn't appear to exist in %s, specify -n for a package not in Ubuntu." % (sourcepkg, release)
|
||||||
sys.exit(1)
|
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):
|
def debian_changelog(sourcepkg, component, version):
|
||||||
'''Return the Debian changelog from the latest up to the given version
|
'''Return the Debian changelog from the latest up to the given version
|
||||||
(exclusive).'''
|
(exclusive).'''
|
||||||
@ -171,24 +158,6 @@ def debian_changelog(sourcepkg, component, version):
|
|||||||
|
|
||||||
return ch
|
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):
|
def raw_input_exit_on_ctrlc(*args, **kwargs):
|
||||||
"""A wrapper around raw_input() to exit with a normalized message on Control-C"""
|
"""A wrapper around raw_input() to exit with a normalized message on Control-C"""
|
||||||
try:
|
try:
|
||||||
@ -489,9 +458,10 @@ if __name__ == '__main__':
|
|||||||
# Find Ubuntu release's package version.
|
# Find Ubuntu release's package version.
|
||||||
if not newsource: (cur_ver, component) = cur_version_component(srcpkg, release)
|
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.
|
# 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.
|
# Debian and Ubuntu versions are the same - stop.
|
||||||
if deb_version == cur_ver:
|
if deb_version == cur_ver:
|
||||||
|
0
ubuntutools/requestsync/__init__.py
Normal file
0
ubuntutools/requestsync/__init__.py
Normal file
50
ubuntutools/requestsync/common.py
Normal file
50
ubuntutools/requestsync/common.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# common.py - common methods used by requestsync
|
||||||
|
#
|
||||||
|
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
||||||
|
#
|
||||||
|
# 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
|
32
ubuntutools/requestsync/lp.py
Normal file
32
ubuntutools/requestsync/lp.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# lp.py - methods used by requestsync while interacting
|
||||||
|
# directly with Launchpad
|
||||||
|
#
|
||||||
|
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
||||||
|
#
|
||||||
|
# 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)
|
61
ubuntutools/requestsync/mail.py
Normal file
61
ubuntutools/requestsync/mail.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# mail.py - methods used by requestsync when used in "mail" mode
|
||||||
|
#
|
||||||
|
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
||||||
|
#
|
||||||
|
# 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)
|
Loading…
x
Reference in New Issue
Block a user