-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
125 lines (95 loc) · 2.89 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
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
import time
from pathlib import Path
from invoke import run, task
# from fabric.api import *
# import fabric.contrib.project as project
# import os
# Local path configuration (can be absolute or relative to fabfile)
# env.deploy_path = '../minchinweb.github.io-master'
# DEPLOY_PATH = env.deploy_path
# Remote server configuration
# production = 'root@localhost:22'
# dest_path = '/var/www'
# Rackspace Cloud Files configuration settings
# env.cloudfiles_username = 'my_rackspace_username'
# env.cloudfiles_api_key = 'my_rackspace_api_key'
# env.cloudfiles_container = 'my_cloudfiles_container'
p = Path.cwd()
# deploy_path = p.parents[0] / 'blog.minchin.ca-temp' # used for local testing
deploy_path = p / "output"
# used for the version to be put on the wider internet
# publish_path = p.parents[0] / 'blog.minchin.ca-master'
publish_path = p / "output"
def clean(ctx):
print("You'll have to manually delete the output folder")
# if os.path.isdir(DEPLOY_PATH):
# local('rm -rf {deploy_path}'.format(**env))
# local('mkdir {deploy_path}'.format(**env))
@task
def build(
ctx, publish=False, carefully=False, travis=False, verbose=False, debug=False
):
"""Build the blog."""
config = "pelicanconf.py"
if publish:
config = "publishconf.py"
if travis:
config = "travisconf.py"
cli_args = ""
if carefully:
cli_args += " --fatal=warnings"
if debug:
cli_args += " --debug"
elif verbose:
cli_args += " --verbose"
ctx.run("pelican -s {}{}".format(config, cli_args))
@task
def build_debug(ctx):
"""Use debug output to build a local version of the blog."""
ctx.run("pelican -s pelicanconf.py --debug")
@task
def rebuild(ctx):
"""clean and build."""
clean(ctx)
build(ctx)
@task
def regenerate(ctx):
"""Rebuild a local version of the blog if files change."""
ctx.run("start pelican -r -s pelicanconf.py")
@task
def serve(ctx):
"""Serve the local blog output on port 8000."""
ctx.run("cd {} && start python -m http.server".format(deploy_path))
@task
def serve_on(ctx, port):
"""Serve the local blog output on a port of your choosing."""
ctx.run("cd {} && start python -m http.server {}".format(deploy_path, port))
@task
def reserve(ctx):
"""Build and serve."""
build(ctx)
serve(ctx)
# @task
# def upload(ctx):
# """Publish and then push the result to GitHub."""
# publish(ctx)
# ctx.run(
# 'cd {} && git add -A && git commit -m "[Generated] {}" && git push'.format(
# publish_path, time.strftime("%Y-%m-%d")
# )
# )
# Add devsever
# only works on Windows
# need to kill the second window manually
@task
def devserver(ctx):
"""Regeneration and serve."""
regenerate(ctx)
serve(ctx)
@task
def test(ctx):
"""Test invoke is working."""
# print(ctx)
print(run)
ctx.run("dir")
# run('dir', shell=INVOKE_SHELL)