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-07 12:53:33 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2009-08-06 00:23:58 +02:00
|
|
|
import subprocess
|
2009-08-07 14:07:46 +02:00
|
|
|
from .common import raw_input_exit_on_ctrlc
|
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-06 16:26:29 +02:00
|
|
|
class SourcePackagePublishingHistory(object):
|
2009-08-04 13:43:31 +02:00
|
|
|
'''
|
2009-08-06 16:26:29 +02:00
|
|
|
Simulate a SourcePackagePublishingHistory class from the LP API caching
|
|
|
|
module.
|
2009-08-04 13:43:31 +02:00
|
|
|
'''
|
|
|
|
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-06 16:26:29 +02:00
|
|
|
return SourcePackagePublishingHistory(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)
|
2009-08-07 12:53:33 +02:00
|
|
|
|
|
|
|
def get_email_address():
|
|
|
|
'''
|
|
|
|
Get the From email address from the DEBEMAIL or EMAIL environment
|
|
|
|
variable or give an error.
|
|
|
|
'''
|
|
|
|
myemailaddr = os.getenv('DEBEMAIL') or os.getenv('EMAIL')
|
|
|
|
if not myemailaddr:
|
|
|
|
print >> sys.stderr, 'The environment variable DEBEMAIL or ' \
|
|
|
|
'EMAIL needs to be set to let this script mail the ' \
|
|
|
|
'sync request.'
|
|
|
|
return myemailaddr
|
2009-08-07 14:07:46 +02:00
|
|
|
|
|
|
|
def needSponsorship(name, component):
|
|
|
|
'''
|
|
|
|
Ask the user if he has upload permissions for the package or the
|
|
|
|
component.
|
|
|
|
'''
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
print "Do you have upload permissions for the '%s' component " \
|
|
|
|
"or the package '%s'?" % (component, name)
|
|
|
|
val = raw_input_exit_on_ctrlc("If in doubt answer 'no'. [y/N]? ")
|
|
|
|
if val.lower() in ('y', 'yes'):
|
|
|
|
return False
|
|
|
|
elif val.lower() in ('n', 'no', ''):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
print 'Invalid answer'
|