From 6ec401381b4b3e6facce5c9a749bc08b8c30f1a7 Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 18 Aug 2015 17:00:00 +0300 Subject: draft --- scripts/trex_console | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 scripts/trex_console (limited to 'scripts') diff --git a/scripts/trex_console b/scripts/trex_console new file mode 100755 index 00000000..6a79d54a --- /dev/null +++ b/scripts/trex_console @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/python ../src/console/trex_console.py -- cgit 1.2.3-korg From 8384612b8493a4a896e91e3bb9d5d25689a87c12 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 20 Aug 2015 09:25:33 +0300 Subject: added args to the console --- scripts/trex-console | 2 ++ scripts/trex_console | 2 -- src/console/trex_console.py | 34 +++++++++++++++++++++++++++++++--- src/console/trex_rpc_client.py | 6 +++++- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100755 scripts/trex-console delete mode 100755 scripts/trex_console (limited to 'scripts') diff --git a/scripts/trex-console b/scripts/trex-console new file mode 100755 index 00000000..50e097e7 --- /dev/null +++ b/scripts/trex-console @@ -0,0 +1,2 @@ +#!/bin/bash +../src/console/trex_console.py $@ diff --git a/scripts/trex_console b/scripts/trex_console deleted file mode 100755 index 6a79d54a..00000000 --- a/scripts/trex_console +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -/usr/bin/python ../src/console/trex_console.py diff --git a/src/console/trex_console.py b/src/console/trex_console.py index 2175fb5c..1cb8194d 100755 --- a/src/console/trex_console.py +++ b/src/console/trex_console.py @@ -1,8 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- import cmd import json import ast +import argparse +import sys from trex_rpc_client import RpcClient import trex_status @@ -78,7 +80,17 @@ class TrexConsole(cmd.Cmd): def do_connect (self, line): '''Connects to the server\n''' - rc, msg = self.rpc_client.connect() + + if line == "": + rc, msg = self.rpc_client.connect() + else: + sp = line.split() + if (len(sp) != 2): + print "\n[usage] connect [server] [port] or without parameters\n" + return + + rc, msg = self.rpc_client.connect(sp[0], sp[1]) + if rc: print "[SUCCESS]\n" else: @@ -207,9 +219,25 @@ class TrexConsole(cmd.Cmd): # aliasing do_exit = do_EOF = do_q = do_quit +def setParserOptions (): + parser = argparse.ArgumentParser(prog="trex_console.py") + + parser.add_argument("-s", "--server", help = "T-Rex Server [default is localhost]", + default = "localhost", + type = str) + + parser.add_argument("-p", "--port", help = "T-Rex Server Port [default is 5050]\n", + default = 5050, + type = int) + + return parser + def main (): + parser = setParserOptions() + options = parser.parse_args(sys.argv[1:]) + # RPC client - rpc_client = RpcClient("localhost", 5050) + rpc_client = RpcClient(options.server, options.port) # console try: diff --git a/src/console/trex_rpc_client.py b/src/console/trex_rpc_client.py index 2ce44afb..77d5fe1c 100644 --- a/src/console/trex_rpc_client.py +++ b/src/console/trex_rpc_client.py @@ -143,7 +143,11 @@ class RpcClient(): print "\nConnecting To RPC Server On {0}".format(self.transport) self.socket = self.context.socket(zmq.REQ) - self.socket.connect(self.transport) + try: + self.socket.connect(self.transport) + except zmq.error.ZMQError as e: + return False, "ZMQ Error: Bad server or port name: " + str(e) + self.connected = True -- cgit 1.2.3-korg