2009-08-04 13:43:31 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# mail.py - methods used by requestsync when used in "mail" mode
|
|
|
|
#
|
|
|
|
# Copyright © 2009 Michael Bienia <geser@ubuntu.com>
|
|
|
|
#
|
2009-08-05 23:10:05 +02:00
|
|
|
# This module may contain code written by other authors/contributors to
|
|
|
|
# the main requestsync script. See there for their names.
|
|
|
|
#
|
2009-08-04 13:43:31 +02:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
2009-08-05 23:10:05 +02:00
|
|
|
# as published by the Free Software Foundation; version 2
|
2009-08-04 13:43:31 +02:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2009-08-05 23:10:05 +02:00
|
|
|
# Please see the /usr/share/common-licenses/GPL-2 file for the full text
|
2009-08-04 13:43:31 +02:00
|
|
|
# of the GNU General Public License license.
|
|
|
|
|
2009-08-06 00:23:58 +02:00
|
|
|
import subprocess
|
2009-08-04 13:43:31 +02:00
|
|
|
from ..lp.udtexceptions import PackageNotFoundException
|
|
|
|
|
2009-08-06 00:23:58 +02:00
|
|
|
__all__ = ['getDebianSrcPkg', 'getUbuntuSrcPkg']
|
|
|
|
|
2009-08-04 13:43:31 +02:00
|
|
|
# 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
|
|
|
|
|
2009-08-06 00:23:58 +02:00
|
|
|
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)
|
2009-08-04 13:43:31 +02:00
|
|
|
|
|
|
|
# Work-around for a bug in Debians madison.php script not returning
|
|
|
|
# only the source line
|
2009-08-06 00:23:58 +02:00
|
|
|
for line in rmadison_out.splitlines():
|
2009-08-04 13:43:31 +02:00
|
|
|
if line.find('source') > 0:
|
2009-08-06 00:23:58 +02:00
|
|
|
return map(lambda x: x.strip(), line.split('|'))
|
|
|
|
|
|
|
|
return None
|
2009-08-04 13:43:31 +02:00
|
|
|
|
2009-08-06 00:23:58 +02:00
|
|
|
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]
|
2009-08-04 13:43:31 +02:00
|
|
|
component = 'main'
|
|
|
|
raw_comp = out[2].split('/')
|
|
|
|
if len(raw_comp) == 2:
|
2009-08-06 00:23:58 +02:00
|
|
|
component = raw_comp[1]
|
|
|
|
|
2009-08-04 13:43:31 +02:00
|
|
|
return SourcePackage(name, version, component)
|
2009-08-06 00:23:58 +02:00
|
|
|
|
|
|
|
def getDebianSrcPkg(name, release):
|
|
|
|
return getSrcPkg('debian', name, release)
|
|
|
|
|
|
|
|
def getUbuntuSrcPkg(name, release):
|
|
|
|
return getSrcPkg('ubuntu', name, release)
|