summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-01-08 00:15:04 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-01-08 00:15:04 +0100
commit4bbb75de3ee0b0f02408f8c39d82004b7209ea7e (patch)
treee61aede937e5f0011a8432a99ec90098e9bf0251
parentnew l18n files (diff)
downloadpyload-4bbb75de3ee0b0f02408f8c39d82004b7209ea7e.tar.xz
new buttons to (remove finished/restart failed) links
-rw-r--r--module/FileDatabase.py43
-rw-r--r--module/web/ajax/urls.py2
-rw-r--r--module/web/ajax/views.py9
-rw-r--r--module/web/media/default/css/default.css9
-rw-r--r--module/web/templates/default/base.html6
-rw-r--r--module/web/templates/default/collector.html7
-rw-r--r--module/web/templates/default/package_ui.js156
-rw-r--r--module/web/templates/default/queue.html6
-rwxr-xr-xpyLoadCore.py11
9 files changed, 184 insertions, 65 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py
index 818c6ed07..631269030 100644
--- a/module/FileDatabase.py
+++ b/module/FileDatabase.py
@@ -165,6 +165,7 @@ class FileHandler:
p = self.getPackage(id)
if not p:
+ if self.packageCache.has_key(id): del self.packageCache[id]
return
e = RemoveEvent("pack", id, "collector" if not p.queue else "queue")
@@ -208,7 +209,7 @@ class FileHandler:
self.core.pullManager.addEvent(e)
p = self.getPackage(pid)
- if len(p.getChildren()) == 0:
+ if not len(p.getChildren()):
p.delete()
#----------------------------------------------------------------------
@@ -507,6 +508,34 @@ class FileHandler:
self.core.threadManager.createInfoThread(urls, pid)
+ @lock
+ @change
+ def deleteFinishedLinks(self):
+ """ deletes finished links and packages, return deleted packages """
+
+ old_packs = self.getInfoData(0)
+ old_packs.update(self.getInfoData(1))
+
+ self.db.deleteFinished()
+
+ new_packs = self.db.getAllPackages(0)
+ new_packs.update(self.db.getAllPackages(1))
+ #get new packages only from db
+
+ deleted = []
+ for id in old_packs.iterkeys():
+ if not new_packs.has_key(str(id)):
+ deleted.append(id)
+ self.deletePackage(int(id))
+
+ return deleted
+
+ @lock
+ @change
+ def restartFailed(self):
+ """ restart all failed links """
+ self.db.restartFailed()
+
#########################################################################
class FileDatabaseBackend(Thread):
"""underlying backend for the filehandler to save the data"""
@@ -879,7 +908,7 @@ class FileDatabaseBackend(Thread):
cmd = "("
for i, item in enumerate(occ):
- if i != 0: cmd += ", "
+ if i: cmd += ", "
cmd += "'%s'" % item
cmd += ")"
@@ -906,6 +935,16 @@ class FileDatabaseBackend(Thread):
self.c.execute("SELECT id FROM links WHERE package=? AND status NOT IN (0, 13) LIMIT 3", (str(pid),))
return [r[0] for r in self.c]
+ @queue
+ def deleteFinished(self):
+ self.c.execute("DELETE FROM links WHERE status=0")
+ self.c.execute("DELETE FROM packages WHERE NOT EXISTS(SELECT 1 FROM links WHERE packages.id=links.package)")
+
+
+ @queue
+ def restartFailed(self):
+ self.c.execute("UPDATE links SET status=3,error='' WHERE status IN (8, 9)")
+
if __name__ == "__main__":
pypath = "."
diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py
index f661b2b6a..ebbf401af 100644
--- a/module/web/ajax/urls.py
+++ b/module/web/ajax/urls.py
@@ -31,4 +31,6 @@ urlpatterns = patterns('ajax',
(r'^package_order/([0-9|]+)$', 'views.package_order'),
(r'^link_order/([0-9|]+)$', 'views.link_order'),
(r'edit_package$', 'views.edit_package'),
+ (r'restart_failed$', 'views.restart_failed'),
+ (r'delete_finished$', 'views.delete_finished'),
) \ No newline at end of file
diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py
index f90052b62..acceac585 100644
--- a/module/web/ajax/views.py
+++ b/module/web/ajax/views.py
@@ -310,3 +310,12 @@ def set_captcha(request):
return JsonResponse({'captcha': True, 'src': src, 'id': id})
else:
return JsonResponse({'captcha': False})
+
+
+@permission('pyload.can_delete')
+def delete_finished(request):
+ return JsonResponse({"del":settings.PYLOAD.delete_finished()})
+
+@permission('pyload.can_delete')
+def restart_failed(request):
+ return JsonResponse(settings.PYLOAD.restart_failed()) \ No newline at end of file
diff --git a/module/web/media/default/css/default.css b/module/web/media/default/css/default.css
index 8ca554e9b..b73ec2278 100644
--- a/module/web/media/default/css/default.css
+++ b/module/web/media/default/css/default.css
@@ -165,7 +165,7 @@ h5 {
h6 {
font-size:80%;
}
-ul#page-actions {
+ul#page-actions, ul#page-actions-more {
float:right;
margin:10px 10px 0 10px;
padding:6px;
@@ -186,10 +186,10 @@ ul#user-actions {
-moz-border-radius:3px;
border-radius:3px;
}
-ul#page-actions li, ul#user-actions li {
+ul#page-actions li, ul#user-actions li, ul#page-actions-more li {
display:inline;
}
-ul#page-actions a, ul#user-actions a {
+ul#page-actions a, ul#user-actions a, ul#page-actions-more a {
text-decoration:none;
color:black;
display:inline;
@@ -230,7 +230,8 @@ ul#page-actions2 a, ul#user-actions2 a {
margin:0 3px;
padding:2px 0px 2px 18px;
}
-ul#page-actions2 a:hover, ul#page-actions2 a:focus, ul#user-actions2 a:hover, ul#user-actions2 a:focus {
+ul#page-actions2 a:hover, ul#page-actions2 a:focus, ul#user-actions2 a:hover, ul#user-actions2 a:focus,
+ul#page-actions-more a:hover, ul#page-actions-more a:focus{
color: #4e7bb4;
}
/****************************/
diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html
index 9b9622a12..94fcd4291 100644
--- a/module/web/templates/default/base.html
+++ b/module/web/templates/default/base.html
@@ -273,9 +273,13 @@ function AddBox()
<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 />
+</ul>
{% endif %}
+{% block pageactions %}
+{% endblock %}
+<br/>
+
<div id="body-wrapper" class="dokuwiki">
<div id="content" lang="en" dir="ltr">
diff --git a/module/web/templates/default/collector.html b/module/web/templates/default/collector.html
index 1a7a4aa0c..c0ac78202 100644
--- a/module/web/templates/default/collector.html
+++ b/module/web/templates/default/collector.html
@@ -36,6 +36,13 @@ document.addEvent("domready", function(){
<a href="/settings/" class="action index" accesskey="x" rel="nofollow"><img src="{{ MEDIA_URL }}img/head-menu-config.png" alt="" />{% trans "Config" %}</a>
</li>{% endblock %}
+{% block pageactions %}
+<ul id="page-actions-more">
+ <li id="del-finished"><a style="padding: 0; font-weight: bold;" href="#">{% trans "Delete Finished" %}</a></li>
+ <li id="restart-failed"><a style="padding: 0; font-weight: bold;" href="#">{% trans "Restart Failed" %}</a></li>
+</ul>
+{% endblock %}
+
{% block content %}
<div id="load-success" style="opacity: 0; float: right; color: white; background-color: #90ee90; padding: 4px; -moz-border-radius: 5px; border-radius: 5px; font-weight: bold; margin-left: -100%; margin-top: -10px;">{% trans "success" %}</div>
<div id="load-failure" style="opacity: 0; float: right; color: white; background-color: #f08080; padding: 4px; -moz-border-radius: 5px; border-radius: 5px; font-weight: bold; margin-left: -100%; margin-top: -10px;">{% trans "failure" %}</div>
diff --git a/module/web/templates/default/package_ui.js b/module/web/templates/default/package_ui.js
index 75e6ef234..eec645184 100644
--- a/module/web/templates/default/package_ui.js
+++ b/module/web/templates/default/package_ui.js
@@ -1,17 +1,17 @@
//{% load i18n %}
var load, success, fail, pack_box;
-document.addEvent("domready", function(){
+document.addEvent("domready", function() {
load = new Fx.Tween($("load-indicator"), {link: "cancel"});
success = new Fx.Tween($("load-success"), {link: "chain"});
fail = new Fx.Tween($("load-failure"), {link: "chain"});
- [load,success,fail].each(function(fx){
+ [load,success,fail].each(function(fx) {
fx.set("opacity", 0)
});
pack_box = new Fx.Tween($('pack_box'));
- $('pack_reset').addEvent('click', function(){
+ $('pack_reset').addEvent('click', function() {
hide_pack()
});
});
@@ -25,34 +25,34 @@ function indicateFinish() {
load.start("opacity", 0)
}
-function indicateSuccess(){
+function indicateSuccess() {
indicateFinish();
- success.start("opacity", 1).chain(function(){
- (function(){
+ success.start("opacity", 1).chain(function() {
+ (function() {
success.start("opacity", 0);
}).delay(250);
});
}
-function indicateFail(){
+function indicateFail() {
indicateFinish();
- fail.start("opacity", 1).chain(function(){
- (function(){
+ fail.start("opacity", 1).chain(function() {
+ (function() {
fail.start("opacity", 0);
}).delay(250);
});
}
-function show_pack(){
+function show_pack() {
bg_show();
$("pack_box").setStyle('display', 'block');
- pack_box.start('opacity',1)
+ pack_box.start('opacity', 1)
}
-function hide_pack(){
+function hide_pack() {
bg_hide();
- pack_box.start('opacity',0).chain(function(){
+ pack_box.start('opacity', 0).chain(function() {
$('pack_box').setStyle('display', 'none');
});
}
@@ -73,6 +73,10 @@ var PackageUI = new Class({
//onStart: this.startSort,
onComplete: this.saveSort.bind(this)
});
+
+ $("del_finished").addEvent("click", this.deleteFinished.bind(this));
+ $("restart_failed").addEvent("click", this.restartFailed.bind(this));
+
},
parsePackages: function() {
@@ -83,7 +87,40 @@ var PackageUI = new Class({
},
loadPackages: function() {
+ },
+ deleteFinished: function() {
+ indicateLoad();
+ new Request.JSON({
+ method: 'get',
+ url: '/json/delete_finished',
+ onSuccess: function(data) {
+ if (data.del.length > 0) {
+ window.location.reload()
+ } else {
+ this.packages.each(function(pack) {
+ pack.close();
+ });
+ indicateSuccess();
+ }
+ }.bind(this),
+ onFailure: indicateFail
+ }).send();
+ },
+
+ restartFailed: function() {
+ indicateLoad();
+ new Request.JSON({
+ method: 'get',
+ url: '/json/restart_failed',
+ onSuccess: function(data) {
+ this.packages.each(function(pack) {
+ pack.close();
+ });
+ indicateSuccess();
+ }.bind(this),
+ onFailure: indicateFail
+ }).send();
},
startSort: function(ele, copy) {
@@ -91,13 +128,13 @@ var PackageUI = new Class({
saveSort: function(ele, copy) {
var order = [];
- this.sorts.serialize(function(li,pos){
- if (li == ele && ele.retrieve("order") != pos){
- order.push(ele.retrieve("pid")+"|"+pos)
+ this.sorts.serialize(function(li, pos) {
+ if (li == ele && ele.retrieve("order") != pos) {
+ order.push(ele.retrieve("pid") + "|" + pos)
}
li.store("order", pos)
});
- if (order.length > 0){
+ if (order.length > 0) {
indicateLoad();
new Request.JSON({
method: 'get',
@@ -126,15 +163,15 @@ var Package = new Class({
this.parseElement();
}
- var pname = this.ele.getElements(".packagename")[0];
+ var pname = this.ele.getElements(".packagename")[0];
this.buttons = new Fx.Tween(this.ele.getElements(".buttons")[0], {link: "cancel"});
this.buttons.set("opacity", 0);
- pname.addEvent("mouseenter", function(e){
+ pname.addEvent("mouseenter", function(e) {
this.buttons.start("opacity", 1)
}.bind(this));
- pname.addEvent("mouseleave", function(e){
+ pname.addEvent("mouseleave", function(e) {
this.buttons.start("opacity", 0)
}.bind(this));
@@ -178,8 +215,8 @@ var Package = new Class({
createLinks: function(data) {
var ul = $("sort_children_{id}".substitute({"id": this.id}));
ul.erase("html");
- data.links.each(function(link){
- var li = new Element("li",{
+ data.links.each(function(link) {
+ var li = new Element("li", {
"style": {
"margin-left": 0
}
@@ -193,8 +230,8 @@ var Package = new Class({
html += "<img title='{% trans "Delete Link" %}' style='cursor: pointer;' width='10px' height='10px' src='{{ MEDIA_URL }}img/delete.png' />&nbsp;&nbsp;";
html += "<img title='{% trans "Restart Link" %}' style='cursor: pointer;margin-left: -4px' width='10px' height='10px' src='{{ MEDIA_URL }}img/arrow_refresh.png' /></div>";
- var div = new Element("div",{
- "id": "file_"+link.id,
+ var div = new Element("div", {
+ "id": "file_" + link.id,
"class": "child",
"html": html
});
@@ -220,26 +257,26 @@ var Package = new Class({
},
registerLinkEvents: function() {
- this.ele.getElements('.child').each(function(child){
+ this.ele.getElements('.child').each(function(child) {
var lid = child.get('id').match(/[0-9]+/);
var imgs = child.getElements('.child_secrow img');
- imgs[0].addEvent('click', function(e){
+ imgs[0].addEvent('click', function(e) {
new Request({
method: 'get',
- url: '/json/remove_link/'+this,
- onSuccess: function(){
- $('file_'+this).nix()
+ url: '/json/remove_link/' + this,
+ onSuccess: function() {
+ $('file_' + this).nix()
}.bind(this),
onFailure: indicateFail
}).send();
}.bind(lid));
- imgs[1].addEvent('click', function(e){
+ imgs[1].addEvent('click', function(e) {
new Request({
method: 'get',
- url: '/json/restart_link/'+this,
- onSuccess: function(){
- var ele = $('file_'+this);
+ url: '/json/restart_link/' + this,
+ onSuccess: function() {
+ var ele = $('file_' + this);
var imgs = ele.getElements("img");
imgs[0].set("src", "/media/default/img/status_queue.png");
var spans = ele.getElements(".child_status");
@@ -269,8 +306,8 @@ var Package = new Class({
indicateLoad();
new Request({
method: 'get',
- url: '/json/remove_package/'+this.id,
- onSuccess: function(){
+ url: '/json/remove_package/' + this.id,
+ onSuccess: function() {
this.ele.nix();
indicateFinish();
}.bind(this),
@@ -283,16 +320,9 @@ var Package = new Class({
indicateLoad();
new Request({
method: 'get',
- url: '/json/restart_package/'+this.id,
- onSuccess: function(){
- var child = this.ele.getElement('.children');
- if (child.getStyle('display') == "block") {
- child.dissolve();
- }
- var ul = $("sort_children_{id}".substitute({"id": this.id}));
- ul.erase("html");
- this.linksLoaded = false;
-
+ url: '/json/restart_package/' + this.id,
+ onSuccess: function() {
+ this.close();
indicateSuccess();
}.bind(this),
onFailure: indicateFail
@@ -300,12 +330,22 @@ var Package = new Class({
event.stop();
},
- movePackage: function(event){
+ close: function() {
+ var child = this.ele.getElement('.children');
+ if (child.getStyle('display') == "block") {
+ child.dissolve();
+ }
+ var ul = $("sort_children_{id}".substitute({"id": this.id}));
+ ul.erase("html");
+ this.linksLoaded = false;
+ },
+
+ movePackage: function(event) {
indicateLoad();
new Request({
method: 'get',
- url: '/json/move_package/'+((this.ui.type +1) % 2) +"/"+ this.id,
- onSuccess: function(){
+ url: '/json/move_package/' + ((this.ui.type + 1) % 2) + "/" + this.id,
+ onSuccess: function() {
this.ele.nix();
indicateFinish();
}.bind(this),
@@ -314,7 +354,7 @@ var Package = new Class({
event.stop();
},
- editPackage: function(event){
+ editPackage: function(event) {
$("pack_form").removeEvents("submit");
$("pack_form").addEvent("submit", this.savePackage.bind(this));
@@ -324,10 +364,10 @@ var Package = new Class({
$("pack_pws").set("value", this.password.get("text"));
var prio = 3;
- $("pack_prio").getChildren("option").each(function(item, index){
- item.erase("selected");
- if (prio.toString() == this.prio.get("text")){
- item.set("selected","selected");
+ $("pack_prio").getChildren("option").each(function(item, index) {
+ item.erase("selected");
+ if (prio.toString() == this.prio.get("text")) {
+ item.set("selected", "selected");
}
prio--;
}.bind(this));
@@ -337,7 +377,7 @@ var Package = new Class({
event.stop();
},
- savePackage: function(event){
+ savePackage: function(event) {
$("pack_form").send();
this.name.set("text", $("pack_name").get("value"));
this.folder.set("text", $("pack_folder").get("value"));
@@ -349,13 +389,13 @@ var Package = new Class({
saveSort: function(ele, copy) {
var order = [];
- this.sorts.serialize(function(li,pos){
- if (li == ele && ele.retrieve("order") != pos){
- order.push(ele.retrieve("lid")+"|"+pos)
+ this.sorts.serialize(function(li, pos) {
+ if (li == ele && ele.retrieve("order") != pos) {
+ order.push(ele.retrieve("lid") + "|" + pos)
}
li.store("order", pos)
});
- if (order.length > 0){
+ if (order.length > 0) {
indicateLoad();
new Request.JSON({
method: 'get',
diff --git a/module/web/templates/default/queue.html b/module/web/templates/default/queue.html
index cd16cf1c4..ec11bc365 100644
--- a/module/web/templates/default/queue.html
+++ b/module/web/templates/default/queue.html
@@ -37,6 +37,12 @@ document.addEvent("domready", function(){
</li>
{% endblock %}
+{% block pageactions %}
+<ul id="page-actions-more">
+ <li id="del_finished"><a style="padding: 0; font-weight: bold;" href="#">{% trans "Delete Finished" %}</a></li>
+ <li id="restart_failed"><a style="padding: 0; font-weight: bold;" href="#">{% trans "Restart Failed" %}</a></li>
+</ul>
+{% endblock %}
{% block content %}
<div id="load-success" style="opacity: 0; float: right; color: white; background-color: #90ee90; padding: 4px; -moz-border-radius: 5px; border-radius: 5px; font-weight: bold; margin-left: -100%; margin-top: -10px;">{% trans "success" %}</div>
diff --git a/pyLoadCore.py b/pyLoadCore.py
index d1dffb6c7..259e2cd0c 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -373,6 +373,8 @@ class Core(object):
self.scheduler.addJob(0, self.accountManager.getAccountInfos)
+ self.server_methods.delete_finished()
+
while True:
sleep(2)
if self.do_restart:
@@ -865,6 +867,15 @@ class ServerMethods():
end = self.core.config['reconnect']['endTime'].split(":")
return self.core.compare_time(start, end)
+ def delete_finished(self):
+ """ delete all finished links + packages, returns deleted packages """
+ deleted = self.core.files.deleteFinishedLinks()
+ return deleted
+
+ def restart_failed(self):
+ """ restart all failed links """
+ self.core.files.restartFailed()
+
def deamon():
try:
pid = os.fork()