Disable error message and add prints for restore_sql_file

pull/98/head
Meng Li 2020-08-18 17:39:25 -04:00
parent 75deaf7c26
commit b116accb6d
1 changed files with 8 additions and 2 deletions

View File

@ -14,9 +14,15 @@ create_cmd = "mysql -h " + config[group]["host"] + " -u " + config[group]["user"
restore_cmd = "mysql -h " + config[group]["host"] + " -u " + config[group]["user"] + " -p" + config[group]["password"] + " " + config[group]["database"] + " < data/external/rapids_example.sql"
try:
subprocess.run(checkdb_cmd.split(), check = True)
print("Checking if " + config[group]["database"] + " database exists")
subprocess.run(checkdb_cmd.split(), check = True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
print(config[group]["database"] + " database does not exist")
print("Creating " + config[group]["database"] + " database")
os.system(create_cmd)
print(config[group]["database"] + " database created")
print("Restoring rapids_example.sql")
os.system(restore_cmd)
print("rapids_example.sql restored in " + config[group]["database"] + " database")
else:
raise ValueError(config[group]["database"] + " DB already exists.")
raise ValueError(config[group]["database"] + " DB already exists")