RF: prefer log over container in getLog and local variables

Even though I have left FileContainer class name intact
pull/1266/head
Yaroslav Halchenko 2015-12-02 22:57:40 -05:00
parent 59da27b9f6
commit 48202f998d
1 changed files with 11 additions and 11 deletions

View File

@ -569,13 +569,13 @@ class FileFilter(Filter):
if path in self.__logs: if path in self.__logs:
logSys.error(path + " already exists") logSys.error(path + " already exists")
else: else:
container = FileContainer(path, self.getLogEncoding(), tail) log = FileContainer(path, self.getLogEncoding(), tail)
db = self.jail.database db = self.jail.database
if db is not None: if db is not None:
lastpos = db.addLog(self.jail, container) lastpos = db.addLog(self.jail, log)
if lastpos and not tail: if lastpos and not tail:
container.setPos(lastpos) log.setPos(lastpos)
self.__logs[path] = container self.__logs[path] = log
logSys.info("Added logfile = %s" % path) logSys.info("Added logfile = %s" % path)
self._addLogPath(path) # backend specific self._addLogPath(path) # backend specific
@ -645,7 +645,7 @@ class FileFilter(Filter):
def getLogEncoding(self): def getLogEncoding(self):
return self.__encoding return self.__encoding
def getFileContainer(self, path): def getLog(self, path):
return self.__logs.get(path, None) return self.__logs.get(path, None)
## ##
@ -656,13 +656,13 @@ class FileFilter(Filter):
# is created and is added to the FailManager. # is created and is added to the FailManager.
def getFailures(self, filename): def getFailures(self, filename):
container = self.getFileContainer(filename) log = self.getLog(filename)
if container is None: if log is None:
logSys.error("Unable to get failures in " + filename) logSys.error("Unable to get failures in " + filename)
return False return False
# Try to open log file. # Try to open log file.
try: try:
has_content = container.open() has_content = log.open()
# see http://python.org/dev/peps/pep-3151/ # see http://python.org/dev/peps/pep-3151/
except IOError, e: except IOError, e:
logSys.error("Unable to open %s" % filename) logSys.error("Unable to open %s" % filename)
@ -683,15 +683,15 @@ class FileFilter(Filter):
# start reading tested to be empty container -- race condition # start reading tested to be empty container -- race condition
# might occur leading at least to tests failures. # might occur leading at least to tests failures.
while has_content: while has_content:
line = container.readline() line = log.readline()
if not line or not self.active: if not line or not self.active:
# The jail reached the bottom or has been stopped # The jail reached the bottom or has been stopped
break break
self.processLineAndAdd(line) self.processLineAndAdd(line)
container.close() log.close()
db = self.jail.database db = self.jail.database
if db is not None: if db is not None:
db.updateLog(self.jail, container) db.updateLog(self.jail, log)
return True return True
def status(self, flavor="basic"): def status(self, flavor="basic"):