summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-02-25 16:32:17 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2010-02-25 16:32:17 +0100
commit83a4073616f9821a8ebf1df0e18e332490503eca (patch)
tree5c045ed9923dbc05277b36686544958a2afbead8
parentgui fix, better click and load support (diff)
downloadpyload-83a4073616f9821a8ebf1df0e18e332490503eca.tar.xz
webinterface improvments + server crash fix
-rw-r--r--module/config/core_default.xml1
-rw-r--r--module/file_list.py5
-rw-r--r--module/web/ServerThread.py27
-rw-r--r--module/web/ajax/views.py36
-rw-r--r--module/web/lighttpd/lighttpd_default.conf2
-rw-r--r--module/web/media/default/css/default.css3
-rw-r--r--module/web/media/default/js/funktions.js2
-rwxr-xr-xmodule/web/run_server.py62
-rw-r--r--module/web/templates/default/base.html3
-rw-r--r--module/web/templates/default/home.html18
-rwxr-xr-xpyLoadCore.py3
11 files changed, 101 insertions, 61 deletions
diff --git a/module/config/core_default.xml b/module/config/core_default.xml
index 0d684890a..4142efd2f 100644
--- a/module/config/core_default.xml
+++ b/module/config/core_default.xml
@@ -13,6 +13,7 @@
</ssl>
<webinterface name="Webinterface">
<activated type="bool" name="Activated">True</activated>
+ <lighttpd type="bool" name="Use Lighttpd">False</lighttpd>
<host type="ip" name="IP">0.0.0.0</host>
<port type="int" name="Port">8001</port>
<template type="str" name="Template">default</template>
diff --git a/module/file_list.py b/module/file_list.py
index 2cdda99c4..01a5924b3 100644
--- a/module/file_list.py
+++ b/module/file_list.py
@@ -126,10 +126,7 @@ class File_List(object):
def getAllFiles(self):
- files = []
- for pypack in self.data["queue"] + self.data["packages"]:
- files += pypack.files
- return files
+ return map(attrgetter("files"), self.data["queue"] + self.data["packages"])
def countDownloads(self):
""" simply return len of all files in all packages(which have no type) in queue and collector"""
diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py
index 712cd4304..7efcc0b75 100644
--- a/module/web/ServerThread.py
+++ b/module/web/ServerThread.py
@@ -1,9 +1,7 @@
#!/usr/bin/env python
from __future__ import with_statement
-import os
from os.path import exists
from os.path import join
-from signal import SIGINT
from subprocess import PIPE
from subprocess import Popen
from subprocess import call
@@ -41,7 +39,7 @@ class WebServer(threading.Thread):
except Exception:
self.lighttpd = False
- if self.lighttpd:
+ if self.lighttpd and self.pycore.config['webinterface']['lighttpd']:
self.pycore.logger.info("Starting lighttpd Webserver: %s:%s" % (host, port))
config = file(join(path, "lighttpd", "lighttpd_default.conf"), "rb")
content = config.readlines()
@@ -52,7 +50,7 @@ class WebServer(threading.Thread):
content = content.replace("%(host)", host)
content = content.replace("%(port)", port)
content = content.replace("%(media)", join(path, "media"))
- content = content.replace("%(version)", ".".join(map(str,version_info[0:2])))
+ content = content.replace("%(version)", ".".join(map(str, version_info[0:2])))
new_config = file(join(path, "lighttpd", "lighttpd.conf"), "wb")
new_config.write(content)
@@ -67,20 +65,23 @@ class WebServer(threading.Thread):
else:
self.pycore.logger.info("Starting django builtin Webserver: %s:%s" % (host, port))
-
+
command = ['python', join(self.pycore.path, "module", "web", "run_server.py"), "%s:%s" % (host, port)]
self.p = Popen(command, stderr=PIPE, stdin=PIPE, stdout=PIPE)
- while self.running:
- sleep(1)
+
def quit(self):
- if self.lighttpd:
- self.p.kill()
- self.p2.kill()
- return True
+ try:
+ if self.lighttpd:
+ self.p.kill()
+ self.p2.kill()
+ return True
+
+ else:
+ self.p.kill()
+ except:
+ pass
- else:
- self.p.kill()
self.running = False
diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py
index a4bfb5573..4265e8081 100644
--- a/module/web/ajax/views.py
+++ b/module/web/ajax/views.py
@@ -1,5 +1,7 @@
+
# Create your views here.
from os.path import join
+import time
from django.conf import settings
from django.core.serializers import json
@@ -7,7 +9,16 @@ from django.http import HttpResponse
from django.http import HttpResponseForbidden
from django.http import HttpResponseServerError
from django.utils import simplejson
-
+from django.utils.translation import ugettext as _
+
+def format_time(seconds):
+ seconds = int(seconds)
+
+ hours, seconds = divmod(seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
+
+
def permission(perm):
def _dec(view_func):
def _view(request, * args, ** kwargs):
@@ -41,7 +52,7 @@ def add_package(request):
queue = int(request.POST['add_dest'])
- links = request.POST['add_links'].replace(" ","\n").split("\n")
+ links = request.POST['add_links'].replace(" ", "\n").split("\n")
try:
f = request.FILES['add_file']
@@ -67,7 +78,7 @@ def add_package(request):
return JsonResponse("success")
-@permission('pyload.can_add_dl')
+@permission('pyload.can_add')
def remove_link(request, id):
try:
settings.PYLOAD.del_links([int(id)])
@@ -86,12 +97,27 @@ def status(request):
def links(request):
try:
links = settings.PYLOAD.status_downloads()
- ids = map(lambda x: x['id'], links)
+ ids = []
+ for link in links:
+ ids.append(link['id'])
+ print link['status']
+ if link['status'] == 'downloading':
+ link['info'] = "%s @ %s kb/s" % (format_time(link['eta']), round(link['speed'], 2))
+ elif link['status'] == 'waiting':
+ link['percent'] = 0
+ link['size'] = 0
+ link['kbleft'] = 0
+ link['info'] = _("waiting %s") % format_time(link['wait_until'] - time.time())
+ else:
+ link['info'] = ""
+
+
data = {}
data['links'] = links
data['ids'] = ids
return JsonResponse(data)
- except:
+ except Exception, e:
+ print e
return HttpResponseServerError()
@permission('pyload.can_see_dl')
diff --git a/module/web/lighttpd/lighttpd_default.conf b/module/web/lighttpd/lighttpd_default.conf
index fb971ffbe..55272ce0a 100644
--- a/module/web/lighttpd/lighttpd_default.conf
+++ b/module/web/lighttpd/lighttpd_default.conf
@@ -37,7 +37,7 @@ server.modules = (
## A static document-root. For virtual hosting take a look at the
## mod_simple_vhost module.
-server.document-root = "/srv/http/"
+server.document-root = "%(path)"
## where to send error-messages to
server.errorlog = "%(path)/error.log"
diff --git a/module/web/media/default/css/default.css b/module/web/media/default/css/default.css
index 3c4762012..986e9a4bc 100644
--- a/module/web/media/default/css/default.css
+++ b/module/web/media/default/css/default.css
@@ -1005,6 +1005,9 @@ a.backlink {
a.play {
background:transparent url(/media/default/img/control_play.png) 0px 1px no-repeat;
}
+a.time {
+ background:transparent url(/media/default/img/status_None.png) 0px 1px no-repeat;
+}
a.play:hover {
background:transparent url(/media/default/img/control_play_blue.png) 0px 1px no-repeat;
}
diff --git a/module/web/media/default/js/funktions.js b/module/web/media/default/js/funktions.js
index 9ca165b36..4c42ee336 100644
--- a/module/web/media/default/js/funktions.js
+++ b/module/web/media/default/js/funktions.js
@@ -12,7 +12,7 @@ function HumanFileSize(size)
var loga = Math.log(size)/Math.log(1024);
var i = Math.floor(loga);
var a = Math.pow(1024, i);
- return Math.round( size / a , 2) + " " + filesizename[i];
+ return (size == 0) ? "0 KB" : (Math.round( size / a , 2) + " " + filesizename[i]);
}
Array.prototype.remove = function(from, to) {
diff --git a/module/web/run_server.py b/module/web/run_server.py
index 3bb9b13f7..5ffa45781 100755
--- a/module/web/run_server.py
+++ b/module/web/run_server.py
@@ -1,20 +1,32 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from django.core.management.base import BaseCommand, CommandError
import os
import sys
os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
-def handle( *args ):
+class Output:
+ def __init__(self, stream):
+ self.stream = stream
+ def write(self, data): # Do nothing
+ return None
+ #self.stream.write(data)
+ #self.stream.flush()
+ def __getattr__(self, attr):
+ return getattr(self.stream, attr)
+
+sys.stderr = Output(sys.stderr)
+#sys.stdout = Output(sys.stdout)
+
+def handle(* args):
import django
from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler
-
+
try:
if len(args) == 1:
try:
- addr,port = args[0].split(":")
+ addr, port = args[0].split(":")
except:
addr = "127.0.0.1"
port = args[0]
@@ -28,7 +40,7 @@ def handle( *args ):
print addr, port
admin_media_path = ''
- shutdown_message = ''
+ shutdown_message = ''
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
from django.conf import settings
@@ -41,26 +53,28 @@ def handle( *args ):
translation.activate(settings.LANGUAGE_CODE)
try:
- handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
- run(addr, int(port), handler)
+ handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
+ run(addr, int(port), handler)
+
except WSGIServerException, e:
- # Use helpful error messages instead of ugly tracebacks.
- ERRORS = {
- 13: "You don't have permission to access that port.",
- 98: "That port is already in use.",
- 99: "That IP address can't be assigned-to.",
- }
- try:
- error_text = ERRORS[e.args[0].args[0]]
- except (AttributeError, KeyError):
- error_text = str(e)
- sys.stderr.write(("Error: %s" % error_text) + '\n')
- # Need to use an OS exit because sys.exit doesn't work in a thread
- os._exit(1)
+ # Use helpful error messages instead of ugly tracebacks.
+ ERRORS = {
+ 13: "You don't have permission to access that port.",
+ 98: "That port is already in use.",
+ 99: "That IP address can't be assigned-to.",
+ }
+ try:
+ error_text = ERRORS[e.args[0].args[0]]
+ except (AttributeError, KeyError):
+ error_text = str(e)
+ sys.stderr.write(("Error: %s" % error_text) + '\n')
+ # Need to use an OS exit because sys.exit doesn't work in a thread
+ #os._exit(1)
except KeyboardInterrupt:
- if shutdown_message:
- print shutdown_message
- sys.exit(0)
+ if shutdown_message:
+ print shutdown_message
+ sys.exit(0)
+
if __name__ == "__main__":
- handle(*sys.argv[1:])
+ handle(*sys.argv[1:])
diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html
index 5771e64e5..82581da45 100644
--- a/module/web/templates/default/base.html
+++ b/module/web/templates/default/base.html
@@ -180,7 +180,8 @@ function AddBox()
{% if perms.pyload.can_see_dl %}
<ul id="page-actions">
- <li><a class="action backlink">{% trans "Speed:" %} <b id="speed">{{ status.speed }}</b> kb/s</a></li>
+ <li><a class="time">{% trans "Download:" %}<a style=" background-color: #7CFC00; padding-left: 0cm; padding-right: 0.1cm; "> {% trans "on" %}</a></a></li>
+ <li><a class="action backlink">{% trans "Speed:" %} <b id="speed">{{ status.speed }}</b> kb/s</a></li>
<li><a class="action cog">{% trans "Active:" %} <b id="aktiv">{{ status.activ }}</b> / <b id="aktiv_from">{{ status.queue }}</b></a></li>
<li><a href="" class="action revisions" accesskey="o" rel="nofollow">{% trans "Reload page" %}</a></li>
</ul><br />
diff --git a/module/web/templates/default/home.html b/module/web/templates/default/home.html
index 08a7a85e6..f3d40b4e0 100644
--- a/module/web/templates/default/home.html
+++ b/module/web/templates/default/home.html
@@ -5,11 +5,6 @@
<script type="text/javascript">
-/*function UpdateLinks( SetInver, index )
-{
- $("#aktiv_percent").text(parseInt($("#aktiv_percent").text)+1)
- setTimeout( UpdateLinks( SetInver, index+1 ), SetInver[index]*1000);
-}*/
var em;
document.addEvent("domready", function(){
@@ -83,7 +78,7 @@ var EntryManager = new Class({
}
}, this)
- }catch(e){alert(e)}
+ }catch(e){}
}
})
@@ -108,8 +103,7 @@ var LinkEntry = new Class({
},
insert: function(item){
try{
- info = SecToRightTime(item.eta) +' @ '+ Math.round(item.speed*100)/100+' kb/s' ;
-
+
this.elements = {
tr: new Element('tr', {
'html': '',
@@ -124,7 +118,7 @@ var LinkEntry = new Class({
'html': item.status
}),
info: new Element('td', {
- 'html': info
+ 'html': item.info
}),
kbleft: new Element('td', {
'html': HumanFileSize(item.size)
@@ -176,7 +170,7 @@ var LinkEntry = new Class({
update: function(item){
this.elements.name.set('text', item.name);
this.elements.status.set('text', item.status);
- this.elements.info.set('text', SecToRightTime(item.eta)+' @ '+Math.round(item.speed*100)/100+' kb/s');
+ this.elements.info.set('text', item.info);
this.elements.kbleft.set('text', HumanFileSize(item.size));
this.elements.percent.set('text', item.percent+ '% / '+ HumanFileSize(item.size-item.kbleft));
this.bar.start({
@@ -204,7 +198,7 @@ var LinkEntry = new Class({
<tr class="header">
<th>{% trans "Name" %}</th>
<th>{% trans "Status" %}</th>
- <th>{% trans "Infos" %}</th>
+ <th>{% trans "Information" %}</th>
<th>{% trans "Size" %}</th>
<th>{% trans "Progress" %}</th>
</tr>
@@ -229,6 +223,6 @@ var LinkEntry = new Class({
</tr>
{% endfor %}
- <tbody>
+ </tbody>
</table>
{% endblock %} \ No newline at end of file
diff --git a/pyLoadCore.py b/pyLoadCore.py
index 0c144b3a6..0459751cf 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -443,6 +443,9 @@ class ServerMethods():
for pyfile in self.core.thread_list.py_downloading:
status['speed'] += pyfile.status.get_speed()
+ status['download'] = self.core.thread_list.pause and self.is_time_download()
+ status['reconnect'] = self.core.config['reconnect']['activated'] and self.is_time_reconnect()
+
return status
def file_exists(self, path): #@XXX: security?!