lisencing

This commit is contained in:
Martijn Voncken 2008-11-25 17:58:52 +00:00
parent 207005e355
commit 03e3ccc3a5
10 changed files with 114 additions and 320 deletions

View file

@ -4,6 +4,7 @@
# webserver_framework.py
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
# Copyright (C) Damien Churchill 2008 <damoxc@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View file

@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
#
# FilteredForm contains code copied from django newforms :
# Copyright (c) 2005, the Lawrence Journal-World
#
# Django Licence, see ./newforms_portable/LICENCE
#

View file

@ -1,3 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
"""
decorators for html-pages.
"""

View file

@ -1,5 +1,25 @@
#!/usr/bin/env python
#only for development/debugging.
# -*- coding: utf-8 -*-
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
import deluge_webserver
deluge_webserver.run(debug = True)

View file

@ -1,10 +0,0 @@
#!/bin/bash
pwd=deluge
url=http://localhost:8112
for arg in "$@"
do
curl -F torrent=@"$arg" -F pwd=$pwd $url/remote/torrent/add
done

View file

@ -1,207 +0,0 @@
// ==UserScript==
// @name Add Torrents To Deluge
// @namespace http://blog.monstuff.com/archives/cat_greasemonkey.html
// @description Let's you add torrents to the deluge WebUi
// @include http://isohunt.com/torrent_details/*
// @include http://thepiratebay.org/details.php?*
// @include http://torrentreactor.net/view.php?*
// @include http://www.mininova.org/*
// @include http://www.torrentspy.com/*
// @include http://ts.searching.com/*
// @include *
// ==/UserScript==
//url-based submit and parsing based on : "Add Torrents To utorrent" by Julien Couvreur
//binary magic,contains from http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
//these parameters need to be edited before using the script
// Server address
var host = "localhost";
// Server port
var port = "8112";
//open_page: "_blank" for a new window or "deluge_webui" for window re-use
//(not for private=1)
var open_page = "_blank"
//Private-trackers 0/1
//different behavior, gets torrent-data from (private) site and pops up a message.
var private_submit = 1;
//deluge_password, only needed if private_submit = 1.
var deluge_password = 'deluge';
//========================
if (host == "") { alert('You need to configure the "Add Torrents To Deluge" user script with your WebUI parameters before using it.'); }
function scanLinks() {
var links = getLinks();
for (var i=0; i < links.length; i++){
var link = links[i];
if (match(link.href)) {
if (private_submit) {
makeUTorrentLink_private(link,i);
}
else {
makeUTorrentLink(link);
}
}
}
}
function makeUTorrentLink(link) {
var uTorrentLink = document.createElement('a');
uTorrentLink.setAttribute("href", makeUTorrentUrl(link.href));
uTorrentLink.setAttribute("target", open_page);
uTorrentLink.style.paddingLeft = "5px";
uTorrentLink.innerHTML = "<img src=\"" + image + "\" style='border: 0px' />";
link.parentNode.insertBefore(uTorrentLink, link.nextSibling);
return uTorrentLink
}
function makeUTorrentUrl(url) {
var uTorrentUrl = "http://"+host+":"+port+"/torrent/add?redir_after_login=1";
return uTorrentUrl + "&url=" + escape(url);
}
function makeUTorrentLink_private(link,i) {
var id = 'deluge_link' + i;
var uTorrentLink = document.createElement('a');
uTorrentLink.setAttribute("href", '#');
uTorrentLink.setAttribute("id", id);
uTorrentLink.style.paddingLeft = "5px";
uTorrentLink.innerHTML = "<img src=\"" + image + "\" style='border: 0px' />";
link.parentNode.insertBefore(uTorrentLink, link.nextSibling);
ulink = document.getElementById(id)
ulink.addEventListener("click", evt_private_submit_factory(link.href),false);
return uTorrentLink
}
function evt_private_submit_factory(url) {
//can this be done without magic?
function evt_private_submit(evt) {
GM_xmlhttpRequest({ method: 'GET', url: url,
overrideMimeType: 'text/plain; charset=x-user-defined',
onload: function(xhr) {
var stream = translateToBinaryString(xhr.responseText);
var data_b64 = window.btoa(stream);
post_to_webui(url, data_b64);
},
onerror:function(xhr) {
alert('error fetching torrent file');
}
});
return false;
}
return evt_private_submit;
}
function post_to_webui(url,data_b64){
//alert('here1');
//data contains the content of the .torrent-file.
var POST_data = ('pwd=' + encodeURIComponent(deluge_password) +
'&torrent_name=' + encodeURIComponent(url) + '.torrent' + //+.torrent is a clutch!
'&data_b64=' + encodeURIComponent(data_b64) );
//alert(POST_data);
GM_xmlhttpRequest({ method: 'POST',
url: "http://"+host+":"+port+"/remote/torrent/add",
headers:{'Content-type':'application/x-www-form-urlencoded'},
data: POST_data,
onload: function(xhr) {
if (xhr.responseText == 'ok\n') {
alert('Added torrent to webui : \n' + url);
}
else {
alert('Error adding torrent to webui:\n"' + xhr.responseText + '"');
}
},
onerror:function(xhr) {
alert('error submitting torrent file');
}
});
}
function match(url) {
// isohunt format
if (url.match(/http:\/\/.*isohunt\.com\/download\//i)) {
return true;
}
if (url.match(/\.torrent$/)) {
return true;
}
if (url.match(/http:\/\/.*bt-chat\.com\/download\.php/)) {
return true;
}
// TorrentReactor
if (url.match(/http:\/\/dl\.torrentreactor\.net\/download.php\?/i)) {
return true;
}
// Mininova
if (url.match(/http:\/\/www\.mininova\.org\/get\//i)) {
return true;
}
// Mininova
if (url.match(/http:\/\/www\.mininova\.org\/get\//i)) {
return true;
}
// TorrentSpy
if (url.match(/http:\/\/ts\.searching\.com\/download\.asp\?/i)) {
return true;
}
if (url.match(/http:\/\/www\.torrentspy\.com\/download.asp\?/i)) {
return true;
}
// Seedler
if (url.match(/http:\/\/.*seedler\.org\/download\.x\?/i)) {
return true;
}
return false;
}
function getLinks() {
var doc_links = document.links;
var links = new Array();
for (var i=0; i < doc_links.length; i++){
links.push(doc_links[i]);
}
return links;
}
var image = "data:image/gif;base64,R0lGODlhEAAQAMZyAB1CdihAYx5CdiBEeCJGeSZJfChKfChLfSpPgTBRgThRdDRUgzRVhDVWhDZWhThYhjtbiD1ciD5diT5eiz9eikBeiUFeiT5fjT1gjkBfjERijkdjiUhljkVnlEdolUxokExqkk5qkU9rklBrklFtk1BullFulk5vmlZymFx3nE97rVZ5pUx8sl54nlt5oVl6pE5/tWJ6nVp9qFqArWOEq1uIuW6EpGCItl2Ku26Gp2KKuGuIrF+MvWaLtl+Nv3KJqG+KrGaOu2aQv2SRwnGOs2uQvGqSwICOpoCQqm6Ww3OVvHKWv3iWuoKWsn+XtnacxXaeynifyXigzICewn2gxnqizoqfunujzpWesX6l0IyivYijw4+jvpOiuoOp0puktY2x2I6y2Y+z2pG02pW43Ze42pa43Z/A4qjG56jH56nI6KzJ6a/M67nR67zW8sLa9cff+M/k+P///////////////////////////////////////////////////////yH+FUNyZWF0ZWQgd2l0aCBUaGUgR0lNUAAh+QQBCgB/ACwAAAAAEAAQAAAHkIB/goOEhYaCX1iHhkdIXU2LgzFARExbkYInCBcvRVSRHgQNEiYoPUmHGAkjO1FSSilBNYYQFTllY2BeSzJChg4iWmhpZ2JXOjgqhBMFH1xvbmtmWUMwM4QZBws/cXBsZFU+LCuFDwIhVm1qYVA8Nx2FEQQDHDZOU09GNIcWDAAGFEC0cBEpwAYNJUgowMQwEAA7";
scanLinks();
/*
binary magic,contains code taken from
http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
*/
function translateToBinaryString(text){
var out;
out='';
for(i=0;i<text.length;i++){
//*bugfix* by Marcus Granado 2006 [http://mgran.blogspot.com] adapted by Thomas Belot
out+=String.fromCharCode(text.charCodeAt(i) & 0xff);
}
return out;
}

View file

@ -1,3 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
import os
import re
template_dirs = ['../templates/ajax/static/js']

View file

@ -1,3 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
import os
import re
template_dirs = ['../templates/classic','../templates/white','../templates/ajax/static/js']

View file

@ -1,102 +0,0 @@
"""
test multicall.
"""
import time
from WebUi.webserver_common import ws, proxy, async_proxy
ws.init_06()
TORRENT_KEYS = ['name', 'total_size', 'num_files', 'num_pieces', 'piece_length',
'eta', 'ratio', 'file_progress', 'distributed_copies', 'total_done',
'total_uploaded', 'state', 'paused', 'progress', 'next_announce',
'total_payload_download', 'total_payload_upload', 'download_payload_rate',
'upload_payload_rate', 'num_peers', 'num_seeds', 'total_peers', 'total_seeds',
'total_wanted', 'tracker', 'trackers', 'tracker_status', 'save_path',
'files', 'file_priorities', 'compact', 'max_connections',
'max_upload_slots', 'max_download_speed', 'prioritize_first_last', 'private'
]
if False:
#
#A: translate this into 1 multicall:
start = time.time()
stats = {
'download_rate':proxy.get_download_rate(),
'upload_rate':proxy.get_upload_rate(),
'max_download':proxy.get_config_value('max_download_speed'),
'max_upload':proxy.get_config_value('max_upload_speed'),
'num_connections':proxy.get_num_connections(),
'max_num_connections':proxy.get_config_value('max_connections_global')
}
print "sync-stats:",time.time() - start
print stats
#
#map callback to a a dict-setter
def dict_cb(key,d):
def callback(result):
d[key] = result
return callback
start = time.time()
d = {}
async_proxy.get_download_rate(dict_cb('download_rate',d))
async_proxy.get_upload_rate(dict_cb('upload_rate',d))
async_proxy.get_config_value(dict_cb('max_download',d),"max_download_speed")
async_proxy.get_config_value(dict_cb('max_upload',d),"max_upload_speed")
async_proxy.get_num_connections(dict_cb("num_connections",d))
async_proxy.get_config_value(dict_cb('max_num_connections',d),"max_connections_global")
async_proxy.force_call(block=True)
print "Async-stats:",time.time() - start
print d
#
#B: translate this to multicall:
#
#old-sync:
start = time.time()
torrent_list = [proxy.get_torrent_status(id, TORRENT_KEYS )
for id in proxy.get_session_state()
]
print "sync-list:",time.time() - start
print torrent_list[0]
#new async:
"""
torrent.compact,
torrent.max_connections,
torrent.max_upload_slots,
torrent.max_upload_speed,
torrent.max_download_speed,
torrent.prioritize_first_last,
torrent.private
"""
start = time.time()
torrent_ids = proxy.get_session_state() #Syc-api.
torrent_dict = {}
for id in torrent_ids:
async_proxy.get_torrent_status(dict_cb(id,torrent_dict), id, TORRENT_KEYS )
async_proxy.force_call(block=True)
print "Async-list:",time.time() - start
print "\n".join(torrent_dict[torrent_ids[0]].keys())
print torrent_dict[torrent_ids[0]]
if False:
print proxy.get_config_value('download_location')
if True:
torrent_id = proxy.get_session_state()[0]
print torrent_id
proxy.move_torrent([torrent_id],"/media/sdb1/test")

View file

@ -1,3 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
"""
Testing the REST api, not the units.
unittest the right way feels so unpythonic :(