Added a simple utilities file.
[pdm.git] / pdm-repl
... / ...
CommitLineData
1#!/usr/bin/python
2
3import sys, getopt, readline
4import pdm.cli
5
6def usage(out):
7 out.write("usage: pdm-repl [-h] SOCKET\n")
8
9opts, args = getopt.getopt(sys.argv[1:], "h")
10for o, a in opts:
11 if o == "-h":
12 usage(sys.stdout)
13 sys.exit(0)
14if len(args) < 1:
15 usage(sys.stderr)
16 sys.exit(1)
17try:
18 cl = pdm.cli.replclient(args[0])
19except Exception as e:
20 sys.stderr.write("%s: %s\n" % (args[0], e))
21 sys.exit(1)
22
23buf = ""
24while True:
25 try:
26 if buf != "":
27 line = raw_input(" ")
28 else:
29 line = raw_input("% ")
30 except EOFError:
31 break
32 if line == "":
33 sys.stdout.write(cl.run(buf))
34 buf = ""
35 else:
36 if buf == "":
37 try:
38 compile(line, "Nought", "eval")
39 except:
40 pass
41 else:
42 sys.stdout.write(cl.run(line))
43 continue
44 buf += line + "\n"