[Python-checkins] r88937 - in tracker/instances/python-dev: detectors/rietveldreactor.py scripts/update_email.py

martin.v.loewis python-checkins at python.org
Mon Apr 9 09:08:43 CEST 2012


Author: martin.v.loewis
Date: Mon Apr  9 09:08:43 2012
New Revision: 88937

Log:
Move email updating to reactor.


Modified:
   tracker/instances/python-dev/detectors/rietveldreactor.py
   tracker/instances/python-dev/scripts/update_email.py

Modified: tracker/instances/python-dev/detectors/rietveldreactor.py
==============================================================================
--- tracker/instances/python-dev/detectors/rietveldreactor.py	(original)
+++ tracker/instances/python-dev/detectors/rietveldreactor.py	Mon Apr  9 09:08:43 2012
@@ -16,10 +16,30 @@
               (nodeid, username, email))
 
 def update_django_user(db, cl, nodeid, oldvalues):
+    user = nodeid
     if 'username' in oldvalues:
         newname = cl.get(nodeid, 'username')
         c = db.cursor
-        c.execute("update auth_user set username=%s where id=%s", (newname, nodeid))
+        c.execute("update auth_user set username=%s where id=%s", (newname, user))
+
+    if 'address' in oldvalues:
+        old = oldvalues['address'].decode('ascii')
+        new = cl.get(nodeid, 'address').decode('ascii')
+        c = db.cursor
+        c.execute('update auth_user set email=%s where id=%s', (new, user))
+        c.execute('update codereview_account set email=%s where id=%s', (new, user))
+        # find issues where user is on nosy
+        c.execute('select nodeid,cc from issue_nosy, codereview_issue '
+                  'where linkid=%s and nodeid=id', (user,))
+        for issue, cc in c.fetchall():
+            cc = cPickle.loads(base64.decodestring(cc))
+            try:
+                cc[cc.index(old)] = new
+            except ValueError:
+                cc.append(new)
+            cc = base64.encodestring(cPickle.dumps(cc))
+            c.execute('update codereview_issue set cc=%s where id=%s', (cc, user))
+        
 
 def update_issue_cc(db, cl, nodeid, oldvalues):
     if 'nosy' not in oldvalues:

Modified: tracker/instances/python-dev/scripts/update_email.py
==============================================================================
--- tracker/instances/python-dev/scripts/update_email.py	(original)
+++ tracker/instances/python-dev/scripts/update_email.py	Mon Apr  9 09:08:43 2012
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-# cron job to update rietveld tables when the email address changes
+# Update rietveld tables when the email address changes
 # this updates auth_user.email, codereview_account.email 
 # and codereview_issue.cc, based on the nosy list s
 # it does not update codereview_issue.reviewers, since it would be
@@ -7,6 +7,9 @@
 # is something that has to be filled out separately in Rietveld.
 # It also does not update codereview_message, since these have already
 # been sent with the email addresses recorded in the database.
+#
+# This script is now part of rietveldreactor
+
 import sys, os, base64, cPickle
 sys.path.insert(1,'/home/roundup/roundup/lib/python2.5/site-packages')
 import roundup.instance


More information about the Python-checkins mailing list