small code review (normalization and duplicated codes removal)

pull/2351/head
sebres 2019-02-20 16:48:11 +01:00
parent 00a6717953
commit 2dd3c546dd
5 changed files with 6 additions and 25 deletions

View File

@ -159,7 +159,7 @@ class FailManager:
def toBan(self, fid=None):
with self.__lock:
for fid in ([fid] if fid != None and fid in self.__failList else self.__failList):
for fid in ([fid] if fid is not None and fid in self.__failList else self.__failList):
data = self.__failList[fid]
if data.getRetry() >= self.__maxRetry:
del self.__failList[fid]

View File

@ -79,12 +79,7 @@ class FilterGamin(FileFilter):
this is a common logic and must be shared/provided by FileFilter
"""
self.getFailures(path)
try:
while True:
ticket = self.failManager.toBan()
self.jail.putFailTicket(ticket)
except FailManagerEmpty:
self.failManager.cleanup(MyTime.time())
self.performBan()
self.__modified = False
##

View File

@ -117,12 +117,7 @@ class FilterPoll(FileFilter):
self.ticks += 1
if self.__modified:
try:
while True:
ticket = self.failManager.toBan()
self.jail.putFailTicket(ticket)
except FailManagerEmpty:
self.failManager.cleanup(MyTime.time())
self.performBan()
self.__modified = False
except Exception as e: # pragma: no cover
if not self.active: # if not active - error by stop...

View File

@ -140,12 +140,7 @@ class FilterPyinotify(FileFilter):
"""
if not self.idle:
self.getFailures(path)
try:
while True:
ticket = self.failManager.toBan()
self.jail.putFailTicket(ticket)
except FailManagerEmpty:
self.failManager.cleanup(MyTime.time())
self.performBan()
self.__modified = False
def _addPending(self, path, reason, isDir=False):

View File

@ -300,12 +300,8 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
else:
break
if self.__modified:
try:
while True:
ticket = self.failManager.toBan()
self.jail.putFailTicket(ticket)
except FailManagerEmpty:
self.failManager.cleanup(MyTime.time())
self.performBan()
self.__modified = 0
except Exception as e: # pragma: no cover
if not self.active: # if not active - error by stop...
break