summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDan Klein <danklein10@gmail.com>2015-11-05 07:35:15 +0200
committerDan Klein <danklein10@gmail.com>2015-11-05 07:35:32 +0200
commit36a9677c0abc038235e7bf706cb2b3dc9e720284 (patch)
treef2585a4f01cc4d2fc62c6d6d302ab5459b56a794 /scripts
parent530625493e92ac300b8a1135d061a3ecd428008d (diff)
added custom line parsing class and methods
Diffstat (limited to 'scripts')
-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