summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-05 09:55:22 +0200
committerimarom <imarom@cisco.com>2015-11-05 09:55:22 +0200
commit64198d95efc9c60de0f9a5cef1b24a67e0744d4b (patch)
tree1da65131531297959523461d38236a72e95e4a6c
parente92507617ed8069b674fa5729b1e6a0c5d4b2662 (diff)
parent36a9677c0abc038235e7bf706cb2b3dc9e720284 (diff)
Merge branch 'rpc_intg1' of csi-sceasr-b45:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-core into rpc_intg1
-rw-r--r--scripts/automation/trex_control_plane/console/line_parsing.py47
1 files changed, 46 insertions, 1 deletions
diff --git a/scripts/automation/trex_control_plane/console/line_parsing.py b/scripts/automation/trex_control_plane/console/line_parsing.py
index 34776424..c1227a39 100644
--- a/scripts/automation/trex_control_plane/console/line_parsing.py
+++ b/scripts/automation/trex_control_plane/console/line_parsing.py
@@ -1,5 +1,50 @@
-__author__ = 'danklei'
+import argparse
+from collections import namedtuple
+import sys
+ArgumentPack = namedtuple('ArgumentPack', ['name_or_flags', 'options'])
+# class ArgumentPack(namedtuple('ArgumentPack', ['name_or_flags', 'options'])):
+#
+# @property
+# def name_or_flags(self):
+# return self.name_or_flags
+#
+# @name_or_flags.setter
+# def name_or_flags(self, val):
+# print "bla"
+# if not isinstance(val, list):
+# self.name_or_flags = [val]
+# else:
+# self.name_or_flags = val
+
+
+OPTIONS_DB = {'-m': ArgumentPack(['-m', '--multiplier'],
+ {'help': "Set multiplier for stream", 'dest':"mult"}),
+ 'file_path': ArgumentPack(['file'],
+ {'help': "File path to yaml file"})}
+
+
+class CCmdArgParser(argparse.ArgumentParser):
+
+ def __init__(self, *args, **kwargs):
+ super(CCmdArgParser, self).__init__(*args, **kwargs)
+ pass
+
+ def error(self, message):
+ # self.print_usage(sys.stderr)
+ self.print_help()
+ return
+
+def gen_parser(op_name, *args):
+ parser = CCmdArgParser(prog=op_name, conflict_handler='resolve')
+ for param in args:
+ try:
+ parser.add_argument(*OPTIONS_DB[param].name_or_flags,
+ **OPTIONS_DB[param].options)
+ except KeyError, e:
+ cause = e.args[0]
+ raise KeyError("The attribute '{0}' is missing as a field of the {1} option.\n".format(cause, param))
+ return parser
if __name__ == "__main__":
pass \ No newline at end of file