-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetConfig.py
executable file
·30 lines (29 loc) · 1.24 KB
/
getConfig.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
#!/usr/bin/env python3
import json
ERR_PRINT = 5;
def get_conf(conffile):
'Read given configuration file and store internal actions etc'
with open(conffile, "r") as fp:
lines = []
linenos = []
for num, line in enumerate(fp, 1):
if not line or line[0] == '#':
continue
lines.append(line.replace("'", "\""))
linenos.append(num)
try:
return(json.loads("".join(lines)))
except Exception as e:
print("Error with loading gestures config.")
print("This is probably caused by not observing configuration syntax.")
print("Check if your configuration is a valid JS object (JSON).")
print()
print("problem at {0} line number, and {1} column.".format(linenos[e.lineno - 2], e.colno))
print(e.msg, "or '{'")
print()
for num in range(e.lineno - ERR_PRINT, e.lineno - 1, 1):
print("line ", linenos[num],": ", end="")
if(num >= e.lineno - 3):
print("Error somewhere on this lines => ", end="")
print("\"",lines[num][:-1],"\"") # array offset
raise Exception('error with loading gestures config.')