mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-16 01:21:07 +00:00
requestsync:
- move mail_bug() to ubuntutools.requestsync.mail - implement support for UBU* environment variables (lp: #400133)
This commit is contained in:
parent
ec92bb5d75
commit
e628bfbe34
4
debian/changelog
vendored
4
debian/changelog
vendored
@ -14,6 +14,8 @@ ubuntu-dev-tools (0.76) UNRELEASED; urgency=low
|
|||||||
[ Michael Bienia ]
|
[ Michael Bienia ]
|
||||||
* Drop python-launchpad-bugs from Depends.
|
* Drop python-launchpad-bugs from Depends.
|
||||||
* buildd: Add a --batch mode for batch retrying/rescoring of packages.
|
* buildd: Add a --batch mode for batch retrying/rescoring of packages.
|
||||||
|
* requestsync:
|
||||||
|
- Use UBU* environment variables before the DEB* ones (lp: #400133)
|
||||||
|
|
||||||
[ Iain Lane ]
|
[ Iain Lane ]
|
||||||
* requestsync:
|
* requestsync:
|
||||||
@ -39,7 +41,7 @@ ubuntu-dev-tools (0.76) UNRELEASED; urgency=low
|
|||||||
- debian/rules: set DEB_PYTHON_SYSTEM to pysupport.
|
- debian/rules: set DEB_PYTHON_SYSTEM to pysupport.
|
||||||
- ubuntu-dev-tools.preinst: remove stale pycentral files on upgrades.
|
- ubuntu-dev-tools.preinst: remove stale pycentral files on upgrades.
|
||||||
|
|
||||||
-- Luca Falavigna <dktrkranz@ubuntu.com> Fri, 21 Aug 2009 17:30:05 +0200
|
-- Michael Bienia <geser@ubuntu.com> Sat, 22 Aug 2009 17:10:13 +0200
|
||||||
|
|
||||||
ubuntu-dev-tools (0.75) karmic; urgency=low
|
ubuntu-dev-tools (0.75) karmic; urgency=low
|
||||||
|
|
||||||
|
101
requestsync
101
requestsync
@ -92,103 +92,6 @@ def checkExistingReports(package):
|
|||||||
"please press enter."
|
"please press enter."
|
||||||
raw_input_exit_on_ctrlc()
|
raw_input_exit_on_ctrlc()
|
||||||
|
|
||||||
def mail_bug(source_package, subscribe, status, bugtitle, bugtext, keyid = None):
|
|
||||||
'''Submit the sync request per email.
|
|
||||||
Return True if email successfully send, otherwise False.'''
|
|
||||||
|
|
||||||
import smtplib
|
|
||||||
import socket
|
|
||||||
|
|
||||||
to = 'new@bugs.launchpad.net'
|
|
||||||
|
|
||||||
myemailaddr = get_email_address()
|
|
||||||
if not myemailaddr:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# generate initial mailbody
|
|
||||||
mailbody = ''
|
|
||||||
if source_package:
|
|
||||||
mailbody += ' affects ubuntu/%s\n' % source_package
|
|
||||||
else:
|
|
||||||
mailbody += ' affects ubuntu\n'
|
|
||||||
mailbody = mailbody + ' status %s\n importance wishlist\n subscribe %s\n done\n\n%s' % (status, subscribe, bugtext)
|
|
||||||
|
|
||||||
# prepare sign_command
|
|
||||||
sign_command = 'gpg'
|
|
||||||
for cmd in ('gpg2', 'gnome-gpg'):
|
|
||||||
if os.access('/usr/bin/%s' % cmd, os.X_OK):
|
|
||||||
sign_command = cmd
|
|
||||||
|
|
||||||
gpg_command = [sign_command, '--clearsign']
|
|
||||||
if keyid:
|
|
||||||
gpg_command.extend(('-u', keyid))
|
|
||||||
|
|
||||||
# sign it
|
|
||||||
gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
|
||||||
signed_report = gpg.communicate(mailbody)[0]
|
|
||||||
assert gpg.returncode == 0
|
|
||||||
|
|
||||||
# generate email
|
|
||||||
mail = '''\
|
|
||||||
From: %s
|
|
||||||
To: %s
|
|
||||||
Subject: %s
|
|
||||||
Content-Type: text/plain; charset=UTF-8
|
|
||||||
|
|
||||||
%s''' % (myemailaddr, to, bugtitle, signed_report)
|
|
||||||
|
|
||||||
# ask for confirmation and allow to edit:
|
|
||||||
print mail
|
|
||||||
print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.'
|
|
||||||
raw_input_exit_on_ctrlc()
|
|
||||||
|
|
||||||
# get server address
|
|
||||||
mailserver = os.getenv('DEBSMTP')
|
|
||||||
if mailserver:
|
|
||||||
print 'Using custom SMTP server:', mailserver
|
|
||||||
else:
|
|
||||||
mailserver = 'fiordland.ubuntu.com'
|
|
||||||
|
|
||||||
# get server port
|
|
||||||
mailserver_port = os.getenv('DEBSMTP_PORT')
|
|
||||||
if mailserver_port:
|
|
||||||
print 'Using custom SMTP port:', mailserver_port
|
|
||||||
else:
|
|
||||||
mailserver_port = 25
|
|
||||||
|
|
||||||
# connect to the server
|
|
||||||
try:
|
|
||||||
s = smtplib.SMTP(mailserver, mailserver_port)
|
|
||||||
except socket.error, s:
|
|
||||||
print >> sys.stderr, "Could not connect to mailserver %s at port %s: %s (%i)" % \
|
|
||||||
(mailserver, mailserver_port, s[1], s[0])
|
|
||||||
print "The port %s may be firewalled. Please try using requestsync with" \
|
|
||||||
% mailserver_port
|
|
||||||
print "the '--lp' flag to file a sync request with the launchpadlib " \
|
|
||||||
"module."
|
|
||||||
return False
|
|
||||||
|
|
||||||
# authenticate to the server
|
|
||||||
mailserver_user = os.getenv('DEBSMTP_USER')
|
|
||||||
mailserver_pass = os.getenv('DEBSMTP_PASS')
|
|
||||||
if mailserver_user and mailserver_pass:
|
|
||||||
try:
|
|
||||||
s.login(mailserver_user, mailserver_pass)
|
|
||||||
except smtplib.SMTPAuthenticationError:
|
|
||||||
print 'Error authenticating to the server: invalid username and password.'
|
|
||||||
s.quit()
|
|
||||||
return False
|
|
||||||
except:
|
|
||||||
print 'Unknown SMTP error.'
|
|
||||||
s.quit()
|
|
||||||
return False
|
|
||||||
|
|
||||||
s.sendmail(myemailaddr, to, mail)
|
|
||||||
s.quit()
|
|
||||||
print 'Sync request mailed.'
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# entry point
|
# entry point
|
||||||
@ -232,7 +135,7 @@ if __name__ == '__main__':
|
|||||||
distro = options.dist
|
distro = options.dist
|
||||||
ffe = options.ffe
|
ffe = options.ffe
|
||||||
|
|
||||||
if not use_lp_bugs and not get_email_address():
|
if not use_lp_bugs and not getEmailAddress():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
@ -366,7 +269,7 @@ if __name__ == '__main__':
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Mail sync request:
|
# Mail sync request:
|
||||||
if mail_bug(srcpkg, subscribe, status, title, report, keyid):
|
if mailBug(srcpkg, subscribe, status, title, report, keyid):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
print 'Something went wrong. No sync request filed.'
|
print 'Something went wrong. No sync request filed.'
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import smtplib
|
||||||
|
import socket
|
||||||
from .common import raw_input_exit_on_ctrlc
|
from .common import raw_input_exit_on_ctrlc
|
||||||
from ..lp.udtexceptions import PackageNotFoundException
|
from ..lp.udtexceptions import PackageNotFoundException
|
||||||
|
|
||||||
@ -83,12 +85,12 @@ def getDebianSrcPkg(name, release):
|
|||||||
def getUbuntuSrcPkg(name, release):
|
def getUbuntuSrcPkg(name, release):
|
||||||
return getSrcPkg('ubuntu', name, release)
|
return getSrcPkg('ubuntu', name, release)
|
||||||
|
|
||||||
def get_email_address():
|
def getEmailAddress():
|
||||||
'''
|
'''
|
||||||
Get the From email address from the DEBEMAIL or EMAIL environment
|
Get the From email address from the UBUMAIL, DEBEMAIL or EMAIL
|
||||||
variable or give an error.
|
environment variable or give an error.
|
||||||
'''
|
'''
|
||||||
myemailaddr = os.getenv('DEBEMAIL') or os.getenv('EMAIL')
|
myemailaddr = os.getenv('UBUMAIL') or os.getenv('DEBEMAIL') or os.getenv('EMAIL')
|
||||||
if not myemailaddr:
|
if not myemailaddr:
|
||||||
print >> sys.stderr, 'The environment variable DEBEMAIL or ' \
|
print >> sys.stderr, 'The environment variable DEBEMAIL or ' \
|
||||||
'EMAIL needs to be set to let this script mail the ' \
|
'EMAIL needs to be set to let this script mail the ' \
|
||||||
@ -111,3 +113,87 @@ def needSponsorship(name, component):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print 'Invalid answer'
|
print 'Invalid answer'
|
||||||
|
|
||||||
|
def mailBug(srcpkg, subscribe, status, bugtitle, bugtext, keyid = None):
|
||||||
|
'''
|
||||||
|
Submit the sync request per email.
|
||||||
|
'''
|
||||||
|
|
||||||
|
to = 'new@bugs.launchpad.net'
|
||||||
|
|
||||||
|
# getEmailAddress() can't fail here as the main code in requestsync
|
||||||
|
# already checks its return value
|
||||||
|
myemailaddr = getEmailAddress()
|
||||||
|
|
||||||
|
# generate mailbody
|
||||||
|
if srcpkg:
|
||||||
|
mailbody = ' affects ubuntu/%s\n' % srcpkg.getPackageName()
|
||||||
|
else:
|
||||||
|
mailbody = ' affects ubuntu\n'
|
||||||
|
mailbody += '''\
|
||||||
|
status %s
|
||||||
|
importance wishlist
|
||||||
|
subscribe %s
|
||||||
|
done
|
||||||
|
|
||||||
|
%s''' % (status, subscribe, bugtext)
|
||||||
|
|
||||||
|
# prepare sign command
|
||||||
|
gpg_command = None
|
||||||
|
for cmd in ('gpg', 'gpg2', 'gnome-gpg'):
|
||||||
|
if os.access('/usr/bin/%s' % cmd, os.X_OK):
|
||||||
|
gpg_command = [cmd]
|
||||||
|
assert gpg_command # TODO: catch exception and produce error message
|
||||||
|
|
||||||
|
gpg_command.append('--clearsign')
|
||||||
|
if keyid:
|
||||||
|
gpg_command.extend(('-u', keyid))
|
||||||
|
|
||||||
|
# sign the mail body
|
||||||
|
gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
|
||||||
|
signed_report = gpg.communicate(mailbody)[0]
|
||||||
|
assert gpg.returncode == 0
|
||||||
|
|
||||||
|
# generate email
|
||||||
|
mail = '''\
|
||||||
|
From: %s
|
||||||
|
To: %s
|
||||||
|
Subject: %s
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
|
||||||
|
%s''' % (myemailaddr, to, bugtitle, signed_report)
|
||||||
|
|
||||||
|
print 'The final report is:\n%s' % mail
|
||||||
|
raw_input_exit_on_ctrlc('Press [Enter] to continue or [Ctrl-C] to abort. ')
|
||||||
|
|
||||||
|
# get server address and port
|
||||||
|
mailserver_host = os.getenv('UBUSMTP') or os.getenv('DEBSMTP') or 'fiordland.ubuntu.com'
|
||||||
|
mailserver_port = os.getenv('UBUSMTP_PORT') or os.getenv('DEBSMTP_PORT') or 25
|
||||||
|
|
||||||
|
# connect to the server
|
||||||
|
try:
|
||||||
|
print 'Connecting to %s:%s ...' % (mailserver_host, mailserver_port)
|
||||||
|
s = smtplib.SMTP(mailserver_host, mailserver_port)
|
||||||
|
except socket.error, s:
|
||||||
|
print >> sys.stderr, "Could not connect to %s:%s: %s (%i)" % \
|
||||||
|
(mailserver_host, mailserver_port, s[1], s[0])
|
||||||
|
return
|
||||||
|
|
||||||
|
# authenticate to the server
|
||||||
|
mailserver_user = os.getenv('UBUSMTP_USER') or os.getenv('DEBSMTP_USER')
|
||||||
|
mailserver_pass = os.getenv('UBUSMTP_PASS') or os.getenv('DEBSMTP_PASS')
|
||||||
|
if mailserver_user and mailserver_pass:
|
||||||
|
try:
|
||||||
|
s.login(mailserver_user, mailserver_pass)
|
||||||
|
except smtplib.SMTPAuthenticationError:
|
||||||
|
print 'Error authenticating to the server: invalid username and password.'
|
||||||
|
s.quit()
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
print 'Unknown SMTP error.'
|
||||||
|
s.quit()
|
||||||
|
return
|
||||||
|
|
||||||
|
s.sendmail(myemailaddr, to, mail)
|
||||||
|
s.quit()
|
||||||
|
print 'Sync request mailed.'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user