-
Notifications
You must be signed in to change notification settings - Fork 0
/
enforce_sheets_opinion
executable file
·79 lines (68 loc) · 2.56 KB
/
enforce_sheets_opinion
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
#!/usr/bin/env python3
from googleapi.memberlist import get_memberlist
from rdoorlib import GHCard,GHACL,GHMUX
def get_sheets_acl():
values = get_memberlist()
if not values:
raise(Exception('No data found.'))
else:
new_acl = GHACL()
# Dec is the decimal equivalent of FC+CC
# With Google Sheets, if a cell is empty, no data is returned for that column
# So the row object may contain between 1 and 5 columns, we'll have to deal with None's.
# order on sheet is 'Name, Status, Card FC, Card CC, Card Dec:'
for row in values:
is_active = False
fc = 0
cc = 0
dec = 0
length = len(row)
if length < 1:
print("Bogus row, no data") # should log XXX
continue
name = row[0]
if length < 2:
print("No status data for '{}'".format(name)) # should log XXX
continue
if row[1] == 'ACTIVE':
is_active = True
if length < 3:
print("No fc data for '{}'".format(name)) # should log XXX
continue
fc = int(row[2])
if length < 4:
print("No cc data for '{}'".format(name)) # should log XXX
continue
cc = int(row[3])
if length < 5:
print("No dec data for '{}'".format(name)) # should log XXX
continue
dec = int(row[3])
if fc == 0 or fc == 0xFF or cc == 0 or cc == 0xFFFF:
# this may be a bug in the future, but 00,0000 or FF,FFFF
# will probably be a data input error
print("We don't believe in edge cases",
"all zeros or all ones on fc/cc for '{}'".format(name))
continue
#print((name,is_active,fc,cc,dec))
new_acl.add(GHCard("{0:0{1}x}".format(fc,2),"{0:0{1}x}".format(cc,4),name=name,allowed=is_active))
return new_acl
def get_door_acl(door):
ghacl = GHACL()
acl_list = door.acl_list()
if len(acl_list) == 0:
raise(Exception('No ACL list from door controller'))
for acl in acl_list:
ghacl.add(GHCard(acl['facility_code'], acl['card_code'],
attribute=acl['attribute'],
index=acl['index'],
location=acl['addr'],
))
return ghacl
def main():
door = GHMUX()
current = get_door_acl(door)
sheets = get_sheets_acl()
current.delta_list_to(sheets, door)
if __name__ == '__main__':
main()