summaryrefslogtreecommitdiff
path: root/tools/new_core.py
blob: 1d19968ba0a7529f427da101e80ff5fd7f701112 (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
#!/usr/bin/env python
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
New core email content generator.
"""

import argparse

import jinja2
import parawrap


CORE_TPL = """
Greetings all stackers,

I propose that we add {{FULL_NAME}}[1] to the {{TEAM_CORE}}[2] team.

{{FIRST_NAME}} has been actively contributing to {{TEAM}} for a while now, both
in helping make {{TEAM}} better via code contribution(s) and by helping with
the review load when {{HE_SHE_LOWER}} can. {{HE_SHE}} has provided quality
reviews and is doing an awesome job with the various {{TEAM}} concepts and
helping make {{TEAM}} the best it can be!

Overall I think {{HE_SHE_LOWER}} would make a great addition to the core
review team.

Please respond with +1/-1.

Thanks much!

- {{ME}}
"""
CORE_TPL = CORE_TPL.strip()


def expand_template(contents, params):
    if not params:
        params = {}
    tpl = jinja2.Template(source=contents, undefined=jinja2.StrictUndefined)
    return tpl.render(**params)


def generate_email(args):
    params = {
        'FULL_NAME': args.who,
        'HE_SHE': args.gender.title(),
        'TEAM_CORE': '%s-core' % args.team,
        'ME': args.sender,
    }
    params['TEAM'] = args.team.strip().lower()
    params['HE_SHE_LOWER'] = params['HE_SHE'].lower()
    params['FIRST_NAME'] = params['FULL_NAME'].split()[0]
    contents = expand_template(CORE_TPL, params)
    contents = parawrap.fill(contents.strip(), width=75)
    # Put the links on after so they are not affected by the wrapping...
    links = [
        'https://launchpad.net/~%s' % args.who_launchpad_id,
        'https://launchpad.net/%s' % params['TEAM'],
    ]
    contents += "\n\n"
    for i, link in enumerate(links, 1):
        contents += "[%s] %s\n" % (i, link)
    return contents.rstrip()


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--adding-who', action="store", dest="who",
                        required=True, metavar="<full-name>")
    parser.add_argument('--adding-who-launchpad-id', action="store",
                        dest="who_launchpad_id",
                        required=True, metavar="<launchpad-id>")
    parser.add_argument('--from-who', action="store", dest="sender",
                        metavar="<full-name>", required=True)
    parser.add_argument('--team', action="store", dest="team",
                        metavar="<team>", required=True)
    parser.add_argument('--gender', action="store", dest="gender",
                        metavar="<he/she>", required=True)
    args = parser.parse_args()
    print(generate_email(args))


if __name__ == '__main__':
    main()