-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsudo.py
executable file
·102 lines (89 loc) · 2.32 KB
/
sudo.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
#!/usr/bin/python
"""
Test library to execute CFA-635 controller code
"""
import sys, getopt, yaml
from cfa635.Device import Device
from cfa635.Controller import Controller
def usage():
"""
Display usage
"""
print 'main.py [-v] -c <configfile>'
print '\n'
print '-v --verbose - Enable extra STDOUT output'
print '-c --config - Config file (required)'
print '-h --help - this help'
def main(argv):
"""
Generate a SUDO string.
"""
configfile = ''
verbose = 0
try:
opts, _args = getopt.getopt(argv, "hvc:", ["ifile=", "ofile="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
usage()
sys.exit()
elif opt == '-v':
verbose += 1
print "Verbose set to: ", verbose
elif opt in ("-c", "--config"):
configfile = arg
if configfile == '':
print "Error: Config file not specified\n"
usage()
sys.exit()
with open(configfile, 'r') as ymlfile:
cfg = yaml.load(ymlfile)
if verbose > 0:
cfg['verbosity'] = verbose
print "Starting LCD Interface:"
dev = Device(cfg)
cfa = Controller(dev)
#0x00
cfa.api.ping(None)
now_last = 0;
count = 0
code_length = 12
code = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
while True:
print "Create CODE: "
while count < code_length:
(now,_press,_release) = cfa.api.read_keypad()
now = ord(now)
if now != now_last:
print "NOW Change Before: ",now_last," Now: ",now
code[count] = now
now_last = now
count += 1
print "Code = : ",yaml.dump(code)
tries = 4
print "Try the code:"
while tries > 0:
count = 0
success = True
now_last = 0;
while count < code_length:
(now,_press,_release) = cfa.api.read_keypad()
now = ord(now)
if now != now_last:
if code[count] != now:
success = False
now_last = now
count += 1
tries -= 1
if success:
print "SUCCESS!"
else:
print "Fail!"
code = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
count = 0
now_last = 0;
dev.close()
if __name__ == "__main__":
main(sys.argv[1:])