Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions cliRPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,36 @@ def usage():
return usage

if __name__ == '__main__':
if len(sys.argv) != 2:
if len(sys.argv) < 2: # If there's less than two arguments, the first being the name of the program, there can't possibly be a command
print usage()
sys.exit(-1)

context = zmq.Context()
cli_sock = context.socket(zmq.REQ)
cli_sock.connect("ipc://RPL_CLI")

try:
cli_sock.send(sys.argv[1], zmq.DONTWAIT)
except zmq.ZMQError, err:
print "unable to communicate with the simpleRPL daemon: %s" % err
sys.exit(-1)
print cli_sock.recv()
interactive = False

if sys.argv[1] == '-i': # Interactive mode is requested
interactive = True
else:
try:
cli_sock.send(sys.argv[1], zmq.DONTWAIT)
except zmq.ZMQError, err:
print "unable to communicate with the simpleRPL daemon: %s" % err
sys.exit(-1)
print cli_sock.recv()


while interactive:
command = raw_input("cliRPL > ")
if command == 'exit':
interactive = False
break
try:
print command
cli_sock.send(command, zmq.DONTWAIT)
except zmq.ZMQError, err:
print "unable to communicate with the simpleRPL daemon: %s" % err
sys.exit(-1)
print cli_sock.recv()