cryptonas/plugins/logs/logs.py

54 lines
1.4 KiB
Python

import cryptobox.plugins.base
import os
class logs(cryptobox.plugins.base.CryptoBoxPlugin):
pluginCapabilities = [ "system" ]
pluginVisibility = [ "preferences" ]
requestAuth = False
rank = 90
def doAction(self, lines=50, size=3000, pattern=None):
import re
## filter input
try:
lines = int(lines)
if lines < 0: raise(ValueError)
except ValueError:
lines = 50
try:
size = int(size)
if size < 0: raise(ValueError)
except ValueError:
size = 3000
if not pattern is None:
pattern = str(pattern)
if re.search(u'\W', pattern): pattern = None
self.hdf[self.hdf_prefix + "Content"] = self.__getLogContent(lines, size, pattern)
self.hdf[self.hdf_prefix + "StyleSheetFile"] = os.path.abspath(os.path.join(self.pluginDir, "logs.css"))
return "show_log"
def getStatus(self):
return "%s:%s:%s" % (
self.cbox.prefs["Log"]["Level"],
self.cbox.prefs["Log"]["Destination"],
self.cbox.prefs["Log"]["Details"])
def __getLogContent(self, lines, maxSize, pattern):
import re
if pattern:
content = []
current_length = 0
for line in self.cbox.getLogData():
if line.find(pattern) != -1:
content.append(line)
current_length += len(line)
if lines and len(content) >=lines: break
if maxSize and current_length >=maxSize: break
else:
content = self.cbox.getLogData(lines, maxSize)
return "<br/>".join(content)