From 95fe1cc6d927c7ca18e3e2002eceafc5b905a112 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 9 Oct 2011 15:18:54 +0200 Subject: [PATCH] Clear log properly --- couchpotato/core/plugins/log/main.py | 46 +++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/couchpotato/core/plugins/log/main.py b/couchpotato/core/plugins/log/main.py index 3daeb35e..059b304c 100644 --- a/couchpotato/core/plugins/log/main.py +++ b/couchpotato/core/plugins/log/main.py @@ -18,29 +18,33 @@ class Logging(Plugin): def get(self): nr = int(getParam('nr', 0)) + current_path = None total = 1 for x in range(0, 50): + path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '') + # Check see if the log exists + if not os.path.isfile(path): + total = x - 1 + break + # 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 - f = open(current_path, 'r') - lines = [] - for line in f.readlines(): - lines.insert(0, line) - log = '' - for line in lines: - log += line + if current_path: + # Reverse + 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, @@ -53,14 +57,20 @@ class Logging(Plugin): 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 + try: + + # Create empty file for current logging + if x is 0: + self.createFile(path, '') + else: + os.remove(path) + + except: + log.error('Couldn\'t delete file "%s": %s', (path, traceback.format_exc())) + return jsonified({ 'success': True })