|
1
|
|
|
from SCons.Script import * |
|
2
|
|
|
|
|
3
|
|
|
from subprocess import Popen |
|
4
|
|
|
import sys |
|
5
|
|
|
import os |
|
6
|
|
|
import subprocess |
|
7
|
|
|
import json |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
def run_backend(target, source, env): |
|
11
|
|
|
'''Runs the backend connector daemon, who serves all configured backends.''' |
|
12
|
|
|
os.chdir('backends') |
|
13
|
|
|
backend = Popen(["python", "daemon.py", "daemon.ini"]) |
|
14
|
|
|
os.chdir('..') |
|
15
|
|
|
if backend.returncode is not None: |
|
16
|
|
|
print "Error %u while starting backend daemon" % backend.returncode |
|
17
|
|
|
exit(-1) |
|
18
|
|
|
print "Enter 'q' for quitting ..." |
|
19
|
|
|
while 1: |
|
20
|
|
|
line = sys.stdin.readline() |
|
21
|
|
|
if line.startswith('q'): |
|
22
|
|
|
backend.terminate() |
|
23
|
|
|
exit(0) |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def run_frontend(target, source, env): |
|
27
|
|
|
'''Runs the server.''' |
|
28
|
|
|
os.system('./manage.py runserver') |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def run_all(target, source, env): |
|
32
|
|
|
'''Runs the frontend and the backend.''' |
|
33
|
|
|
os.chdir('backends') |
|
34
|
|
|
backend = Popen(["python", "daemon.py", "daemon.ini"]) |
|
35
|
|
|
os.chdir('..') |
|
36
|
|
|
os.system('./manage.py runserver') |
|
37
|
|
|
backend.terminate() |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
def fixture_save(target, source, env): |
|
41
|
|
|
'''Creates a test fixture from the current database.''' |
|
42
|
|
|
testaccount = {"model": "auth.user", "pk": 2, |
|
43
|
|
|
"fields": { |
|
44
|
|
|
"username": "testadmin", |
|
45
|
|
|
"password": "pbkdf2_sha256$10000$JNt1EZn2g72p$vX3UFh7g4mPa313pWW4lf4YxkUhL534V8/kxFaQ1XvM=" |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
jsontext = subprocess.check_output(['./manage.py', 'dumpdata', |
|
49
|
|
|
'FuzzEd.project', |
|
50
|
|
|
'FuzzEd.graph', |
|
51
|
|
|
'FuzzEd.node', |
|
52
|
|
|
'FuzzEd.nodegroup', |
|
53
|
|
|
'FuzzEd.edge', |
|
54
|
|
|
'FuzzEd.property']) |
|
55
|
|
|
data = json.loads(jsontext) |
|
56
|
|
|
# Remove existing user account data, replace with test suite user |
|
57
|
|
|
for entry in data: |
|
58
|
|
|
if entry['model'] == 'auth.user': |
|
59
|
|
|
print "Replacing database user with test suite user" |
|
60
|
|
|
del entry |
|
61
|
|
|
if 'owner' in entry['fields']: |
|
62
|
|
|
entry['fields']['owner'] = 2 # see above |
|
63
|
|
|
print "Replacing database user reference for " + entry["model"] |
|
64
|
|
|
data.append(testaccount) |
|
65
|
|
|
output = open("FuzzEd/fixtures/new.json", "w") |
|
66
|
|
|
output.write(json.dumps(data, indent=4)) |
|
67
|
|
|
print "New fixture file is now available at fixtures/new.json" |
|
68
|
|
|
output.close() |
|
69
|
|
|
|
|
70
|
|
|
# def fixture_load(fname=None): |
|
71
|
|
|
# '''Loads the database with a test fixture from ./FuzzEd/fixtures/''' |
|
72
|
|
|
# if fname==None: |
|
73
|
|
|
# print "Usage: fab fixture_load:<filename>" |
|
74
|
|
|
# return |
|
75
|
|
|
# os.system('./manage.py loaddata ./FuzzEd/fixtures/'+fname) |
|
76
|
|
|
|