forked from PythonClassmates/pythonclassmates.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
131 lines (100 loc) · 3.15 KB
/
tasks.py
File metadata and controls
131 lines (100 loc) · 3.15 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- coding: utf-8 -*-
import os
import shutil
import sys
from pathlib import Path
from invoke import task
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
CONFIG = {}
CONFIG['basedir'] = Path('.')
CONFIG['inputdir'] = CONFIG['basedir'] / 'content'
CONFIG['outputdir'] = CONFIG['basedir'] / 'output'
CONFIG['conffile'] = CONFIG['basedir'] / 'pelicanconf.py'
CONFIG['publishconf'] = CONFIG['basedir'] / 'publishconf.py'
CONFIG['opts'] = '--fatal=warnings'
CONFIG['port'] = 8000
@task
def clean(c):
"""Remove generated files"""
if CONFIG['outputdir'].is_dir():
shutil.rmtree(CONFIG['outputdir'])
CONFIG['outputdir'].mkdir(parents=True, exist_ok=True)
@task
def build(c):
"""Builds the local Pelican blog"""
c.run('echo "Building your Pelican website"')
c.run('pelican {inputdir} -o {outputdir} -s {conffile} {opts}'
.format(**CONFIG)
)
@task
def html(c):
"""Builds the local Pelican blog"""
build(c)
@task
def rebuild(c):
"""Builds with the delete switch"""
c.run('echo "Re-building your Pelican website"')
c.run('pelican -d -s {conffile} {opts}'.format(**CONFIG))
@task
def publish(c):
"""Builds the Pelican blog with deployment settings"""
c.run('echo "Publishing your Pelican website"')
c.run('pelican {inputdir} -o {outputdir} -s {publishconf} {opts}'
.format(**CONFIG)
)
@task
def autoreload(c):
"""Starts the autoreload server to help during writing of blog articles"""
c.run('echo "Running autoreload server. Press CTRL+C to stop"')
c.run('pelican -r {inputdir} -o {outputdir} -s {conffile} {opts}'
.format(**CONFIG)
)
@task
def regenerate(c):
"""Starts the autoreload server to help during writing of blog articles"""
autoreload(c)
@task
def serve(c):
"""Serve site at http://localhost:8000/"""
class AddressReuseTCPServer(RootedHTTPServer):
allow_reuse_address = True
server = AddressReuseTCPServer(
CONFIG['outputdir'],
('', CONFIG['port']),
ComplexHTTPRequestHandler
)
sys.stderr.write('Serving on port {port} ...\n'.format(**CONFIG))
server.serve_forever()
@task
def runserver(c):
"""Serve site at http://localhost:8000/"""
serve(c)
@task
def reserve(c):
"""Builds, then serves"""
build(c)
serve(c)
@task
def preview(c):
"""Builds the production version of site"""
c.run('pelican -s publishconf.py')
@task
def revert(c):
"""Reverts the repository to the previous commit if not on a Pull Request
on Travis.
"""
if not os.getenv('TRAVIS_PULL_REQUEST'):
c.run('echo "Build errors were encountered. Reverting last commit..."')
c.run('git revert HEAD -n')
c.run(
'git commit -m "Revert to last commit because errors were found."'
)
c.run('git checkout -b errors')
c.run(
'git push -f https://{GITHUB_TOKEN}@github.com/'
'PythonClassmates/PythonClassmates.org.git errors:master'
.format(**os.environ)
)
c.run('echo "Last commit reverted"')
else:
c.run('echo "In a pull request. Nothing to revert."')