mirror of https://github.com/fail2ban/fail2ban
code review
parent
4c1bcac0c7
commit
4180cc362e
|
@ -411,11 +411,9 @@ class Fail2banClient(Fail2banCmdLine, Thread):
|
|||
signal.signal(s, sh)
|
||||
|
||||
|
||||
##
|
||||
# Wonderful visual :)
|
||||
#
|
||||
|
||||
class _VisualWait:
|
||||
"""Small progress indication (as "wonderful visual") during waiting process
|
||||
"""
|
||||
pos = 0
|
||||
delta = 1
|
||||
def __init__(self, maxpos=10):
|
||||
|
@ -427,6 +425,8 @@ class _VisualWait:
|
|||
sys.stdout.write('\r'+(' '*(35+self.maxpos))+'\r')
|
||||
sys.stdout.flush()
|
||||
def heartbeat(self):
|
||||
"""Show or step for progress indicator
|
||||
"""
|
||||
if not self.pos:
|
||||
sys.stdout.write("\nINFO [#" + (' '*self.maxpos) + "] Waiting on the server...\r\x1b[8C")
|
||||
self.pos += self.delta
|
||||
|
@ -441,6 +441,8 @@ class _VisualWait:
|
|||
elif self.pos < 2:
|
||||
self.delta = 1
|
||||
class _NotVisualWait:
|
||||
"""Mockup for invisible progress indication (not verbose)
|
||||
"""
|
||||
def __enter__(self):
|
||||
return self
|
||||
def __exit__(self, *args):
|
||||
|
@ -449,6 +451,8 @@ class _NotVisualWait:
|
|||
pass
|
||||
|
||||
def VisualWait(verbose, *args, **kwargs):
|
||||
"""Wonderful visual progress indication (if verbose)
|
||||
"""
|
||||
return _VisualWait(*args, **kwargs) if verbose > 1 else _NotVisualWait()
|
||||
|
||||
|
||||
|
|
|
@ -83,9 +83,6 @@ class Fail2banCmdLine():
|
|||
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).")
|
||||
output("")
|
||||
output("Written by Cyril Jaquier <cyril.jaquier@fail2ban.org>.")
|
||||
output("Many contributions by Yaroslav O. Halchenko <debian@onerussian.com>.")
|
||||
|
||||
def dispUsage(self):
|
||||
""" Prints Fail2Ban command line options and exits
|
||||
|
@ -262,7 +259,7 @@ class Fail2banCmdLine():
|
|||
@staticmethod
|
||||
def exit(code=0): # pragma: no cover - can't test
|
||||
logSys.debug("Exit with code %s", code)
|
||||
if os._exit:
|
||||
if hasattr(os, '_exit') and os._exit:
|
||||
os._exit(code)
|
||||
else:
|
||||
sys.exit(code)
|
||||
|
|
|
@ -27,6 +27,9 @@ __license__ = "GPL"
|
|||
import textwrap
|
||||
|
||||
def output(s):
|
||||
"""Default output handler for printing protocol.
|
||||
Used to ease mocking in the test cases.
|
||||
"""
|
||||
print(s)
|
||||
|
||||
##
|
||||
|
|
|
@ -419,7 +419,7 @@ class Server:
|
|||
getLogger("fail2ban").setLevel(getattr(logging, value))
|
||||
self.__logLevel = value
|
||||
except AttributeError:
|
||||
raise ValueError("Invalid log level")
|
||||
raise ValueError("Invalid log level %r" % value)
|
||||
|
||||
##
|
||||
# Get the logging level.
|
||||
|
|
|
@ -54,10 +54,9 @@ if not CONFIG_DIR:
|
|||
else:
|
||||
CONFIG_DIR = '/etc/fail2ban'
|
||||
|
||||
# In not installed env (setup, test-cases) use fail2ban modules from main directory:
|
||||
if 1 or os.environ.get('PYTHONPATH', None) is None:
|
||||
os.putenv('PYTHONPATH', os.path.dirname(os.path.dirname(os.path.dirname(
|
||||
os.path.abspath(__file__)))))
|
||||
# During the test cases (or setup) use fail2ban modules from main directory:
|
||||
os.putenv('PYTHONPATH', os.path.dirname(os.path.dirname(os.path.dirname(
|
||||
os.path.abspath(__file__)))))
|
||||
|
||||
class F2B(optparse.Values):
|
||||
def __init__(self, opts={}):
|
||||
|
|
Loading…
Reference in New Issue