From d0a322f2b858eb89ee7b7cdca4b273e8e09d6f67 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 15 Jun 2012 22:21:16 -0400 Subject: [PATCH] ENH: be able to control verbosity from cmdline for fail2ban-testcases --- fail2ban-testcases | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index 1ade220d..a6e473d8 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -1,6 +1,8 @@ #!/usr/bin/python # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- # vi: set ft=python sts=4 ts=4 sw=4 noet : +"""Script to run Fail2Ban tests battery +""" # This file is part of Fail2Ban. # @@ -19,8 +21,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Author: Cyril Jaquier -# -# $Revision$ __author__ = "Cyril Jaquier" __version__ = "$Revision$" @@ -41,6 +41,28 @@ from testcases import datedetectortestcase from testcases import actiontestcase from server.mytime import MyTime +from optparse import OptionParser, Option + +def get_opt_parser(): + # use module docstring for help output + p = OptionParser( + usage="%s [OPTIONS]\n" % sys.argv[0] + __doc__, + version="%prog " + version) + + p.add_options([ + Option('-l', "--log-level", type="choice", + dest="log_level", + choices=('debug', 'fatal'), + default='fatal', + help="Log level for the logger to use during running tests"), + ]) + + return p + +parser = get_opt_parser() +(opts, files) = parser.parse_args() +assert(not len(files)) + # Set the time to a fixed, known value # Sun Aug 14 12:00:00 CEST 2005 @@ -55,7 +77,7 @@ logSys = logging.getLogger("fail2ban") # Add the default logging handler stdout = logging.StreamHandler(sys.stdout) logSys.addHandler(stdout) -logSys.setLevel(logging.FATAL) +logSys.setLevel(getattr(logging, opts.log_level.upper())) print "Fail2ban " + version + " test suite. Please wait..."