small code review (normalization and duplicated codes removal)

pull/2351/head
sebres 6 years ago
parent 00a6717953
commit 2dd3c546dd

@ -159,7 +159,7 @@ class FailManager:
def toBan(self, fid=None): def toBan(self, fid=None):
with self.__lock: 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] data = self.__failList[fid]
if data.getRetry() >= self.__maxRetry: if data.getRetry() >= self.__maxRetry:
del self.__failList[fid] del self.__failList[fid]

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

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

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

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

Loading…
Cancel
Save