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
=== modified file 'debian/changelog'
--- debian/changelog 2011-12-02 22:06:35 +0000
+++ debian/changelog 2011-12-03 17:15:28 +0000
@@ -27,6 +27,7 @@
27 * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884)27 * sponsor-patch: Check permission to unsubscribe sponsors-team (LP: #896884)
28 * grep-merges: We already require a UTF-8 enabled terminal, so encode 28 * grep-merges: We already require a UTF-8 enabled terminal, so encode
29 package and uploader name in UTF-8 (LP: #694388)29 package and uploader name in UTF-8 (LP: #694388)
30 * requestsync: Give user option to retry in case of temporary error (LP: #850360)
3031
31 -- Andreas Moog <amoog@ubuntu.com> Wed, 30 Nov 2011 21:04:39 +010032 -- Andreas Moog <amoog@ubuntu.com> Wed, 30 Nov 2011 21:04:39 +0100
3233
3334
=== modified file 'ubuntutools/requestsync/mail.py'
--- ubuntutools/requestsync/mail.py 2011-11-13 20:50:34 +0000
+++ ubuntutools/requestsync/mail.py 2011-12-03 17:15:28 +0000
@@ -21,6 +21,7 @@
21# of the GNU General Public License license.21# of the GNU General Public License license.
2222
23import os23import os
24import re
24import sys25import sys
25import smtplib26import smtplib
26import socket27import socket
@@ -162,14 +163,30 @@
162 print 'The final report is:\n%s' % mail163 print 'The final report is:\n%s' % mail
163 confirmation_prompt()164 confirmation_prompt()
164165
166 # save mail in temporary file
167 f=open("/tmp/requestsync-" + re.sub("[^a-zA-Z0-9_\-]","",bugtitle.replace(" ","_")), "w")
168 f.write(mail)
169 f.close()
170
171 Logger.normal('The e-mail has been saved in %s and will be deleted '
172 'after succesful transmission', f.name)
173
165 # connect to the server174 # connect to the server
166 try:175 while True:
167 Logger.info('Connecting to %s:%s ...', mailserver_host, mailserver_port)176 try:
168 s = smtplib.SMTP(mailserver_host, mailserver_port)177 Logger.info('Connecting to %s:%s ...', mailserver_host, mailserver_port)
169 except socket.error, s:178 s = smtplib.SMTP(mailserver_host, mailserver_port)
170 Logger.error('Could not connect to %s:%s: %s (%i)',179 break
171 mailserver_host, mailserver_port, s[1], s[0])180 except socket.error, s:
172 return181 Logger.error('Could not connect to %s:%s: %s (%i)',
182 mailserver_host, mailserver_port, s[1], s[0])
183 return
184 except smtplib.SMTPConnectError, s:
185 Logger.error('Could not connect to %s:%s: %s (%i)',
186 mailserver_host, mailserver_port, s[1], s[0])
187 if s.smtp_code == 421:
188 confirmation_prompt(message='This is a temporary error, press '
189 '[Enter] to retry. Press [Ctrl-C] to abort now.')
173190
174 if mailserver_user and mailserver_pass:191 if mailserver_user and mailserver_pass:
175 try:192 try:
@@ -184,6 +201,21 @@
184 s.quit()201 s.quit()
185 return202 return
186203
187 s.sendmail(myemailaddr, to, mail.encode('utf-8'))204 while True:
188 s.quit()205 try:
189 Logger.normal('Sync request mailed.')206 s.sendmail(myemailaddr, to, mail.encode('utf-8'))
207 s.quit()
208 os.remove(f.name)
209 Logger.normal('Sync request mailed.')
210 break
211 except smtplib.SMTPRecipientsRefused, smtperror:
212 smtp_code, smtp_message = smtperror.recipients[to]
213 Logger.error('Error while sending: %i, %s', smtp_code, smtp_message)
214 if smtp_code == 450:
215 confirmation_prompt(message='This is a temporary error, press '
216 '[Enter] to retry. Press [Ctrl-C] to abort now.')
217 else:
218 return
219 except smtplib.SMTPServerDisconnected:
220 Logger.error('Server disconnected while sending the mail.')
221 return

Subscribers

People subscribed via source and target branches

to status/vote changes: