From 5c57334bb61ecd44d8b6b69080dce9ff4748a806 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Thu, 9 Jul 2020 17:27:54 +0530 Subject: [PATCH] fix: move run_command to utils Signed-off-by: Chinmay D. Pai --- build/common/commands/new.py | 2 +- build/common/commands/restore_backup.py | 12 +----------- build/common/commands/utils.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 build/common/commands/utils.py diff --git a/build/common/commands/new.py b/build/common/commands/new.py index 96175e12..feba0401 100644 --- a/build/common/commands/new.py +++ b/build/common/commands/new.py @@ -5,7 +5,7 @@ import semantic_version from frappe.commands.site import _new_site from frappe.installer import update_site_config from check_connection import get_config, get_site_config, COMMON_SITE_CONFIG_FILE -from restore_backup import run_command +from utils import run_command def get_password(env_var, default=None): diff --git a/build/common/commands/restore_backup.py b/build/common/commands/restore_backup.py index ce085bfc..dc7333e0 100644 --- a/build/common/commands/restore_backup.py +++ b/build/common/commands/restore_backup.py @@ -1,7 +1,6 @@ import os import datetime import json -import subprocess import tarfile import hashlib import frappe @@ -9,21 +8,12 @@ import boto3 from new import get_password from push_backup import DATE_FORMAT, check_environment_variables +from utils import run_command from frappe.utils import get_sites, random_string from frappe.installer import make_conf, get_conf_params, make_site_dirs, update_site_config from check_connection import get_site_config, get_config, COMMON_SITE_CONFIG_FILE -def run_command(command): - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, error = process.communicate() - if process.returncode: - print("Something went wrong:") - print(f"error code: {process.returncode}") - print(f"stdout:\n{out}") - print(f"\nstderr:\n{error}") - - def list_directories(path): directories = [] for name in os.listdir(path): diff --git a/build/common/commands/utils.py b/build/common/commands/utils.py new file mode 100644 index 00000000..d9535c6b --- /dev/null +++ b/build/common/commands/utils.py @@ -0,0 +1,12 @@ +import subprocess + + +def run_command(command): + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, error = process.communicate() + if process.returncode: + print("Something went wrong:") + print(f"return code: {process.returncode}") + print(f"stdout:\n{out}") + print(f"\nstderr:\n{error}") + exit(process.returncode)