diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-12-10 15:44:37 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-12-10 15:44:37 +0100 |
commit | 2c7203032324820c122b1e7b77604212391f75f9 (patch) | |
tree | cc5e1b4802672a2927de922ccfe884dd93eb2e6c | |
parent | incomplete: gui model-view stuff (diff) | |
download | pyload-2c7203032324820c122b1e7b77604212391f75f9.tar.xz |
cleaned some code, pyLoad Script Support (closed #16)
-rw-r--r-- | config | 2 | ||||
-rw-r--r-- | module/captcha/LinksaveIn.py | 2 | ||||
-rw-r--r-- | module/network/Keepalive.py | 1 | ||||
-rw-r--r-- | module/plugins/HotfileCom.py | 1 | ||||
-rw-r--r-- | module/plugins/LinkList.py | 1 | ||||
-rw-r--r-- | module/plugins/RapidshareCom.py | 1 | ||||
-rw-r--r-- | module/thread_list.py | 26 | ||||
-rw-r--r-- | module/web/WebServer.py | 1 | ||||
-rwxr-xr-x | pyLoadCli.py | 5 | ||||
-rwxr-xr-x | pyLoadCore.py | 61 | ||||
-rw-r--r-- | scripts/Readme.txt | 23 |
11 files changed, 86 insertions, 38 deletions
@@ -5,7 +5,7 @@ username = admin password = pwhere [ssl] -activated = True +activated = False cert = ssl.crt key = ssl.key diff --git a/module/captcha/LinksaveIn.py b/module/captcha/LinksaveIn.py index 15ccdb1ac..d6f61e362 100644 --- a/module/captcha/LinksaveIn.py +++ b/module/captcha/LinksaveIn.py @@ -6,7 +6,6 @@ from os.path import abspath from glob import glob import tempfile -from pprint import pprint class LinksaveIn(OCR): def __init__(self): @@ -144,7 +143,6 @@ class LinksaveIn(OCR): self.clean(4) self.image.save(self.data_dir+"cleaned_pass2.png") letters = self.split_captcha_letters() - org = self.image final = "" for n, letter in enumerate(letters): self.image = letter diff --git a/module/network/Keepalive.py b/module/network/Keepalive.py index 2443f5bbf..0ab3431ad 100644 --- a/module/network/Keepalive.py +++ b/module/network/Keepalive.py @@ -609,7 +609,6 @@ def test(url, N=10): test_timeout(url) if __name__ == '__main__': - import time import sys try: N = int(sys.argv[1]) diff --git a/module/plugins/HotfileCom.py b/module/plugins/HotfileCom.py index 7ae432c78..a046cb6b1 100644 --- a/module/plugins/HotfileCom.py +++ b/module/plugins/HotfileCom.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import re -import urllib from time import time from module.Plugin import Plugin diff --git a/module/plugins/LinkList.py b/module/plugins/LinkList.py index c934ca464..dba78ffd2 100644 --- a/module/plugins/LinkList.py +++ b/module/plugins/LinkList.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import re from module.Plugin import Plugin diff --git a/module/plugins/RapidshareCom.py b/module/plugins/RapidshareCom.py index f7bcb5de8..778383338 100644 --- a/module/plugins/RapidshareCom.py +++ b/module/plugins/RapidshareCom.py @@ -6,7 +6,6 @@ from time import time from module.Plugin import Plugin import hashlib -import logging class RapidshareCom(Plugin): diff --git a/module/thread_list.py b/module/thread_list.py index 3c69121c2..2faec1581 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -18,12 +18,12 @@ # ### from __future__ import with_statement +from os.path import exists import re import subprocess +from threading import RLock import time import urllib2 -from os.path import exists -from threading import RLock from download_thread import Download_Thread @@ -75,6 +75,7 @@ class Thread_List(object): if pyfile: self.py_downloading.append(pyfile) + self.scripts_download_preparing(pyfile.modul.__name__, pyfile.url) if not pyfile.plugin.multi_dl: self.occ_plugins.append(pyfile.modul.__name__) pyfile.active = True @@ -133,7 +134,7 @@ class Thread_List(object): pyfile.plugin.req.init_curl() elif pyfile.status.type == "failed": - self.parent.logger.warning("Download failed: " + pyfile.url+ " | " + pyfile.status.error) + self.parent.logger.warning("Download failed: " + pyfile.url + " | " + pyfile.status.error) with open(self.parent.config['general']['failed_file'], 'a') as f: f.write(pyfile.url + "\n") @@ -142,6 +143,8 @@ class Thread_List(object): self.list.save() + self.scripts_download_finished(pyfile.modul.__name__, pyfile.url, pyfile.status.filename, pyfile.download_folder) + self.lock.release() return True @@ -186,7 +189,7 @@ class Thread_List(object): return False def reconnect(self): - reconn = subprocess.Popen(self.parent.config['general']['reconnect_method']) + reconn = subprocess.Popen(self.parent.config['general']['reconnect_method'], stdout=subprocess.PIPE) reconn.wait() time.sleep(1) ip = "" @@ -197,3 +200,18 @@ class Thread_List(object): ip = "" time.sleep(1) self.parent.logger.info("Reconnected, new IP: " + ip) + + + def scripts_download_preparing(self, pluginname, url): + for script in self.parent.scripts['download_preparing']: + out = subprocess.Popen([script, pluginname, url], stdout=subprocess.PIPE) + out.wait() + + def scripts_download_finished(self, pluginname, url, filename, location): + map(lambda script: subprocess.Popen([script, pluginname, url, filename, location], stdout=subprocess.PIPE), self.parent.scripts['download_finished']) + + def scripts_package_finished(self, name, location): #@TODO Implement! + map(lambda script: subprocess.Popen([script, name, location], stdout=subprocess.PIPE), self.parent.scripts['download_finished']) + + def scripts_reconnected(self, ip): + map(lambda script: subprocess.Popen([script, ip], stdout=subprocess.PIPE), self.parent.scripts['download_finished']) diff --git a/module/web/WebServer.py b/module/web/WebServer.py index 3486bf7cb..15541676b 100644 --- a/module/web/WebServer.py +++ b/module/web/WebServer.py @@ -103,7 +103,6 @@ from bottle import route from bottle import run from bottle import send_file from bottle import template -from bottle import validate core = None diff --git a/pyLoadCli.py b/pyLoadCli.py index cf75019be..b6d08a238 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -21,7 +21,10 @@ SERVER_VERSION = "0.3" -import curses, traceback, string, os +import curses +import traceback +import string +import os from time import sleep, time import xmlrpclib from threading import RLock, Thread diff --git a/pyLoadCore.py b/pyLoadCore.py index e97b1fcaf..d78a195da 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -26,31 +26,32 @@ CURRENT_VERSION = '0.3' import ConfigParser import gettext from glob import glob +from imp import find_module import logging import logging.handlers +from os import chdir +from os import listdir from os import mkdir from os import sep -from os import chdir +from os.path import abspath from os.path import basename -from os.path import exists from os.path import dirname -from os.path import abspath +from os.path import exists +from re import sub import subprocess from sys import argv from sys import exit from sys import path from sys import stdout +import thread import time from time import sleep -from imp import find_module -from re import sub + from module.file_list import File_List -from module.thread_list import Thread_List from module.network.Request import Request -#~ from module.web.WebServer import WebServer import module.remote.SecureXMLRPCServer as Server - -import thread +from module.thread_list import Thread_List +from module.web.WebServer import WebServer class Core(object): """ pyLoad Core """ @@ -132,17 +133,18 @@ class Core(object): self.init_logger(logging.INFO) # logging level + self.init_scripts() path.append(self.plugin_folder) - self.create_plugin_index() + self.create_plugin_index() - self.server_methods = ServerMethods(self) + self.server_methods = ServerMethods(self) self.file_list = File_List(self) self.thread_list = Thread_List(self) self.server_methods.check_update() self.init_server() - #~ self.init_webserver() # start webinterface like cli, gui etc + self.init_webserver() # start webinterface like cli, gui etc self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only @@ -163,7 +165,7 @@ class Core(object): def init_server(self): try: server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) - usermap = { self.config['remote']['username']: self.config['remote']['password']} + usermap = {self.config['remote']['username']: self.config['remote']['password']} if self.config['ssl']['activated']: self.server = Server.SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], self.config['ssl']['key'], usermap) self.logger.info("Secure XMLRPC Server Started") @@ -197,6 +199,19 @@ class Core(object): self.logger.addHandler(console) #if console logging self.logger.setLevel(level) + + def init_scripts(self): + """ scan directory for scripts to execute""" + f = lambda x: False if x.startswith("#") or x.endswith("~") else True + self.scripts = {} + self.scripts['download_preparing'] = map(lambda x: 'scripts/download_preparing/' + x, filter(f, listdir('scripts/download_preparing'))) + self.scripts['download_finished'] = map(lambda x: 'scripts/download_finished/' + x, filter(f, listdir('scripts/download_finished'))) + self.scripts['package_finished'] = map(lambda x: 'scripts/package_finished/' + x, filter(f, listdir('scripts/package_finished'))) + self.scripts['reconnected'] = map(lambda x: 'scripts/reconnected/' + x, filter(f, listdir('scripts/reconnected'))) + + self.logger.info("Installed Scripts: %s" % str(self.scripts)) + + def check_install(self, check_name, legend, python=True, essential=False): """check wether needed tools are installed""" try: @@ -266,10 +281,10 @@ class Core(object): elif start < now and end < now and start > end: return True else: return False - #~ def init_webserver(self): - #~ self.webserver = WebServer(self) - #~ if self.config['webinterface']['activated']: - #~ self.webserver.start() + def init_webserver(self): + self.webserver = WebServer(self) + if self.config['webinterface']['activated']: + self.webserver.start() #################################### ########## XMLRPC Methods ########## @@ -282,7 +297,7 @@ class ServerMethods(): def check_update(self): """checks newst version""" if self.core.config['updates']['search_updates']: - version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" %(CURRENT_VERSION, self.core.config['updates']['install_updates'])) + version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, self.core.config['updates']['install_updates'])) if version_check == "": self.core.logger.info("No Updates for pyLoad") return False @@ -293,7 +308,7 @@ class ServerMethods(): tmp_zip = open(tmp_zip_name, 'w') tmp_zip.write(version_check) tmp_zip.close() - __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip_name,"Test/") + __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip_name, "Test/") return True except: @@ -354,12 +369,8 @@ class ServerMethods(): def add_package(self, name, links): pid = self.new_package(name) self.core.file_list.packager.pushPackage2Queue(pid) - fids = [] - for link in links: - fids.append(self.core.file_list.collector.addLink(link)) - for fid in fids: - self.move_file_2_package(fid,pid) - + fids = map(self.core.file_list.collector.addLink, links) + map(lambda fid: self.move_file_2_package(fid, pid), fids) self.push_package_2_queue(pid) def new_package(self, name): diff --git a/scripts/Readme.txt b/scripts/Readme.txt new file mode 100644 index 000000000..138b40b9b --- /dev/null +++ b/scripts/Readme.txt @@ -0,0 +1,23 @@ + ############################# + ### pyLoad Script Support ### + ############################# + +pyLoad is able to start any kind of scripts at given events. +Simply put your script in a suitable folder and pyLoad will execute it at the given events and pass some arguments to them. + +--> Note: Scripts, which starts with # will be ignored! +For Example: #converter.sh will not be executed. + +--> Note: You have to restart pyload when you change script names or locations. + +Below you see the list of arguments, which are passed to the scripts. + +## Argument list ## + +download_preparing: pluginname url + +download_finished: pluginname url filename filelocation + +package_finshed: packagename packagelocation + +reconnected: newip
\ No newline at end of file |