You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6 KiB

from couchpotato.api import addApiView
from couchpotato.core.helpers.request import jsonified, getParam
14 years ago
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
14 years ago
import os
14 years ago
import traceback
log = CPLog(__name__)
class Logging(Plugin):
def __init__(self):
addApiView('logging.get', self.get)
14 years ago
addApiView('logging.clear', self.clear)
def get(self):
nr = int(getParam('nr', 0))
14 years ago
total = 1
for x in range(0, 50):
path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '')
# Set current path
if x is nr:
current_path = path
# Check see if the log exists
if not os.path.isfile(path):
total = x
break
# Reverse
14 years ago
f = open(current_path, 'r')
lines = []
for line in f.readlines():
lines.insert(0, line)
log = ''
for line in lines:
log += line
return jsonified({
'success': True,
'log': log,
14 years ago
'total': total,
})
14 years ago
def clear(self):
for x in range(0, 50):
path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '')
try:
os.remove(path)
except:
log.error('Couldn\'t delete file "%s": %s', (path, traceback.format_exc()))
if not os.path.isfile(path):
break
return jsonified({
'success': True
})