-
Notifications
You must be signed in to change notification settings - Fork 12
/
tasks.py
85 lines (68 loc) · 1.97 KB
/
tasks.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
from invoke import task, run
import os
import shutil
import sys
import socketserver
from pelican.server import ComplexHTTPRequestHandler
# Local path configuration (can be absolute or relative to fabfile)
DEPLOY_PATH = 'output'
# Remote server configuration
production = 'root@localhost:22'
aest_path = '/var/www'
# Github Pages configuration
github_pages_branch = "gh-pages"
# Port for `serve`
PORT = 8001
@task
def clean(context):
"""Remove generated files"""
if os.path.isdir(DEPLOY_PATH):
shutil.rmtree(DEPLOY_PATH)
os.makedirs(DEPLOY_PATH)
@task
def build(context):
"""Build local version of site"""
run('pelican -s pelicanconf.py')
@task
def buildglpages(context):
"""Build Gitlab pages version of site"""
run('pelican -s gitlabpagesconf.py')
@task
def rebuild(context):
"""`clean` then `build`"""
clean()
build()
@task
def regenerate(context):
"""Automatically regenerate site upon file modification"""
run('pelican -r -s pelicanconf.py')
@task
def serve(context):
"""Serve site at http://localhost:8000/"""
os.chdir(DEPLOY_PATH)
class AddressReuseTCPServer(socketserver.TCPServer):
allow_reuse_address = True
# Pelican assumes that the request handler has a 'base_path' set.
# Since this assumption does not hold true anymore, we set this
# attribute here manually
request_handler = ComplexHTTPRequestHandler
request_handler.base_path = "."
server = AddressReuseTCPServer(('', PORT), request_handler)
sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
server.serve_forever()
@task
def reserve(context):
"""`build`, then `serve`"""
build()
serve()
@task
def preview(context):
"""Build production version of site"""
run('pelican -s publishconf.py')
@task
def gh_pages(context):
"""Publish to GitHub Pages"""
clean(context)
preview(context)
run("ghp-import -b gh-pages output")
#run("git push origin {github_pages_branch}".format(**env))