Merge branch '0.10-short-version' into 0.10

pull/2141/merge
sebres 7 years ago
commit 61e30949b3

@ -41,6 +41,8 @@ ver. 0.10.4-dev-1 (20??/??/??) - development edition
### New Features
### Enhancements
* since v.0.10.4, fail2ban-client, fail2ban-server and fail2ban-regex will return version without logo info,
additionally option `-V` can be used to get version in normalized machine-readable short format.
ver. 0.10.3 (2018/04/04) - the-time-is-always-right-to-do-what-is-right

@ -25,7 +25,7 @@ import logging
import os
import sys
from ..version import version
from ..version import version, normVersion
from ..protocol import printFormatted
from ..helpers import getLogger, str2LogLevel, getVerbosityFormat
@ -78,12 +78,11 @@ class Fail2banCmdLine():
for o in obj.__dict__:
self.__dict__[o] = obj.__dict__[o]
def dispVersion(self):
def dispVersion(self, short=False):
if not short:
output("Fail2Ban v" + version)
output("")
output("Copyright (c) 2004-2008 Cyril Jaquier, 2008- Fail2Ban Contributors")
output("Copyright of modifications held by their respective authors.")
output("Licensed under the GNU General Public License v2 (GPL).")
else:
output(normVersion())
def dispUsage(self):
""" Prints Fail2Ban command line options and exits
@ -114,7 +113,7 @@ class Fail2banCmdLine():
output(" --timeout timeout to wait for the server (for internal usage only, don't read configuration)")
output(" --str2sec <STRING> convert time abbreviation format to seconds")
output(" -h, --help display this help message")
output(" -V, --version print the version")
output(" -V, --version print the version (-V returns machine-readable short format)")
if not caller.endswith('server'):
output("")
@ -168,7 +167,7 @@ class Fail2banCmdLine():
self.dispUsage()
return True
elif o in ["-V", "--version"]:
self.dispVersion()
self.dispVersion(o == "-V")
return True
return None

@ -45,7 +45,7 @@ try: # pragma: no cover
except ImportError:
FilterSystemd = None
from ..version import version
from ..version import version, normVersion
from .filterreader import FilterReader
from ..server.filter import Filter, FileContainer
from ..server.failregex import Regex, RegexException
@ -93,6 +93,10 @@ def journal_lines_gen(flt, myjournal): # pragma: no cover
break
yield flt.formatJournalEntry(entry)
def dumpNormVersion(*args):
output(normVersion())
sys.exit(0)
def get_opt_parser():
# use module docstring for help output
p = OptionParser(
@ -145,6 +149,8 @@ Report bugs to https://github.com/fail2ban/fail2ban/issues
dest="log_level",
default='critical',
help="Log level for the Fail2Ban logger to use"),
Option('-V', action="callback", callback=dumpNormVersion,
help="get version in machine-readable short format"),
Option('-v', '--verbose', action="count", dest="verbose",
default=0,
help="Increase verbosity"),

@ -452,7 +452,10 @@ class Fail2banClientTest(Fail2banClientServerBase):
self.assertLogged("Usage: " + CLIENT)
self.assertLogged("Report bugs to ")
self.pruneLog()
self.execCmd(SUCCESS, (), "-vq", "-V")
self.execCmd(SUCCESS, (), "-V")
self.assertLogged(fail2bancmdline.normVersion())
self.pruneLog()
self.execCmd(SUCCESS, (), "-vq", "--version")
self.assertLogged("Fail2Ban v" + fail2bancmdline.version)
self.pruneLog()
self.execCmd(SUCCESS, (), "--str2sec", "1d12h30m")

@ -347,6 +347,11 @@ class Fail2banRegexTest(LogCaptureTestCase):
def testExecCmdLine_Usage(self):
self.assertNotEqual(_test_exec_command_line(), 0)
self.pruneLog()
self.assertEqual(_test_exec_command_line('-V'), 0)
self.assertLogged(fail2banregex.normVersion())
self.pruneLog()
self.assertEqual(_test_exec_command_line('--version'), 0)
def testExecCmdLine_Direct(self):
self.assertEqual(_test_exec_command_line(

@ -25,3 +25,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2005-2016 Yaroslav Halchenko,
__license__ = "GPL-v2+"
version = "0.10.4.dev1"
def normVersion():
""" Returns fail2ban version in normalized machine-readable format"""
return version.replace('.fix', '').replace('.dev', '.')

Loading…
Cancel
Save