From 69e247d873d514fc08e143b64fa651c3b0b6c96d Mon Sep 17 00:00:00 2001
From: Jeremy Stanley <fungi@yuggoth.org>
Date: Tue, 24 Jun 2014 20:37:40 +0000
Subject: [PATCH] Make ATC lists sort E-mails with preferred first

* tools/atc/email-stats.py: Adjust the order in which Gerrit E-mail
addresses are returned so that the one listed as the preferred
address is sorted to the beginning of the set.

Change-Id: I95b5817ada58f4059df4f5c0b406183f1c1e5b74
---
 tools/atc/email_stats.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/atc/email_stats.py b/tools/atc/email_stats.py
index 1f863c638c..c2ecd3aa2c 100644
--- a/tools/atc/email_stats.py
+++ b/tools/atc/email_stats.py
@@ -49,6 +49,15 @@ def get_account(accounts, num):
 def main():
     accounts = {}
 
+    for row in csv.reader(open('accounts.csv')):
+        num = int(row[-1])
+        name = row[1]
+        email = row[2]
+        a = get_account(accounts, num)
+        a.full_name = name
+        if email and email != '\\N':
+            a.emails.append(email)
+
     for row in csv.reader(open('emails.csv')):
         num, email, pw, external = row
         num = int(num)
@@ -67,12 +76,6 @@ def main():
                 raise Exception("Already a username")
             a.username = m.group(1)
 
-    for row in csv.reader(open('accounts.csv')):
-        num = int(row[-1])
-        name = row[1]
-        a = get_account(accounts, num)
-        a.full_name = name
-
     username_accounts = {}
     for a in accounts.values():
         username_accounts[a.username] = a