-
Notifications
You must be signed in to change notification settings - Fork 0
/
inst_dependencies.py
38 lines (34 loc) · 1.18 KB
/
inst_dependencies.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
#Dependencies used in Update script. From Sunfounder's install script.
def errors(self):
return self._errors
def colored(text, color):
color = color.lower()
colors = {
"grey": "\033[1;30m%s\033[0m",
"red": "\033[1;31m%s\033[0m",
"green": "\033[1;32m%s\033[0m",
"yellow": "\033[1;33m%s\033[0m",
"blue": "\033[1;34m%s\033[0m",
"purple": "\033[1;35m%s\033[0m",
"cyan": "\033[1;36m%s\033[0m",
"white": "\033[1;37m%s\033[0m",
}
return colors[color] % text
def run_command(cmd=""):
import subprocess
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = p.stdout.read().decode('utf-8')
status = p.poll()
return status, result
def do(msg="", cmd=""):
print("[ ] %s..." % (msg), end='', flush=True)
status, result = eval(cmd)
if status == 0 or status == None or result == "":
print('\r[ %s ]' % colored("OK", "green"))
return True
else:
print('\r[%s]' % colored("Fail", "red"))
errors.append("%s error:\n Status:%s\n Error:%s" %
(msg, status, result))
return False