forked from karrot-dev/karrot-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.py
executable file
·57 lines (36 loc) · 1.34 KB
/
sync.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
#!/usr/bin/env python
import subprocess
import os
import glob
import sys
from os.path import dirname, realpath, join
import pkgutil
process_mjml = '--no-mjml' not in sys.argv[1:]
def color(num):
def format(val):
return '\033[' + str(num) + 'm' + val + '\033[0m'
return format
green = color(92)
yellow = color(93)
def header(val):
print('\n', yellow('★'), green(val), '\n')
environ = os.environ.copy()
# do not prompt if dependency source already exists, just wipe and get the required version
environ['PIP_EXISTS_ACTION'] = 'w'
base = dirname(realpath(__file__))
if 'piptools' not in [m.name for m in pkgutil.iter_modules()]:
header("Installing pip-tools")
subprocess.run(['pip', 'install', 'pip-tools'], env=environ, check=True)
header("Installing python dependencies")
subprocess.run(['pip-sync', 'requirements.txt'], env=environ, check=True)
if process_mjml:
header("Installing node js dependencies")
subprocess.run(['yarn'], env=environ, cwd=join(base, 'mjml'), check=True)
header("Removing old templates")
entries = glob.glob(join(base, 'karrot/*/templates/*.html.jinja2'))
for entry in entries:
os.remove(entry)
print('Removed {} entries'.format(len(entries)))
header("Generating new templates")
subprocess.run(['./mjml/convert'], env=environ, check=True)
header('All done ☺')