summaryrefslogtreecommitdiff
path: root/tools/email_renamed_users.py
blob: f82a28ba30a077fbd47e0f0091dde9fd5d372cbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import smtplib
import pickle
import sys
import os

from email.mime.text import MIMEText

# Workaround current bug in docutils:
# http://permalink.gmane.org/gmane.text.docutils.devel/6324
import docutils.utils

root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path = [root] + sys.path

import config
import store

config = config.Config("config.ini")
store = store.Store(config)

EMAIL_PLURAL = """
Hello there!

PyPI has begun to enforce restrictions on what a valid Python package name
contains.

These rules are:

* Must contain ONLY ASCII letters, digits, underscores, hyphens, and periods
* Must begin and end with an ASCII letter or digit

You are listed as an owner or maintainer on %(old)s.

Due to the new rules these packages will be renamed to %(new)s.

These new names represent what someone using pip or easy_install would already
have had to use in order to install your packages.

I am sorry for any inconvenience this may have caused you.
"""


EMAIL_SINGLE = """
Hello there!

PyPI has begun to enforce restrictions on what a valid Python package name
contains.

These rules are:

* Must contain ONLY ASCII letters, digits, underscores, hyphens, and periods
* Must begin and end with an ASCII letter or digit

You are listed as an owner or maintainer on "%(old)s".

Due to the new rules this package will be renamed to "%(new)s".

This new name represents what someone using pip or easy_install would
already have had to use in order to install your package.

I am sorry for any inconvenience this may have caused you.
"""

with open("renamed.pkl") as pkl:
    renamed = pickle.load(pkl)


# Build up a list of all users to email
users = {}
for old, new in renamed:
    for role in store.get_package_roles(new):
        user_packages = users.setdefault(role["user_name"], [])
        user_packages.append((old, new))

sent = []

# Email each user
server = smtplib.SMTP(config.mailhost)
for username, packages in users.iteritems():
    packages = sorted(set(packages))

    user = store.get_user(username)

    if not user["email"]:
        continue

    if len(packages) > 1:
        msg = MIMEText(EMAIL_PLURAL % {
                        "old": ", ".join(['"%s"' % x[0] for x in packages]),
                        "new": ", ".join(['"%s"' % x[1] for x in packages]),
                    })
    elif packages:
        msg = MIMEText(EMAIL_SINGLE % {
                                "old": packages[0][0],
                                "new": packages[0][1],
                            })

    msg["Subject"] = "Important notice about your PyPI packages"
    msg["From"] = "donald@python.org"
    msg["To"] = user["email"]

    server.sendmail("donald@python.org", [user["email"]], msg.as_string())
    sent.append(("donald@python.org", [user["email"]], msg.as_string()))
server.quit()

with open("sent.pkl", "w") as pkl:
    pickle.dump(sent, pkl)