-
Notifications
You must be signed in to change notification settings - Fork 2
/
make
executable file
·90 lines (75 loc) · 2.16 KB
/
make
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
#!/usr/bin/env python
import sys
import os
import argparse
import shlex
import shutil
import subprocess
import http.server
import socketserver
BASEURL = 'ipython-books.github.io'
def call(cmd, wait=True):
cmd_list = shlex.split(cmd)
p = subprocess.Popen(cmd_list)
if wait:
p.wait()
def conf():
"Generate the derivate conf files."
with open('pelicanconf.py', 'r') as f:
contents = f.read()
loc = "SITEURL = '/'\n" + contents
pub = ("SITEURL = 'http://%s'\n" % BASEURL) + contents
with open('pelicanconf_loc.py', 'w') as f:
f.write(loc)
with open('pelicanconf_pub.py', 'w') as f:
f.write(pub)
def build(local=True, monitor=True):
"Build the local HTML site in output."
monitor = monitor & local
conf()
which = 'loc' if local else 'pub'
call("pelican -s=pelicanconf_%s.py %s" % (which, '-r' if monitor else ''),
wait=not(monitor))
def serve():
"Launch a local HTTP server."
build()
os.chdir('output')
# subprocess.Popen(["python", "-m", "http.server"])
call("python -m http.server", wait=False)
os.chdir('..')
def clean():
"Clean all output and cache."
shutil.rmtree('output')
shutil.rmtree('cache')
shutil.rmtree('__pycache__')
def upload(msg):
"""Build and push all changes online."""
build(local=False)
call("git add content/*.md")
call("git add content/*.ipynb")
call('git commit -am "%s"' % msg)
call("git push")
call("cp -ar output/. ../%s" % BASEURL)
os.chdir("../%s" % BASEURL)
call("git add --ignore-removal *")
call('git commit -am "%s"' % msg)
call('git push')
def kill():
"Kill the running processes."
call("killall python pelican")
commands = {
# None: lambda: print("Please provide a command."),
None: serve,
'build': build,
'build_once': lambda: build(monitor=False),
'serve': serve,
'conf': conf,
'clean': clean,
'upload': upload,
'kill': kill,
}
parser = argparse.ArgumentParser()
parser.add_argument('command', type=str, nargs='?')
parser.add_argument('args', type=str, nargs='*')
args = parser.parse_args()
commands[args.command](*args.args)