summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gregy <gregy@gregy.cz> 2010-08-08 11:59:53 +0200
committerGravatar Gregy <gregy@gregy.cz> 2010-08-08 11:59:53 +0200
commitabc562faf737ad769ec03f5ac94ba467de828ffa (patch)
tree6f826bfe618eb1da28e3c722d360f828469d4dba
parentmerge (diff)
downloadpyload-abc562faf737ad769ec03f5ac94ba467de828ffa.tar.xz
Handling special cases in log (empty, non existing..)
-rw-r--r--module/web/pyload/views.py10
-rwxr-xr-xpyLoadCore.py16
2 files changed, 14 insertions, 12 deletions
diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py
index 082882147..2d210b6d7 100644
--- a/module/web/pyload/views.py
+++ b/module/web/pyload/views.py
@@ -209,7 +209,7 @@ def logs(request, item=-1):
item = 0
if item < 1 or type(item) is not int:
- item = len(log) - perpage + 1
+ item = 1 if len(log) - perpage + 1 < 1 else len(log) - perpage + 1
if type(fro) is datetime: # we will search for datetime
item = -1
@@ -225,21 +225,23 @@ def logs(request, item=-1):
date,time,level,message = l.split(" ", 3)
dtime = datetime.strptime(date+' '+time, '%d.%m.%Y %H:%M:%S')
except:
- dtime = datetime.strptime('01.01.3333 12:12:12', '%d.%m.%Y %H:%M:%S')
+ dtime = None
date = '?'
time = ' '
level = '?'
message = l;
- if item == -1 and fro <= dtime:
+ if item == -1 and dtime != None and fro <= dtime:
item = counter #found our datetime
if item >= 0:
data.append({'line': counter, 'date': date+" "+time, 'level':level, 'message': message})
perpagecheck = perpagecheck +1;
- if fro == None: #if fro not set set it to first showed line
+ if fro == None and dtime != None: #if fro not set set it to first showed line
fro = dtime;
if perpagecheck >= perpage and perpage > 0:
break
+ if fro == None: #still not set, empty log?
+ fro = datetime.now()
if reversed:
data.reverse()
return render_to_response(join(settings.TEMPLATE, 'logs.html'), RequestContext(request, {'warning': warning, 'log': data, 'from': fro.strftime('%d.%m.%Y %H:%M:%S'), 'reversed': reversed, 'perpage':perpage, 'perpage_p':sorted(perpage_p), 'iprev': 1 if item - perpage < 1 else item - perpage, 'inext': (item + perpage) if item+perpage < len(log) else item}, [status_proc]))
diff --git a/pyLoadCore.py b/pyLoadCore.py
index d40173aed..2bc2a946e 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -544,15 +544,15 @@ class ServerMethods():
self.add_package(th.name, [th.name], 1)
- def get_log(self, offset=0):
+ def get_log(self):
filename = join(self.core.config['log']['log_folder'], 'log.txt')
- fh = open(filename, "r")
- lines = fh.readlines()
- fh.close()
- if offset >= len(lines):
- return None
-
- return lines
+ try:
+ fh = open(filename, "r")
+ lines = fh.readlines()
+ fh.close()
+ return lines
+ except:
+ return ('No log available',)
def stop_downloads(self):
pyfiles = self.core.files.cache.values()