import os
import subprocess
def INFO(info):
output = "\033[1;32m" + info + "\033[0m"
print(output)
def WARNING(info):
output = "\033[1;33m" + info + "\033[0m"
print(output)
def ERROR(info):
output = "\033[1;31m" + info + "\033[0m"
print(output)
def exec_and_output(cmd, is_print=False):
if is_print:
print(cmd)
cmd = ['/bin/sh', '-c', cmd]
pipe = subprocess.Popen(cmd, shell=False, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = pipe.communicate()
if stderr:
ERROR(stderr)
return stdout
def exec_and_stderr_stdout(cmd, is_print=False):
if is_print:
print(cmd)
cmd = ['/bin/sh', '-c', cmd]
pipe = subprocess.Popen(cmd, shell=False, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = pipe.communicate()
ERROR(stderr)
return stderr, stdout
def get_work_dir_list(path):
dir_list = []
dirs = os.listdir(path)
for cur_dir in dirs:
if cur_dir[-4:] == ".zip":
continue
dir_list.append(cur_dir)
return dir_list
def mkdir_data_folder(path):
cmd = "mkdir " + path + " > /dev/null 2>&1"
exec_and_output(cmd)
def run_one_cmd(cmd):
cmd = ['/bin/sh', '-c', cmd]
with subprocess.Popen(cmd, shell=False, text=True,\
stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
print(f'\033[94m******************************\nruning cmd: {cmd}\n******************************\033[0m')
stdout, stderr = p.communicate()
ERROR(stderr)
return stdout, stderr, p.returncode