mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-12 09:21:29 +00:00
requestsync: Give user option to retry in case of temporary error (LP: #850360)
This commit is contained in:
commit
121af2e631
1
debian/changelog
vendored
1
debian/changelog
vendored
@ -27,6 +27,7 @@ ubuntu-dev-tools (0.137) UNRELEASED; urgency=low
|
|||||||
* sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884)
|
* sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884)
|
||||||
* grep-merges: We already require a UTF-8 enabled terminal, so encode
|
* grep-merges: We already require a UTF-8 enabled terminal, so encode
|
||||||
package and uploader name in UTF-8 (LP: #694388)
|
package and uploader name in UTF-8 (LP: #694388)
|
||||||
|
* requestsync: Give user option to retry in case of temporary error (LP: #850360)
|
||||||
|
|
||||||
-- Andreas Moog <amoog@ubuntu.com> Wed, 30 Nov 2011 21:04:39 +0100
|
-- Andreas Moog <amoog@ubuntu.com> Wed, 30 Nov 2011 21:04:39 +0100
|
||||||
|
|
||||||
|
@ -21,9 +21,11 @@
|
|||||||
# of the GNU General Public License license.
|
# of the GNU General Public License license.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import smtplib
|
import smtplib
|
||||||
import socket
|
import socket
|
||||||
|
import tempfile
|
||||||
|
|
||||||
from debian.changelog import Changelog, Version
|
from debian.changelog import Changelog, Version
|
||||||
from devscripts.logger import Logger
|
from devscripts.logger import Logger
|
||||||
@ -162,14 +164,33 @@ Content-Type: text/plain; charset=UTF-8
|
|||||||
print 'The final report is:\n%s' % mail
|
print 'The final report is:\n%s' % mail
|
||||||
confirmation_prompt()
|
confirmation_prompt()
|
||||||
|
|
||||||
|
# save mail in temporary file
|
||||||
|
backup = tempfile.NamedTemporaryFile(mode='w', delete=False,
|
||||||
|
prefix='requestsync-' + re.sub(r'[^a-zA-Z0-9_-]', '',
|
||||||
|
bugtitle.replace(' ', '_')))
|
||||||
|
with backup:
|
||||||
|
backup.write(mail)
|
||||||
|
|
||||||
|
Logger.normal('The e-mail has been saved in %s and will be deleted '
|
||||||
|
'after succesful transmission', backup.name)
|
||||||
|
|
||||||
# connect to the server
|
# connect to the server
|
||||||
try:
|
while True:
|
||||||
Logger.info('Connecting to %s:%s ...', mailserver_host, mailserver_port)
|
try:
|
||||||
s = smtplib.SMTP(mailserver_host, mailserver_port)
|
Logger.normal('Connecting to %s:%s ...', mailserver_host,
|
||||||
except socket.error, s:
|
mailserver_port)
|
||||||
Logger.error('Could not connect to %s:%s: %s (%i)',
|
s = smtplib.SMTP(mailserver_host, mailserver_port)
|
||||||
mailserver_host, mailserver_port, s[1], s[0])
|
break
|
||||||
return
|
except socket.error, s:
|
||||||
|
Logger.error('Could not connect to %s:%s: %s (%i)',
|
||||||
|
mailserver_host, mailserver_port, s[1], s[0])
|
||||||
|
return
|
||||||
|
except smtplib.SMTPConnectError, s:
|
||||||
|
Logger.error('Could not connect to %s:%s: %s (%i)',
|
||||||
|
mailserver_host, mailserver_port, s[1], s[0])
|
||||||
|
if s.smtp_code == 421:
|
||||||
|
confirmation_prompt(message='This is a temporary error, press '
|
||||||
|
'[Enter] to retry. Press [Ctrl-C] to abort now.')
|
||||||
|
|
||||||
if mailserver_user and mailserver_pass:
|
if mailserver_user and mailserver_pass:
|
||||||
try:
|
try:
|
||||||
@ -184,6 +205,25 @@ Content-Type: text/plain; charset=UTF-8
|
|||||||
s.quit()
|
s.quit()
|
||||||
return
|
return
|
||||||
|
|
||||||
s.sendmail(myemailaddr, to, mail.encode('utf-8'))
|
while True:
|
||||||
s.quit()
|
try:
|
||||||
Logger.normal('Sync request mailed.')
|
s.sendmail(myemailaddr, to, mail.encode('utf-8'))
|
||||||
|
s.quit()
|
||||||
|
os.remove(backup.name)
|
||||||
|
Logger.normal('Sync request mailed.')
|
||||||
|
break
|
||||||
|
except smtplib.SMTPRecipientsRefused, smtperror:
|
||||||
|
smtp_code, smtp_message = smtperror.recipients[to]
|
||||||
|
Logger.error('Error while sending: %i, %s', smtp_code, smtp_message)
|
||||||
|
if smtp_code == 450:
|
||||||
|
confirmation_prompt(message='This is a temporary error, press '
|
||||||
|
'[Enter] to retry. Press [Ctrl-C] to abort now.')
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
except smtplib.SMTPResponseException, e:
|
||||||
|
Logger.error('Error while sending: %i, %s',
|
||||||
|
e.smtp_code, e.smtp_error)
|
||||||
|
return
|
||||||
|
except smtplib.SMTPServerDisconnected:
|
||||||
|
Logger.error('Server disconnected while sending the mail.')
|
||||||
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user