run_commands.fixture_save()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 29
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

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