forked from ghaberek/omada-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles.py
executable file
·75 lines (53 loc) · 1.41 KB
/
profiles.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
#!/usr/bin/env python3
import sys, collections
from omada import Omada
FIELDDEF = collections.OrderedDict([
('id', ('ID', 30)),
('name', ('NAME', 30)),
('poe', ('POE', 30)),
('nativeNetworkId', ('Native Network ID', 30)),
])
def format_poe (poe):
if poe == 0:
return 'Disabled'
elif poe == 1:
return 'Enabled'
elif poe == 2:
return 'Keep the device settings'
else:
return 'Unknown'
def print_header():
if sys.stdout.isatty():
sys.stdout.write( '\33[1m' )
for key in FIELDDEF:
text,width = FIELDDEF[key]
sys.stdout.write( text.ljust(abs(width)) )
if sys.stdout.isatty():
sys.stdout.write( '\33[0m' )
sys.stdout.write( '\n' )
def print_profile ( profile ):
for key in profile:
if key == 'poe':
profile[key] = format_poe( profile['poe'])
for key in FIELDDEF:
text = profile[key] if key in profile else '--'
if not isinstance(text, str): text = str(text)
width = FIELDDEF[key][1]
if len(text) >= abs(width):
text = text[0:abs(width)-4] + '... '
elif width > 0:
text = text.ljust(abs(width))
else:
text = text.rjust(abs(width)-1)
sys.stdout.write( text )
sys.stdout.write( '\n' )
def main():
omada = Omada('omada.cfg')
omada.login()
print_header()
profiles = omada.getProfiles()
for profile in profiles:
print_profile( profile )
omada.logout()
if __name__ == '__main__':
main()