This repository was archived by the owner on Nov 25, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtasks.py
46 lines (39 loc) · 1.4 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
import os
import signal
from invoke import run, task, Collection
@task
def start_slides(ctx):
if not os.path.exists("twistd.pid"):
ctx.run("twistd web --port tcp:5000 --path docs")
@task
def stop_slides(ctx):
if os.path.exists("twistd.pid"):
pid = int(open("twistd.pid").read().strip())
os.kill(pid, signal.SIGTERM)
RUNNERS = {
# example: (WSGI app, additional environ)
'ex1-1': ('it_works.demo_app', {}),
'ex2-2': ('simple_wsgi_app.application', {}),
'ex3-1': ('simple_http_objects.application', {}),
'ex3-2': ('bizkit.application', {'BIZKIT_APP': 'hello_bizkit:hello'}),
'ex4-1': ('bizkit.application', {'BIZKIT_APP': 'hello_goodbye'}),
'ex5-1': ('bizkit.application', {'BIZKIT_APP': 'hello_goodbye_templates'}),
'ex6-1': ('bizkit.application', {'BIZKIT_APP': 'greeting_persist'}),
}
@task(name="run")
def run_example(ctx, ex):
if not ex.startswith('ex'):
ex = 'ex' + ex
if ex not in RUNNERS:
print(f"No such example: {ex}")
return
os.chdir(ex)
wsgi_app, env = RUNNERS[ex]
env['PYTHONPATH'] = '.'
ctx.run(f'twist --log-format text web --wsgi {wsgi_app} --port tcp:8080', env=env, echo=True)
slides = Collection("slides")
slides.add_task(start_slides, "start")
slides.add_task(stop_slides, "stop")
ns = Collection()
ns.add_collection(slides)
ns.add_task(run_example)