-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrunme
executable file
·126 lines (99 loc) · 2.89 KB
/
runme
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
126
#!/usr/bin/env python
import ql
import os
import ql.prepr
import ql.perf
import ql.migrate
from ql.pg import psql
import sys
import glob
import re
if 'DB' in os.environ:
db = os.environ['DB']
else:
print "Please set env DB=?"
exit(1)
def each_file(fls,cb):
for fl in sorted(fls):
if os.path.isfile(fl):
cb(fl)
else:
print 'Could not fild file %s' % fl
def run_tests(args):
load(['./src/tests.sql'])
if not args:
args = glob.glob('./test/*_spec.sql')
psql(db, 'SELECT tests.start()')
def run(fl):
ql.reload_test(db, fl)
each_file(args,run)
res = psql(db, 'SELECT tests.fail()')
if res['returncode'] != 0:
print ql.hl('red','FAILED TESTS')
report = psql(db, 'SELECT * from tests.report()')['stdout']
print ql.hl('red', report)
sys.exit(1)
else:
print ql.hl('green','All tests passed')
def compile(args):
def run(fl):
f = open(fl)
print '-- FILE: %s' % fl
print ql.prepr.process(fl, f.read())
f.close
each_file(args,run)
def reload(args):
if not args: args = glob.glob('./src/**/*.sql')
ql.reload_files(db,args)
def load(args):
if not args: args = glob.glob('./src/**/*.sql')
def run(fl): ql.reload(db, fl)
each_file(args,run)
def integrate(args):
print psql('postgres','drop database if exists %s' % db)['stdout']
print psql('postgres','create database %s' % db)['stdout']
migrate(args)
run_tests([])
def build(args):
integrate(args)
ql.pgdump(db)
def install(args):
print 'TODO'
def migrate(args):
ql.migrate.migrate(db)
def seed(args):
if not 'PATIENTS_COUNT' in os.environ:
print "Please set required PATIENTS_COUNT environment variable"
exit(1)
if not 'RAND_SEED' in os.environ:
os.environ['RAND_SEED'] = '0.21'
r = psql(db, """\\conninfo
SELECT fhir.generate_tables('{Patient,Organization,Encounter,Practitioner}');
""")
perf_files = glob.glob('./perf/*.sql')
reload(perf_files)
r = psql(db, """\\timing
SELECT generator.generate(%(patients_count)s, %(rand_seed)s)
""" \
% {'patients_count': os.environ['PATIENTS_COUNT'],
'rand_seed': os.environ['RAND_SEED']})
print r["stdout"]
def perf(args):
ql.perf.perf(db, args)
def rename(args):
mod_nm = args[0]
new_nm = args[1]
print '%s -> %s' % (mod_nm, new_nm)
commands = dict(test=run_tests, compile=compile, load=load, reload=reload, integrate=integrate, build=build, migrate=migrate, seed=seed, perf=perf, rename=rename)
if len(sys.argv) < 2:
print "Please use command:"
print commands.keys()
exit(1)
cmd = sys.argv[1]
print cmd
if cmd in commands:
print 'run command %s' % cmd
commands[cmd](sys.argv[2:])
else:
print 'Unknown command %s' % cmd
print commands