-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautomaton.py
More file actions
48 lines (41 loc) · 1.13 KB
/
Copy pathautomaton.py
File metadata and controls
48 lines (41 loc) · 1.13 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
import sys
import automaton.client.rest as client_lib
import automaton.lib.exceptions as exceptions
import socket
host = "localhost"
args = sys.argv[1:]
if sys.argv[1] == "-h": # Allow host to be specified
host = sys.argv[2]
args = sys.argv[3:]
try:
client = client_lib.ClientWrapper(host, appname="cmd")
client.open()
try:
client.allowAllServices()
cmd = ''
if len(sys.argv) > 1:
cmd = ' '.join(args)
while True:
if cmd == "help":
print client.getAvailableServices()
elif cmd != '':
try:
print client.interpret(cmd)
except exceptions.ServiceNotProvidedError as err:
print err
except exceptions.ServiceNotRegisteredError as err:
print err
except exceptions.UnknownIntentError:
print "Cannot understand query."
cmd = raw_input("> ")
except exceptions.ClientNotRegisteredError:
print "Service not registered"
finally:
try:
client.close()
except exceptions.ClientNotRegisteredError:
pass
except exceptions.ClientError as err:
print repr(err)
except (KeyboardInterrupt, EOFError):
pass