Merge lp:~ampelbein/ubuntu-dev-tools/fix-850360 into lp:~ubuntu-dev/ubuntu-dev-tools/trunk

Proposed by Andreas Moog
Status: Merged
Merged at revision: 1250
Proposed branch: lp:~ampelbein/ubuntu-dev-tools/fix-850360
Merge into: lp:~ubuntu-dev/ubuntu-dev-tools/trunk
Diff against target: 86 lines (+43/-10)
2 files modified
debian/changelog (+1/-0)
ubuntutools/requestsync/mail.py (+42/-10)
To merge this branch: bzr merge lp:~ampelbein/ubuntu-dev-tools/fix-850360
Reviewer Review Type Date Requested Status
Stefano Rivera Approve
Review via email: mp+83530@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

I'd prefer .smtp_code to [0]

Can you wrap the long line?

Should we maybe dump the e-mail in . (or /tmp/) and print the filename if there's any error in sending it?

1246. By Andreas Moog

Wrap long line

Revision history for this message
Andreas Moog (ampelbein) wrote :

1+2 done.

I was thinking about saving the mail in /tmp/requestsync-$PACKAGE before sending and delete the file after succesfully sending the mail so that the user has it saved in case he wants to send manually later.

1247. By Andreas Moog

Save a temporary file in case sending fails

Revision history for this message
Stefano Rivera (stefanor) wrote :

* print -> Logger.normal, please
* spaces after commas, please

1248. By Andreas Moog

Use Logger.normal

1249. By Andreas Moog

Merge with trunk

Revision history for this message
Andreas Moog (ampelbein) wrote :

Ok, all done. Should work now.

Revision history for this message
Stefano Rivera (stefanor) wrote :

Traceback (most recent call last):
  File "./requestsync", line 348, in <module>
    main()
  File "./requestsync", line 344, in main
    mailserver_user, mailserver_pass)
  File "/home/stefanor/bzr/ubuntu-dev-tools/fix-850360/ubuntutools/requestsync/mail.py", line 166, in mail_bug
    f=open("/tmp/requestsync-" + srcpkg,"w")
TypeError: cannot concatenate 'str' and 'NoneType' objects

(Also, space after that comma, please :) )

Oh, and all 400-series errors are temporary, I suggest: 400 <= s.smtp_code < 500:

review: Needs Fixing
Revision history for this message
Andreas Moog (ampelbein) wrote :

I don't understand that traceback to be honest. Shouldn't srcpkg never be None? What command did you use to invoke requestsync? Or maybe i understand the error wrong.

Regarding the error codes, you are right, but 421 should be the only response that makes sense to retry at that point. It would perhaps make sense to implement another check after the s.sendmail() command to give a retry option in case of greylisting (reply code 450 in most cases).

Other temporary error aren't worthwhile to retry within a reasonable timeframe because they most often depend on admin interaction. (451/452).

1250. By Andreas Moog

Merge trunk

1251. By Andreas Moog

Space after comma

Revision history for this message
Stefano Rivera (stefanor) wrote :

srcpkg is None if it'll be a new package in Ubuntu.

1252. By Andreas Moog

Merge trunk

1253. By Andreas Moog

Use bugtitle as temporary filename

1254. By Andreas Moog

Also allow retry if recipient got rejected

1255. By Andreas Moog

Add a exception for disconnected server

1256. By Andreas Moog

Use regex to filter unwanted characters in filename

Revision history for this message
Andreas Moog (ampelbein) wrote :

Thank you Stefano for all your help and patience with me! Merge proposal updated!

Revision history for this message
Stefano Rivera (stefanor) wrote :

Made a few minor modifications, and merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-12-02 22:06:35 +0000
3+++ debian/changelog 2011-12-03 17:15:28 +0000
4@@ -27,6 +27,7 @@
5 * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884)
6 * grep-merges: We already require a UTF-8 enabled terminal, so encode
7 package and uploader name in UTF-8 (LP: #694388)
8+ * requestsync: Give user option to retry in case of temporary error (LP: #850360)
9
10 -- Andreas Moog <amoog@ubuntu.com> Wed, 30 Nov 2011 21:04:39 +0100
11
12
13=== modified file 'ubuntutools/requestsync/mail.py'
14--- ubuntutools/requestsync/mail.py 2011-11-13 20:50:34 +0000
15+++ ubuntutools/requestsync/mail.py 2011-12-03 17:15:28 +0000
16@@ -21,6 +21,7 @@
17 # of the GNU General Public License license.
18
19 import os
20+import re
21 import sys
22 import smtplib
23 import socket
24@@ -162,14 +163,30 @@
25 print 'The final report is:\n%s' % mail
26 confirmation_prompt()
27
28+ # save mail in temporary file
29+ f=open("/tmp/requestsync-" + re.sub("[^a-zA-Z0-9_\-]","",bugtitle.replace(" ","_")), "w")
30+ f.write(mail)
31+ f.close()
32+
33+ Logger.normal('The e-mail has been saved in %s and will be deleted '
34+ 'after succesful transmission', f.name)
35+
36 # connect to the server
37- try:
38- Logger.info('Connecting to %s:%s ...', mailserver_host, mailserver_port)
39- s = smtplib.SMTP(mailserver_host, mailserver_port)
40- except socket.error, s:
41- Logger.error('Could not connect to %s:%s: %s (%i)',
42- mailserver_host, mailserver_port, s[1], s[0])
43- return
44+ while True:
45+ try:
46+ Logger.info('Connecting to %s:%s ...', mailserver_host, mailserver_port)
47+ s = smtplib.SMTP(mailserver_host, mailserver_port)
48+ break
49+ except socket.error, s:
50+ Logger.error('Could not connect to %s:%s: %s (%i)',
51+ mailserver_host, mailserver_port, s[1], s[0])
52+ return
53+ except smtplib.SMTPConnectError, s:
54+ Logger.error('Could not connect to %s:%s: %s (%i)',
55+ mailserver_host, mailserver_port, s[1], s[0])
56+ if s.smtp_code == 421:
57+ confirmation_prompt(message='This is a temporary error, press '
58+ '[Enter] to retry. Press [Ctrl-C] to abort now.')
59
60 if mailserver_user and mailserver_pass:
61 try:
62@@ -184,6 +201,21 @@
63 s.quit()
64 return
65
66- s.sendmail(myemailaddr, to, mail.encode('utf-8'))
67- s.quit()
68- Logger.normal('Sync request mailed.')
69+ while True:
70+ try:
71+ s.sendmail(myemailaddr, to, mail.encode('utf-8'))
72+ s.quit()
73+ os.remove(f.name)
74+ Logger.normal('Sync request mailed.')
75+ break
76+ except smtplib.SMTPRecipientsRefused, smtperror:
77+ smtp_code, smtp_message = smtperror.recipients[to]
78+ Logger.error('Error while sending: %i, %s', smtp_code, smtp_message)
79+ if smtp_code == 450:
80+ confirmation_prompt(message='This is a temporary error, press '
81+ '[Enter] to retry. Press [Ctrl-C] to abort now.')
82+ else:
83+ return
84+ except smtplib.SMTPServerDisconnected:
85+ Logger.error('Server disconnected while sending the mail.')
86+ return

Subscribers

People subscribed via source and target branches

to status/vote changes: