-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate
executable file
·75 lines (62 loc) · 2.24 KB
/
generate
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
#!/usr/bin/python3
import glob
import subprocess
import os.path
import shutil
import errno
# Can upload with rsync -a -v _site/ <dest>/
# Could extend this with using a cache of sha256 output files
# to see if we should regenerate or not,
# but just cleaning _site/ is easier before build
# and using raco to update during development.
def main():
dirname = os.path.dirname(__file__)
output_dir = os.path.join(dirname, "_site/")
print("Generating site to", output_dir)
# First make sure we've generated all files.
for f in glob.glob('*.pm'):
output = os.path.splitext(f)[0]
if os.path.isfile(output):
print("Skip", f)
continue
subprocess.call(["raco", "pollen", "render", f])
# sassc sass/main.scss --style compressed > css/main.css
with open('css/main.css', 'w') as main:
print("Generating css/main.css")
subprocess.call(["sassc", "sass/main.scss", "--style", "compressed"],
stdout=main)
# Clean destination directory.
if not os.path.exists(output_dir):
print("Creating", output_dir)
os.makedirs(output_dir)
else:
print("Cleaning", output_dir)
for root, dirs, files in os.walk(output_dir):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d))
# Then copy all relevant files.
for match in ["*.html", "*.xml", "css/", "files/",
"images/", "fonts/", "favicon*"]:
for src in glob.glob(match):
dst = os.path.join(output_dir, src)
src = os.path.join(dirname, src)
copy(src, dst)
# Need to remove files generated from .p extensions.
# Easier to just do it after than change capture above.
for pfile in glob.glob("*.p"):
actual = os.path.join(output_dir, os.path.splitext(pfile)[0])
if os.path.isfile(actual):
os.unlink(actual)
print("Done")
# Copying in python seems... Difficult.
def copy(src, dst):
try:
shutil.copytree(src, dst)
except OSError as exc: # python >2.5
if exc.errno == errno.ENOTDIR:
shutil.copy(src, dst)
else: raise
if __name__ == '__main__':
main()