2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-12-23 18:48:58 +00:00

fix: file input with subprocess

This commit is contained in:
Revant Nandgaonkar 2020-07-10 16:18:25 +05:30
parent 31ff697835
commit 4598cb24f4
2 changed files with 6 additions and 6 deletions

View File

@ -209,7 +209,8 @@ def restore_postgres(config, site_config, database_file):
run_command(psql_command + [psql_uri, "-c", f"CREATE DATABASE \"{db_name}\""])
run_command(psql_command + [psql_uri, "-c", f"CREATE user {db_name} password '{db_password}'"])
run_command(psql_command + [psql_uri, "-c", f"GRANT ALL PRIVILEGES ON DATABASE \"{db_name}\" TO {db_name}"])
run_command(psql_command + [f"{psql_uri}/{db_name}", "<", database_file.replace('.gz', '')])
with open(database_file.replace('.gz', ''), 'r') as db_file:
run_command(psql_command + [f"{psql_uri}/{db_name}", "<"], stdin=db_file)
def restore_mariadb(config, site_config, database_file):
@ -244,10 +245,9 @@ def restore_mariadb(config, site_config, database_file):
grant_privileges = mysql_command + ["-e", f"GRANT ALL PRIVILEGES ON \`{db_name}\`.* TO '{db_name}'@'%' IDENTIFIED BY '{db_password}'; FLUSH PRIVILEGES;"]
run_command(grant_privileges)
command = mysql_command + [f"{db_name}", "<", database_file.replace(".gz", "")]
print('Restoring MariaDB')
run_command(command)
with open(database_file.replace(".gz", ""), "r") as db_file:
run_command(mysql_command + [f"{db_name}", "<"], stdin=db_file)
def main():

View File

@ -1,10 +1,10 @@
import subprocess
def run_command(command, stdout=None, stderr=None):
def run_command(command, stdout=None, stdin=None, stderr=None):
stdout = stdout or subprocess.PIPE
stderr = stderr or subprocess.PIPE
process = subprocess.Popen(command, stdout=stdout, stderr=stderr)
process = subprocess.Popen(command, stdout=stdout, stdin=stdin, stderr=stderr)
out, error = process.communicate()
if process.returncode:
print("Something went wrong:")