-
Notifications
You must be signed in to change notification settings - Fork 2
/
checktools.py
144 lines (109 loc) · 3.02 KB
/
checktools.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import subprocess as sp
import datetime
import sys
cc = 0
logfile = open('log.txt','a')
ins = "\nChecks for dev libraries (fmt,sqlite3,yaml), and binaries (make,cmake,git,g++)\n"
print("\033[1m{}\033[0m".format(ins))
logfile.write(ins)
ok = False
def genTS(): return datetime.datetime.now().replace(tzinfo=datetime.timezone.utc)
print(genTS())
def exec_cmd(_cmd,cc):
op = None
try:
logfile.write('\n----');
logfile.write('\n[{}]:{}'.format(cc,genTS()))
logfile.write('\n\ncommand:\n {}'.format(_cmd))
op = sp.Popen(_cmd.split(' '),stdout=sp.PIPE, stderr=sp.PIPE)
logfile.write('\n\noutput:\n {}'.format(str(op.stdout.read(),'utf-8')))
logfile.write('\n\n {}'.format(str(op.stderr.read(),'utf-8')))
except:
logfile.write('\n\nstatus:\n {}\n\n'.format('FAILED!'))
print("FAILED AT:\n [{}]:{}".format(cc,_cmd))
print("====================================")
print("ERROR: Please check the logfile....");
print("====================================")
sys.exit(1)
return True
cc += 1
cmd = "rm -rf ./build"
print('Delete and recreate \'./build\' directory: [y/n]')
for line in sys.stdin:
if 'y' == line.rstrip():
ok = exec_cmd(cmd,cc)
break;
else:
print(" \'./build\' not deleted")
break;
cc+=1
cmd = "mkdir -p ./tests_bin/"
exec_cmd(cmd,cc)
# created if doesn't exist
cc+=1
cmd = "mkdir -p ./build"
exec_cmd(cmd,cc)
cc+=1
cmd = "g++ --version"
ok = exec_cmd(cmd,cc)
cc+=1
cmd = "git --version"
ok = exec_cmd(cmd,cc)
cc+=1
cmd = "make --version"
ok = exec_cmd(cmd,cc)
cmd = "cmake --version"
cc+=1
ok = exec_cmd(cmd,cc)
cc += 1
cmd = "pkg-config --version"
ok = exec_cmd(cmd,cc)
# Get the deps into build directory
cc += 1
url = "https://github.com/fmtlib/fmt.git"
dd = './build'
cmd = "git -C {} clone {}".format(dd,url)
exec_cmd(cmd,cc)
cc += 1
url = "https://github.com/jbeder/yaml-cpp"
cmd = "git -C {} clone {}".format(dd,url)
exec_cmd(cmd,cc)
# check for the headers by compiling
cc += 1
f='./tests/default_headers.cpp'
o='./tests_bin/default_headers_check'
cmd = "g++ -o {} -I./include {}".format(o,f)
exec_cmd(cmd,cc)
cc += 1
cmd = "./{}".format(o)
exec_cmd(cmd,cc)
cc += 1
cmd = "rm -rf {}".format(o)
exec_cmd(cmd,cc)
cc += 1
f='./tests/app_headers.cpp'
o='./tests_bin/app_header_check'
cmd = "make app"
exec_cmd(cmd,cc)
cc += 1
cmd = "./tests_bin/app_header_check"
exec_cmd(cmd,cc)
cc += 1
cmd = "rm -rf ./tests_bin/app_header_check"
exec_cmd(cmd,cc)
cc += 1
cmd = "pkg-config --list-all"
exec_cmd(cmd,cc)
cmd = "\nSUCCESS: All checks have passed and commands run..."
logfile.write(cmd)
print(cmd)
cmd = "\nPlease go to \'./build\' dir and build, the libraries"
logfile.write(cmd)
print(cmd)
print("\nCheck out the log file {} for what has been processed by this script".format('log.txt'))
cmd = "\nAfter building the libraries please run: \n \033[1m{}\033[0m\n".format('make install')
logfile.write(cmd)
print(cmd)
cmd = "Please add the macros to \'bashrc\'in the directory :\n |{} \nfor more functionality, refer to the docs: \n |{}\n".format('github/bash','github.com/wiki')
logfile.write(cmd)
print(cmd)