8
8
class DoorShell (cmd .Cmd ):
9
9
prompt = 'doorbot> '
10
10
11
+ def get_args (self , line ):
12
+ return [ x for x in line .split (' ' ) if x != '' ]
13
+
11
14
def __init__ (self ):
12
15
cmd .Cmd .__init__ (self )
13
16
14
- def do_list (self , arg ):
17
+ def do_list (self , line ):
15
18
"""list"""
16
19
doorctl .list_users ()
17
20
18
- def do_enable (self , arg ):
21
+ def do_enable (self , line ):
19
22
"""enable <fobid>"""
20
- for rfid in arg . strip ( ' ' ). rstrip ( ' ' ). split ( ' ' ):
23
+ for rfid in self . get_args ( line ):
21
24
doorctl .enable (rfid )
22
25
23
- def do_disable (self , arg ):
26
+ def do_disable (self , line ):
24
27
"""disable <fobid>"""
25
- for rfid in arg . strip ( ' ' ). rstrip ( ' ' ). split ( ' ' ):
28
+ for rfid in self . get_args ( line ):
26
29
doorctl .disable (rfid )
27
30
28
- def do_delete (self , arg ):
31
+ def do_delete (self , line ):
29
32
"""delete <fobid>"""
30
- for rfid in arg . strip ( ' ' ). rstrip ( ' ' ). split ( ' ' ):
33
+ for rfid in self . get_args ( line ):
31
34
doorctl .delete (rfid )
32
35
33
- def do_addkey (self , arg ):
36
+ def do_addkey (self , line ):
34
37
"""addkey [<fobid> <pin>]"""
35
- args = arg . strip ( ' ' ). rstrip ( ' ' ). split ( ' ' )
36
- if args [ 0 ] == '' :
38
+ args = self . get_args ( line )
39
+ if len ( args ) == 0 :
37
40
doorctl .socket_command ('addkey' )
38
41
elif len (args ) == 2 :
39
42
try :
@@ -44,18 +47,18 @@ def do_addkey(self, arg):
44
47
else :
45
48
print "usage: addkey [<fobid> <pin>]"
46
49
47
- def do_openmode (self , arg ):
50
+ def do_openmode (self , line ):
48
51
"""openmode"""
49
52
doorctl .socket_command ('openmode' )
50
53
51
- def do_authmode (self , arg ):
54
+ def do_authmode (self , line ):
52
55
"""authmode"""
53
56
doorctl .socket_command ('authmode' )
54
57
55
- def do_resetpin (self , arg ):
58
+ def do_resetpin (self , line ):
56
59
"""resetpin [<fobid> <pin>]"""
57
- args = arg . strip ( ' ' ). rstrip ( ' ' ). split ( ' ' )
58
- if args [ 0 ] == '' :
60
+ args = self . get_args ( line )
61
+ if len ( args ) == 0 :
59
62
doorctl .socket_command ('resetpin' )
60
63
elif len (args ) == 2 :
61
64
try :
@@ -66,19 +69,19 @@ def do_resetpin(self, arg):
66
69
else :
67
70
print "usage: resetpin [<fobid> <pin>]"
68
71
69
- def do_shutdown (self , arg ):
72
+ def do_shutdown (self , line ):
70
73
"""shutdown"""
71
74
doorctl .socket_command ('shutdown' )
72
75
73
- def do_restart (self , arg ):
76
+ def do_restart (self , line ):
74
77
"""restart"""
75
78
doorctl .socket_command ('restart' )
76
79
77
- def do_quit (self , arg ):
80
+ def do_quit (self , line ):
78
81
"""quit"""
79
82
sys .exit (0 )
80
83
81
- def do_EOF (self , arg ):
84
+ def do_EOF (self , line ):
82
85
"""quit"""
83
86
sys .exit (0 )
84
87
0 commit comments