-
Notifications
You must be signed in to change notification settings - Fork 14
/
configure_celery.py
45 lines (34 loc) · 1.1 KB
/
configure_celery.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
import os
import sys
from jinja2 import Environment, FileSystemLoader
def usage(argv):
cmd = os.path.basename(argv[0])
print(
"usage: %s <path_to_ini_file> \n"
"(example: %s ./development.ini )" % (cmd, cmd)
)
sys.exit(1)
def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
formshare_path = "."
formshare_ini_file = os.path.abspath(argv[1])
if not os.path.exists(formshare_ini_file):
print("Ini file {} does not exists".format(formshare_ini_file))
sys.exit(1)
formshare_celery_app = os.path.join(
formshare_path, *["formshare", "config", "celery_app.py"]
)
template_environment = Environment(
autoescape=False,
loader=FileSystemLoader(os.path.join(formshare_path, "templates")),
trim_blocks=False,
)
context = {"FORMSHARE_INI_FILE": formshare_ini_file}
rendered_template = template_environment.get_template(
"celery_app_template.jinja2"
).render(context)
with open(formshare_celery_app, "w") as f:
f.write(rendered_template)
if __name__ == "__main__":
main()