-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathftpython.py
More file actions
58 lines (51 loc) · 1.29 KB
/
ftpython.py
File metadata and controls
58 lines (51 loc) · 1.29 KB
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
from command import *
class Ftpython(object):
def __init__(self):
"""
Creates new command object, calls accept_command
"""
self.command = Command()
while True:
self.accept_command()
def accept_command(self):
"""
Prompts user for command
"""
cmd = raw_input('ftpython> ')
self.dir_cmd(cmd)
def dir_cmd(self, cmd):
"""
Directs a given command to the appropriate action
"""
parsed_cmd = self.parse_cmd(cmd)
cmd = parsed_cmd['cmd']
args = parsed_cmd['args']
try:
getattr(self.command, cmd)(args)
except AttributeError:
print "Invalid command."
except TypeError:
print "Invalid command"
def parse_cmd(self, cmd):
"""
Returns a dictionary with a command name and the trailing args
"""
cmd = cmd.strip().split(' ')
name = cmd[0]
if len(cmd) > 2:
args = cmd[1:]
elif len(cmd) == 2:
args = cmd[1]
else:
args = False
return {
'cmd': name,
'args': args
}
def main():
"""
Creates instances of Ftpython
"""
Ftpython()
if __name__ == "__main__":
main()