This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
eccProg.py
78 lines (62 loc) · 2.62 KB
/
eccProg.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
#!/usr/bin/env python3
from time import sleep
import logging
import os
import subprocess
print("Nebra ECC Tool")
preTestFail = 0
afterTestFail = 0
ECC_SUCCESSFUL_TOUCH_FILEPATH = "/var/data/gwmfr_ecc_provisioned"
logging.basicConfig(level=os.environ.get("LOGLEVEL", "DEBUG"))
def record_successful_provision():
logging.debug("ECC provisioning complete")
# Via: https://stackoverflow.com/questions/12654772/create-empty-file-using-python/12654798
# because path lib not included in python3-minimal
# https://stackoverflow.com/questions/1158076/implement-touch-using-python
open(ECC_SUCCESSFUL_TOUCH_FILEPATH, 'a').close()
logging.debug("ECC provisioning recorded. Touched to %s" % ECC_SUCCESSFUL_TOUCH_FILEPATH)
while preTestFail < 10:
preTest = subprocess.run(["/opt/gateway_mfr/bin/gateway_mfr", "ecc", "onboarding"], capture_output=True)
preTestResult = str(preTest.stdout.decode('ascii')).rstrip()
if "not responding to pings" not in preTestResult:
break
else:
print("Can't load provisioning tool, retrying")
preTestFail += 1
sleep(2)
if "ecc_response_exec_error" in preTestResult:
print("Provisioning")
while afterTestFail < 5:
subprocess.run(["/opt/gateway_mfr/bin/gateway_mfr", "ecc", "provision"])
print("Testing")
afterTest = subprocess.run(["/opt/gateway_mfr/bin/gateway_mfr", "ecc", "onboarding"], capture_output=True).stdout
afterTestResult = str(afterTest.decode('ascii')).rstrip()
print(afterTestResult)
if "ecc_response_exec_error" in afterTestResult:
print("\033[91mProgramming FAILED\033[0m")
print("Retrying provisioning")
afterTestFail += 1
sleep(2)
elif (len(afterTestResult) == 51 or len(afterTestResult) == 52):
print("\033[92mProgramming Success!\033[0m")
record_successful_provision()
break
else:
print("\033[91mAn Unknown Error Occured\033[0m")
print("Retrying provisioning")
afterTestFail += 1
sleep(2)
elif (len(preTestResult) == 50 or len(preTestResult) == 51 or len(preTestResult) == 52):
print("\033[93mKey Already Programmed\033[0m")
print(preTestResult)
record_successful_provision()
else:
print("An Unknown Error Occured")
print(preTestResult)
# This next bit of mank is so we can run the gwmfr container for longer
# by providing the OVERRIDE_GWMFR_EXIT environment variable for trouble
# shooting purposes.
if os.getenv('OVERRIDE_GWMFR_EXIT', None):
while(True):
print("GWMFR Utility Exit Overriden")
sleep(300)