forked from PowerDNS/pdnscontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.task
executable file
·65 lines (55 loc) · 1.87 KB
/
.travis.task
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
#!/usr/bin/env python
import os
import shutil
import sys
import time
from subprocess import check_call, Popen
def create_instance_conf():
shutil.copyfile("instance/pdnscontrol.conf.example", "instance/pdnscontrol.conf")
with open("instance/pdnscontrol.conf", "a") as f:
db = 'sqlite:////' + os.getcwd() + '/instance/test.db'
tpl = """
DATABASE_URI = '{db}'
SECRET_KEY = 'test-key-do-not-use'
SECURITY_PASSWORD_SALT = 'test-salt-do-not-use'
"""
f.write(tpl.format(db=db))
def npm(args):
args = ['npm'] + args
print "Running %s ..." % (' '.join(args))
check_call(args, cwd='pdnscontrol', close_fds=True)
def before_script():
create_instance_conf()
npm(['install'])
npm(['run', 'update-webdriver'])
Popen(['Xvfb', os.environ.get('DISPLAY')], close_fds=True)
time.sleep(2) # give server time to start
check_call(['./install.py'], close_fds=True)
def run_with_server():
args = sys.argv[3:]
if len(args) == 0:
raise RuntimeError('No command passed to run with server')
print "Running \"%s\" with pdnscontrol debug server..." % (' '.join(args))
server_proc = Popen(['python', '-c', 'import pdnscontrol; pdnscontrol.app.run(use_reloader=False)'], close_fds=True)
time.sleep(2) # wait for server to start
proc = None
try:
proc = Popen(args, close_fds=True, cwd='pdnscontrol')
proc.communicate()
rc = proc.wait()
proc = None
finally:
print "Killing pdnscontrol debug server..."
server_proc.kill()
server_proc.wait()
if proc:
proc.terminate()
sys.exit(rc)
if len(sys.argv) < 2:
raise RuntimeError('Syntax: ./.travis.task COMMAND [-- command]')
elif sys.argv[1] == 'before_script':
before_script()
elif sys.argv[1] == 'run_with_server':
run_with_server()
else:
raise RuntimeError('Unknown COMMAND passed')