forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_email.py
executable file
·154 lines (133 loc) · 4.76 KB
/
generate_email.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python3
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
from typing import Any, Dict, List
from click.core import Context
try:
import jinja2
except ModuleNotFoundError:
exit("Jinja2 is a required dependency for this script")
try:
import click
except ModuleNotFoundError:
exit("Click is a required dependency for this script")
RECEIVER_EMAIL = "[email protected]"
PROJECT_NAME = "Superset"
PROJECT_MODULE = "superset"
PROJECT_DESCRIPTION = "Apache Superset is a modern, enterprise-ready business intelligence web application"
def string_comma_to_list(message: str) -> List[str]:
if not message:
return []
return [element.strip() for element in message.split(",")]
def render_template(template_file: str, **kwargs: Any) -> str:
"""
Simple render template based on named parameters
:param template_file: The template file location
:kwargs: Named parameters to use when rendering the template
:return: Rendered template
"""
template = jinja2.Template(open(template_file).read())
return template.render(kwargs)
class BaseParameters(object):
def __init__(
self,
version: str,
version_rc: str,
) -> None:
self.version = version
self.version_rc = version_rc
self.template_arguments: Dict[str, Any] = {}
def __repr__(self) -> str:
return f"Apache Credentials: {self.version}/{self.version_rc}"
@click.group()
@click.pass_context
@click.option("--version", envvar="SUPERSET_VERSION")
@click.option("--version_rc", envvar="SUPERSET_VERSION_RC")
def cli(
ctx: Context,
version: str,
version_rc: str,
) -> None:
"""Welcome to releasing send email CLI interface!"""
base_parameters = BaseParameters(version, version_rc)
base_parameters.template_arguments["receiver_email"] = RECEIVER_EMAIL
base_parameters.template_arguments["project_name"] = PROJECT_NAME
base_parameters.template_arguments["project_module"] = PROJECT_MODULE
base_parameters.template_arguments["project_description"] = PROJECT_DESCRIPTION
base_parameters.template_arguments["version"] = base_parameters.version
base_parameters.template_arguments["version_rc"] = base_parameters.version_rc
ctx.obj = base_parameters
@cli.command("vote_pmc")
@click.pass_obj
def vote_pmc(base_parameters: BaseParameters) -> None:
template_file = "email_templates/vote_pmc.j2"
message = render_template(template_file, **base_parameters.template_arguments)
print(message)
@cli.command("result_pmc")
@click.option(
"--vote_bindings",
default="",
type=str,
prompt="A List of people with +1 binding vote (ex: Max,Grace,Krist)",
)
@click.option(
"--vote_nonbindings",
default="",
type=str,
prompt="A List of people with +1 non binding vote (ex: Ville)",
)
@click.option(
"--vote_negatives",
default="",
type=str,
prompt="A List of people with -1 vote (ex: John)",
)
@click.option(
"--vote_thread",
default="",
type=str,
prompt="Permalink to the vote thread "
"(see https://lists.apache.org/[email protected])",
)
@click.pass_obj
def result_pmc(
base_parameters: BaseParameters,
vote_bindings: str,
vote_nonbindings: str,
vote_negatives: str,
vote_thread: str,
) -> None:
template_file = "email_templates/result_pmc.j2"
base_parameters.template_arguments["vote_bindings"] = string_comma_to_list(
vote_bindings
)
base_parameters.template_arguments["vote_nonbindings"] = string_comma_to_list(
vote_nonbindings
)
base_parameters.template_arguments["vote_negatives"] = string_comma_to_list(
vote_negatives
)
base_parameters.template_arguments["vote_thread"] = vote_thread
message = render_template(template_file, **base_parameters.template_arguments)
print(message)
@cli.command("announce")
@click.pass_obj
def announce(base_parameters: BaseParameters) -> None:
template_file = "email_templates/announce.j2"
message = render_template(template_file, **base_parameters.template_arguments)
print(message)
cli()