2017-05-01 20:20:53 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-01-04 21:53:35 +01:00
|
|
|
# contains helper methods
|
2017-05-01 20:20:53 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
|
|
|
|
def executeCommmand(inst_command):
|
|
|
|
proc = subprocess.Popen(inst_command , stdout=PIPE, stderr= PIPE, shell=True)
|
|
|
|
print ( inst_command )
|
|
|
|
oo,ee = proc.communicate()
|
|
|
|
print (ee)
|
|
|
|
print (oo)
|
|
|
|
|
|
|
|
def executeSQLscript(sqlfile, conn_options, dbname):
|
2019-01-04 21:53:35 +01:00
|
|
|
inst_command = 'sqlcmd -I ' + conn_options + ' -i ' + sqlfile + ' -d ' + dbname
|
2017-05-01 20:20:53 +02:00
|
|
|
executeCommmand(inst_command)
|
|
|
|
|
2019-01-04 21:53:35 +01:00
|
|
|
def manageTestDB(sqlfile, conn_options, dbname):
|
|
|
|
tmp_sql_file = 'test_db_tmp.sql'
|
|
|
|
if os.path.exists(tmp_sql_file):
|
|
|
|
os.remove(tmp_sql_file)
|
|
|
|
with open(sqlfile, 'r') as infile:
|
|
|
|
script = infile.read().replace('TEST_DB', dbname)
|
|
|
|
with open(tmp_sql_file, 'w') as outfile:
|
|
|
|
outfile.write(script)
|
2017-05-01 20:20:53 +02:00
|
|
|
|
2019-01-04 21:53:35 +01:00
|
|
|
executeSQLscript(tmp_sql_file, conn_options, 'master')
|
|
|
|
os.remove(tmp_sql_file)
|