~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.4 by Karl Fogel
Add the copyright header block to more files; tweak format in a few files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5543.7.4 by Tim Penhey
All done.
6
# Disable pylint complaining about relative import of _pythonpath
7
# pylint: disable-msg=W0403
5543.7.3 by Tim Penhey
New revisions now check to see if we know the author.
8
9
"""Try to link RevionAuthors to Launchpad Person entries.
10
11
Iterate through the RevisionAuthors and extract their email address.
12
Then use that email address to link to a Person.
13
"""
14
15
import _pythonpath
16
17
import email.Utils
18
import sys
19
20
from canonical.launchpad.scripts import execute_zcml_for_scripts
21
from canonical.lp import initZopeless
22
23
from canonical.launchpad.database.revision import RevisionAuthor
24
25
def main(argv):
26
    execute_zcml_for_scripts()
27
    ztm = initZopeless()
28
    try:
5543.7.4 by Tim Penhey
All done.
29
        total = RevisionAuthor.select().count()
30
        for number, author in enumerate(RevisionAuthor.select()):
5543.7.3 by Tim Penhey
New revisions now check to see if we know the author.
31
            if author.email is None:
32
                email_address = email.Utils.parseaddr(author.name)[1]
33
                # If there is no @, then it isn't a real email address.
34
                if '@' in email_address:
35
                    author.email = email_address
36
                    if author.linkToLaunchpadPerson():
5743.2.4 by Tim Penhey
Page tests now pass.
37
                        print "%s linked to %s" % (
38
                            author.name.encode('ascii', 'replace'),
39
                            author.person.name)
5543.7.3 by Tim Penhey
New revisions now check to see if we know the author.
40
        ztm.commit()
41
    finally:
42
        ztm.abort()
43
44
45
if __name__ == '__main__':
46
    main(sys.argv)