-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.py
30 lines (25 loc) · 819 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import configparser
from termcolor import cprint
import subprocess
import os.path
from settings import *
def check_dir(dir):
if not os.path.exists(dir):
print(f"Directory '{dir}' not found")
sys.exit(1)
def execute(cmd, hide_output=False):
cprint(f"Executing: '{cmd}'", 'magenta')
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
stdout, stderr = p.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if p.returncode != 0:
cprint(f"The following command failed:\n{cmd}\nStderr: {stdout}\nStderr: {stderr}", 'red')
sys.exit(1)
if not hide_output:
if len(stdout) > 0:
print(stdout)
if len(stderr) > 0:
print(stderr)
return stdout