-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
42 lines (34 loc) · 1.02 KB
/
common.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import sys,os
INTERACTIVE = True
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def log(message):
print(message)
sys.stdout.flush()
def step(description):
log(bcolors.OKBLUE + f"========={description}==========" + bcolors.ENDC)
def report(message):
log(bcolors.BOLD + message + bcolors.ENDC)
def error(message):
log(bcolors.FAIL + message + bcolors.ENDC)
raise Exception(message)
def would_you_like_to_continue(message):
if not INTERACTIVE:
return
report(message + ". Would you like to continue (y/n):")
result = sys.stdin.readline()
if result.strip() != "y":
sys.exit(0)
def execute_command(command):
log(command)
result = os.system(command)
if (result != 0):
error(f"Failed while trying to execute: '{command}'")