summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Feldt <hans.feldt@ericsson.com>2015-05-13 17:56:50 +0200
committerHans Feldt <hans.feldt@ericsson.com>2015-05-13 17:56:50 +0200
commit432430aa31d826a5cb4bf3960a6b22c05c8affeb (patch)
tree9284b65b41b06dc4f34e5c7a026b15e2039e1552
parent6b9779bb4e98b636db41903549a8d64af81d9f71 (diff)
add cmdparser
cmdparser.py is the parser for the command line tool yardstick Change-Id: I0a27be35ad21d54d8c5cc7c2ab72aa60ed8f5d1f JIRA: - Signed-off-by: Hans Feldt <hans.feldt@ericsson.com>
-rw-r--r--yardstick/cmdparser.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/yardstick/cmdparser.py b/yardstick/cmdparser.py
new file mode 100644
index 000000000..e8f770386
--- /dev/null
+++ b/yardstick/cmdparser.py
@@ -0,0 +1,71 @@
+##############################################################################
+# Copyright (c) 2015 Ericsson AB and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+""" Argument parser for yardstick command line tool
+
+"""
+
+import argparse
+import logging
+
+from pkg_resources import get_distribution
+
+
+class CmdParser(argparse.ArgumentParser):
+ def __init__(self):
+ argparse.ArgumentParser.__init__(self)
+
+ self.output_file_default = "/tmp/yardstick.out"
+ self._version = "yardstick version %s " % \
+ get_distribution('yardstick').version
+
+ self.__add_arguments()
+
+ def __add_arguments(self):
+ self.add_argument("-d", "--debug",
+ help="increase output verbosity to debug",
+ action="store_true")
+
+ self.add_argument("-v", "--verbose",
+ help="increase output verbosity to info",
+ action="store_true")
+
+ self.add_argument("-V", "--version",
+ help="display version",
+ version=self._version,
+ action="version")
+
+ self.add_argument("--keep-deploy",
+ help="keep context deployed in cloud",
+ action="store_true")
+
+ self.add_argument("--parse-only",
+ help="parse the benchmark config file and exit",
+ action="store_true")
+
+ self.add_argument("--output-file",
+ help="file where output is stored, default %s" %
+ self.output_file_default,
+ default=self.output_file_default)
+
+ self.add_argument("taskfile", type=str,
+ help="path to taskfile", nargs=1)
+
+ def parse_args(self):
+ args = argparse.ArgumentParser.parse_args(self)
+
+ logger = logging.getLogger('yardstick')
+
+ logger.setLevel(logging.WARNING)
+ if args.verbose:
+ logger.setLevel(logging.INFO)
+ if args.debug:
+ logger.setLevel(logging.DEBUG)
+
+ return args