-
Notifications
You must be signed in to change notification settings - Fork 9
/
pyDwCli.py
45 lines (38 loc) · 924 Bytes
/
pyDwCli.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
import urllib
import re
import traceback
import sys
if len(sys.argv) < 2:
print "Usage: pyDwCli <url> [<cmd>]"
sys.exit(1)
url = sys.argv[1]
cmd = None
if len(sys.argv) > 2:
cmd = " ".join(sys.argv[2:])
while True:
try:
if cmd:
wdata = cmd
else:
print "pyDriveWire>",
wdata = raw_input()
except EOFError:
print
print "Bye!"
break
# basic stuff
if wdata.find(chr(4)) == 0 or wdata.lower() in ["exit", "quit"]:
# XXX Do some cleanup... how?
print "Bye!"
break
try:
wdata = re.subn('.\b', '', wdata)[0]
wdata = re.subn('.\x7f', '', wdata)[0]
conn = urllib.urlopen(url, wdata)
print conn.read()
if cmd:
break
except Exception as ex:
print "ERROR:: %s" % str(ex)
traceback.print_exc()
# vim: ts=4 sw=4 sts=4 expandtab