From 6a730384ac852dcb76cbd51cee17b381f9f4e7b2 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 16 Nov 2009 16:29:15 +0100 Subject: core now uses xmlrpc --- pyLoadCore.py | 442 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 198 insertions(+), 244 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index c4c5dd9f0..51a95169e 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -17,7 +17,7 @@ # along with this program; if not, see . # ### -CURRENT_VERSION = '0.2.3.2' +CURRENT_VERSION = '0.3' import ConfigParser import gettext @@ -40,22 +40,85 @@ import time from time import sleep import urllib2 from imp import find_module +from re import sub try: find_module("Crypto") except ImportError: print "Install pycrypto to use pyLoad" exit() from module.file_list import File_List -from module.remote.RequestObject import RequestObject -from module.remote.SocketServer import ServerThread from module.thread_list import Thread_List -from module.web.WebServer import WebServer +#from module.web.WebServer import WebServer +from SimpleXMLRPCServer import SimpleXMLRPCServer as Server +from module.network.Request import Request +import thread class Core(object): - """ pyLoad main - """ + """ pyLoad Core """ def __init__(self): - + if len(argv) > 1: + if argv[1] == "-v": + print "pyLoad", CURRENT_VERSION + exit() + + def read_config(self): + """ read config and sets preferences """ + self.configfile = ConfigParser.SafeConfigParser() + self.configfile.read('config') + for section in self.configfile.sections(): + self.config[section] = {} + for option in self.configfile.options(section): + self.config[section][option] = self.configfile.get(section, option) + self.config[section][option] = False if self.config[section][option].lower() == 'false' else self.config[section][option] + + def set_option(self, section, option, value): + self.config[option] = value + self.configfile.set(section, option, str(value)) + self.configfile.write(open('config', "wb")) + + def read_option(self): + return self.config + + def server_send_status(self): + obj = RequestObject() + obj.command = "update" + obj.data = self.get_downloads() + obj.status = self.server_status() + self.server.push_all(obj) + + def init_webserver(self): + if not self.config['webinterface']['activated']: + return False + + try: + self.webserver = WebServer(self) + self.webserver.start() + except Exception, e: + self.logger.error("Failed starting webserver, no webinterface available: %s" % str(e)) + exit() + + def shutdown(self): + "abort all downloads and exit" + self.thread_list.pause = True + + for pyfile in self.thread_list.py_downloading: + pyfile.plugin.req.abort = True + + while self.thread_list.py_downloading: + sleep(1) + self.logger.info("Going to shutdown pyLoad") + exit() + + def toggle_pause(self): + if self.thread_list.pause: + self.thread_list.pause = False + return False + elif not self.thread_list.pause: + self.thread_list.pause = True + return True + + def start(self): + """ starts the machine""" chdir(dirname(abspath(__file__)) + sep) self.config = {} @@ -68,13 +131,13 @@ class Core(object): translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) - self.check_installs("pycurl", "pycurl for lower memory footprint while downloading") - self.check_installs("tesseract", "tesseract for captcha reading", False) - self.check_installs("gocr", "gocr for captcha reading", False) - self.check_create(self.config['log']['log_folder'], _("folder for logs")) - self.check_create(self.config['general']['download_folder'], _("folder for downloads")) - self.check_create(self.config['general']['link_file'], _("file for links"), False) - self.check_create(self.config['general']['failed_file'], _("file for failed links"), False) + self.check_install("pycurl", "pycurl for lower memory footprint while downloading") + self.check_install("tesseract", "tesseract for captcha reading", False) + self.check_install("gocr", "gocr for captcha reading", False) + self.check_file(self.config['log']['log_folder'], _("folder for logs")) + self.check_file(self.config['general']['download_folder'], _("folder for downloads")) + self.check_file(self.config['general']['link_file'], _("file for links"), False) + self.check_file(self.config['general']['failed_file'], _("file for failed links"), False) if self.config['general']['debug_mode']: self.init_logger(logging.DEBUG) # logging level @@ -85,7 +148,7 @@ class Core(object): self.check_update() - self.logger.info(_("Downloadtime: %s") % self.is_dltime()) # debug only + self.logger.info(_("Downloadtime: %s") % self.is_time_download()) # debug only path.append(self.plugin_folder) self.create_plugin_index() @@ -96,13 +159,42 @@ class Core(object): self.thread_list = Thread_List(self) #Webserver + #self.self.server() +# self.init_webserver() + + + self.read_url_list(self.config['general']['link_file']) + + while True: + sleep(2) + if self.do_kill: + self.logger.info("pyLoad quits") + exit() +#################################################################################################################### +###############################################überarbeitet######################################################### +#################################################################################################################### - self.init_webserver() + def init_logger(self, level): - def check_installs(self, check_name, legend, python=True, essential=False): + file_handler = logging.handlers.RotatingFileHandler(self.config['log']['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log']['log_count'])) #100 kib each + console = logging.StreamHandler(stdout) + + frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") + file_handler.setFormatter(frm) + console.setFormatter(frm) + + self.logger = logging.getLogger("log") # settable in config + + if self.config['log']['file_log']: + self.logger.addHandler(file_handler) + + self.logger.addHandler(console) #if console logging + self.logger.setLevel(level) + + def check_install(self, check_name, legend, python=True, essential=False): """check wether needed tools are installed""" try: - if python: + if python: find_module(check_name) else: pipe = subprocess.PIPE @@ -110,8 +202,8 @@ class Core(object): except: print "Install", legend if essential: exit() - - def check_create(self, check_name, legend, folder=True): + + def check_file(self, check_name, legend, folder=True): """check wether needed files are exists""" if not exists(check_name): try: @@ -123,131 +215,65 @@ class Core(object): except: print _("could not create %s") % legend exit() - - def read_config(self): - """ read config and sets preferences - """ - self.configfile = ConfigParser.SafeConfigParser() - self.configfile.read('config') - for section in self.configfile.sections(): - self.config[section] = {} - for option in self.configfile.options(section): - self.config[section][option] = self.configfile.get(section, option) - self.config[section][option] = False if self.config[section][option].lower() == 'false' else self.config[section][option] - - def set_option(self, section, option, value): - self.config[option] = value - self.configfile.set(section, option, str(value)) - self.configfile.write(open('config', "wb")) - - def read_option(self): - return self.config - - def create_plugin_index(self): - for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): - plugin_pattern = "" - plugin_file = basename(file_handler).replace('.pyc', '').replace('.py', '') - for line in open(file_handler, "r").readlines(): - if "props['pattern']" in line: - plugin_pattern = line.split("r\"")[1].split("\"")[0] - break - if plugin_pattern != "": - self.plugins_avaible[plugin_file] = plugin_pattern - self.logger.debug(plugin_file + _(" added")) - self.logger.info(_("created index of plugins")) - - def read_links(self): - """read links from txt""" - txt = open(self.config['general']['link_file'], 'r') - new_links = 0 - links = txt.readlines() - for link in links: - if link != "\n": - self.file_list.append(link) - new_links += 1 - - txt.close() - - self.file_list.save() - if new_links: - self.logger.info("Parsed link from %s: %i" % (self.config['general']['link_file'], new_links)) - - txt = open(self.config['general']['link_file'], 'w') - txt.write("") - txt.close() - + def check_update(self): - """checks newst version - """ + """checks newst version""" if not self.config['updates']['search_updates']: return False - - newst_version = urllib2.urlopen("http://update.pyload.org/index.php?do=" + CURRENT_VERSION).readline() + + newst_version = Request().load("http://update.pyload.org/index.php?do=" + CURRENT_VERSION) if newst_version == "True": if not self.config['updates']['install_updates']: - self.logger.info("New version available, please run Updater") + self.logger.info("New Version of pyLoad available") else: updater = __import__("pyLoadUpdater") updater.main() else: - self.logger.info("pyLoad is up-to-date") - - def init_logger(self, level): - - file_handler = logging.handlers.RotatingFileHandler(self.config['log']['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log']['log_count'])) #100 kib each - console = logging.StreamHandler(stdout) + self.logger.info("No Updates for pyLoad") - frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") - file_handler.setFormatter(frm) - console.setFormatter(frm) - - self.logger = logging.getLogger("log") # settable in config - - if self.config['log']['file_log']: - self.logger.addHandler(file_handler) - - self.logger.addHandler(console) #if console logging - self.logger.setLevel(level) - - def is_dltime(self): - start = self.config['downloadTime']['start'].split(":") - end = self.config['downloadTime']['end'].split(":") - - return self.compare_time(start, end) - - def is_reconnect_time(self): - - start = self.config['reconnectTime']['start'].split(":") - end = self.config['reconnectTime']['end'].split(":") - - return self.compare_time(start, end) + def create_plugin_index(self): + for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): + plugin_file = sub("(\.pyc|\.py)", "", basename(file_handler)) + for line in open(file_handler, "r").readlines(): + if "props['pattern']" in line: + plugin_pattern = line.split("r\"")[1].split("\"")[0] + self.plugins_avaible[plugin_file] = plugin_pattern + self.logger.debug(("%s added") % plugin_file) + break + self.logger.info(_("created index of plugins")) def compare_time(self, start, end): - - if start == end: - return True + if start == end: return True now = time.localtime()[3:5] + if start < now and end > now: return True + elif start > end and (now > start or now < end): return True + elif start < now and end < now and start > end: return True + else: return False + + def init_server(self): + try: + self.server = Server(("", 1337), allow_none=True) + self.server.register_function(self.status_downloads) + self.server.register_function(self.status_server) + self.server.register_function(self.kill) + self.server.register_function(self.del_urls) + self.server.register_function(self.add_urls) + self.server.register_function(self.get_urls) + self.server.register_function(self.move_urls_up) + self.server.register_function(self.move_urls_down) + self.server.register_function(self.is_time_download) + self.server.register_function(self.is_time_reconnect) +# self.server.register_function(self.server_status) + self.logger.info("Test Server Started") + thread.start_new_thread(self.server.serve_forever, ()) + except Exception, e: + self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) - if start < now and end > now: - return True - elif start > end and (now > start or now < end): - return True - elif start < now and end < now and start > end: - return True - else: - return False - - def format_time(self, seconds): - seconds = int(seconds) - if seconds > 60: - hours, seconds = divmod(seconds, 3600) - minutes, seconds = divmod(seconds, 60) - return "%.2i:%.2i:%.2i" % (hours, minutes, seconds) - return _("%i seconds") % seconds - - def get_downloads(self): - list = [] +##############################################server funktionen#################################################### + + def status_downloads(self): + downloads = [] for pyfile in self.thread_list.py_downloading: download = {} download['id'] = pyfile.id @@ -260,18 +286,10 @@ class Core(object): download['status'] = pyfile.status.type download['wait_until'] = pyfile.status.waituntil download['plugin'] = pyfile.status.plugin - list.append(download) - - return list - - def server_send_status(self): - obj = RequestObject() - obj.command = "update" - obj.data = self.get_downloads() - obj.status = self.server_status() - self.server.push_all(obj) - - def server_status(self): + downloads.append(download) + return downloads + + def status_server(self): status = {} status['pause'] = self.thread_list.pause status['queue'] = len(self.file_list.files) @@ -281,127 +299,63 @@ class Core(object): status['speed'] += pyfile.status.get_speed() return status - - def init_server(self): - - try: - self.server = ServerThread(self) - self.server.start() - except Exception, e: - self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) - exit() - - def init_webserver(self): - - if not self.config['webinterface']['activated']: - return False - - try: - self.webserver = WebServer(self) - self.webserver.start() - except Exception, e: - self.logger.error("Failed starting webserver, no webinterface available: %s" % str(e)) - exit() - - def kill(self): - self.do_kill = True - self.logger.info("Going to kill pyLoad") - exit() - return True - - def shutdown(self): - "abort all downloads and exit" - self.thread_list.pause = True - - for pyfile in self.thread_list.py_downloading: - pyfile.plugin.req.abort = True - - while self.thread_list.py_downloading: - sleep(1) - self.logger.info("Going to shutdown pyLoad") - exit() - def add_links(self, links): + def add_urls(self, links): self.file_list.extend(links) self.file_list.save() - - def remove_links(self, ids): + + def del_urls(self, ids): for id in ids: self.file_list.remove_id(id) self.file_list.save() - - def get_links(self): + + def kill(self): + self.do_kill = True + return True + + def get_urls(self): return self.file_list.data - def move_links_up(self, ids): - + def move_urls_up(self, ids): for id in ids: self.file_list.move(id) - self.file_list.save() - def move_links_down(self, ids): - + def move_urls_down(self, ids): for id in ids: self.file_list.move(id, 1) - self.file_list.save() + + def read_url_list(self, url_list): + """read links from txt""" + txt = open(self.config['general']['link_file'], 'r') + new_links = 0 + links = txt.readlines() + for link in links: + if link != "\n": + self.file_list.append(link) + new_links += 1 - def toggle_pause(self): - if self.thread_list.pause: - self.thread_list.pause = False - return False - elif not self.thread_list.pause: - self.thread_list.pause = True - return True + txt.close() - def start(self): - """ starts the machine - """ - if len(argv) > 1: - shortOptions = 'pu:l:' - longOptions = ['print', 'url=', 'list='] - - opts, extraparams = __import__("getopt").getopt(argv[1:], shortOptions, longOptions) - for option, params in opts: - if option in ("-p", "--print"): - print "Print test output" - self.print_test_status = True - elif option in ("-u", "--url"): - self.logger.info("Add url: " + params) - self.add_links([params]) - elif option in ("-l", "--list"): - list = open(params, 'r').readlines() - self.add_links(list) - self.logger.info("Add list:" + params) - - self.read_links() + self.file_list.save() + if new_links: + self.logger.info("Parsed link from %s: %i" % (self.config['general']['link_file'], new_links)) - while True: - #self.thread_list.status() - if self.print_test_status: - self._test_print_status() - self.server_send_status() - sleep(2) - if self.do_kill: - self.logger.info("pyLoad quits") - exit() + txt = open(self.config['general']['link_file'], 'w') + txt.write("") + txt.close() - def _test_print_status(self): + def is_time_download(self): + start = self.config['downloadTime']['start'].split(":") + end = self.config['downloadTime']['end'].split(":") + return self.compare_time(start, end) - if self.thread_list.py_downloading: - for pyfile in self.thread_list.py_downloading: - if pyfile.status.type == 'downloading': - print pyfile.status.filename + ": speed is", int(pyfile.status.get_speed()), "kb/s" - print pyfile.status.filename + ": finished in", self.format_time(pyfile.status.get_ETA()) - elif pyfile.status.type == 'waiting': - print pyfile.status.filename + ": wait", self.format_time(pyfile.status.waituntil - time.time()) + def is_time_reconnect(self): + start = self.config['reconnectTime']['start'].split(":") + end = self.config['reconnectTime']['end'].split(":") + return self.compare_time(start, end) if __name__ == "__main__": - if len(argv) > 1: - if argv[1] == "-v": - print "pyLoad", CURRENT_VERSION - exit() - - testLoader = Core() - testLoader.start() + pyload_core = Core() + pyload_core.start() -- cgit v1.2.3 From 7579e0750c7bd81c916012e2842c8a96ad8fa414 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 22 Nov 2009 15:04:30 +0100 Subject: secure xmlrpc --- pyLoadCore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 51a95169e..920278fe0 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -49,7 +49,7 @@ except ImportError: from module.file_list import File_List from module.thread_list import Thread_List #from module.web.WebServer import WebServer -from SimpleXMLRPCServer import SimpleXMLRPCServer as Server +from module.remote.SecureXMLRPCServer import SecureXMLRPCServer from module.network.Request import Request import thread @@ -253,7 +253,7 @@ class Core(object): def init_server(self): try: - self.server = Server(("", 1337), allow_none=True) + self.server = SecureXMLRPCServer(("", 1337), "ssl.crt", "ssl.key", {"testuser":"testpw"}) self.server.register_function(self.status_downloads) self.server.register_function(self.status_server) self.server.register_function(self.kill) -- cgit v1.2.3 From 8afd72d4a918108a081a6a94ccc72f4c2d275897 Mon Sep 17 00:00:00 2001 From: spoob Date: Mon, 16 Nov 2009 20:28:33 +0100 Subject: Fixed DLC Plugin --- pyLoadCore.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 920278fe0..a0e645fb2 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -234,12 +234,13 @@ class Core(object): def create_plugin_index(self): for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): plugin_file = sub("(\.pyc|\.py)", "", basename(file_handler)) - for line in open(file_handler, "r").readlines(): - if "props['pattern']" in line: - plugin_pattern = line.split("r\"")[1].split("\"")[0] - self.plugins_avaible[plugin_file] = plugin_pattern - self.logger.debug(("%s added") % plugin_file) - break + if plugin_file == "DLC": + plugin_pattern = "(?!http://).*\.dlc" + else: + for line in open(file_handler, "r").readlines(): + if "props['pattern']" in line: + plugin_pattern = line.split("r\"")[1].split("\"")[0] + break self.logger.info(_("created index of plugins")) def compare_time(self, start, end): -- cgit v1.2.3 From b391a5b9061d7d41bf1ae7df71f5a5e64b8491e8 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 22 Nov 2009 17:44:03 +0100 Subject: fixed SecureXMLRPCServer --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index a0e645fb2..671cc7585 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -255,6 +255,7 @@ class Core(object): def init_server(self): try: self.server = SecureXMLRPCServer(("", 1337), "ssl.crt", "ssl.key", {"testuser":"testpw"}) + self.server.register_introspection_functions() self.server.register_function(self.status_downloads) self.server.register_function(self.status_server) self.server.register_function(self.kill) -- cgit v1.2.3 From e50443e707bd6e01e42cdf519e1422589694dbb1 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 22 Nov 2009 18:41:09 +0100 Subject: fixed plugin index --- pyLoadCore.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 671cc7585..6d52ca4e0 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -233,6 +233,7 @@ class Core(object): def create_plugin_index(self): for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): + plugin_pattern = "" plugin_file = sub("(\.pyc|\.py)", "", basename(file_handler)) if plugin_file == "DLC": plugin_pattern = "(?!http://).*\.dlc" @@ -241,6 +242,9 @@ class Core(object): if "props['pattern']" in line: plugin_pattern = line.split("r\"")[1].split("\"")[0] break + if plugin_pattern != "": + self.plugins_avaible[plugin_file] = plugin_pattern + self.logger.debug(plugin_file + _(" added")) self.logger.info(_("created index of plugins")) def compare_time(self, start, end): -- cgit v1.2.3 From 419a93755b6180bbab69aaf973cd99f49b4a2268 Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 22 Nov 2009 18:51:14 +0100 Subject: Webinterface with XMLRPC --- pyLoadCore.py | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 6d52ca4e0..b4045ffee 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -48,7 +48,7 @@ except ImportError: exit() from module.file_list import File_List from module.thread_list import Thread_List -#from module.web.WebServer import WebServer +from module.web.WebServer import WebServer from module.remote.SecureXMLRPCServer import SecureXMLRPCServer from module.network.Request import Request import thread @@ -87,11 +87,11 @@ class Core(object): self.server.push_all(obj) def init_webserver(self): - if not self.config['webinterface']['activated']: - return False - +# if not self.config['webinterface']['activated']: +# return False + return False try: - self.webserver = WebServer(self) + self.webserver = WebServer() self.webserver.start() except Exception, e: self.logger.error("Failed starting webserver, no webinterface available: %s" % str(e)) @@ -158,9 +158,9 @@ class Core(object): self.file_list = File_List(self) self.thread_list = Thread_List(self) - #Webserver +# Webserver #self.self.server() -# self.init_webserver() + self.init_webserver() self.read_url_list(self.config['general']['link_file']) @@ -173,6 +173,25 @@ class Core(object): #################################################################################################################### ###############################################überarbeitet######################################################### #################################################################################################################### + def init_server(self): + try: + self.server = SecureXMLRPCServer(("", 1337), "ssl.crt", "ssl.key", {"testuser":"testpw"}) + self.server.register_introspection_functions() + self.server.register_function(self.status_downloads) + self.server.register_function(self.status_server) + self.server.register_function(self.kill) + self.server.register_function(self.del_urls) + self.server.register_function(self.add_urls) + self.server.register_function(self.get_urls) + self.server.register_function(self.move_urls_up) + self.server.register_function(self.move_urls_down) + self.server.register_function(self.is_time_download) + self.server.register_function(self.is_time_reconnect) + # self.server.register_function(self.server_status) + self.logger.info("Test Server Started") + thread.start_new_thread(self.server.serve_forever, ()) + except Exception, e: + self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) def init_logger(self, level): @@ -256,26 +275,6 @@ class Core(object): elif start < now and end < now and start > end: return True else: return False - def init_server(self): - try: - self.server = SecureXMLRPCServer(("", 1337), "ssl.crt", "ssl.key", {"testuser":"testpw"}) - self.server.register_introspection_functions() - self.server.register_function(self.status_downloads) - self.server.register_function(self.status_server) - self.server.register_function(self.kill) - self.server.register_function(self.del_urls) - self.server.register_function(self.add_urls) - self.server.register_function(self.get_urls) - self.server.register_function(self.move_urls_up) - self.server.register_function(self.move_urls_down) - self.server.register_function(self.is_time_download) - self.server.register_function(self.is_time_reconnect) -# self.server.register_function(self.server_status) - self.logger.info("Test Server Started") - thread.start_new_thread(self.server.serve_forever, ()) - except Exception, e: - self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) - ##############################################server funktionen#################################################### def status_downloads(self): -- cgit v1.2.3 From 1d3b74dc93d403783924c654cc22f3304a1d7f0a Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 25 Nov 2009 18:55:38 +0100 Subject: basic curses cli --- pyLoadCore.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b4045ffee..b329655a0 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -79,13 +79,6 @@ class Core(object): def read_option(self): return self.config - def server_send_status(self): - obj = RequestObject() - obj.command = "update" - obj.data = self.get_downloads() - obj.status = self.server_status() - self.server.push_all(obj) - def init_webserver(self): # if not self.config['webinterface']['activated']: # return False @@ -175,7 +168,11 @@ class Core(object): #################################################################################################################### def init_server(self): try: - self.server = SecureXMLRPCServer(("", 1337), "ssl.crt", "ssl.key", {"testuser":"testpw"}) + server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) + usermap = { + self.config['remote']['username']: self.config['remote']['password'] + } + self.server = SecureXMLRPCServer(server_addr, "ssl.crt", "ssl.key", usermap) self.server.register_introspection_functions() self.server.register_function(self.status_downloads) self.server.register_function(self.status_server) @@ -187,7 +184,8 @@ class Core(object): self.server.register_function(self.move_urls_down) self.server.register_function(self.is_time_download) self.server.register_function(self.is_time_reconnect) - # self.server.register_function(self.server_status) + self.server.register_function(self.get_conf_val) + self.server.register_function(self.file_exists) self.logger.info("Test Server Started") thread.start_new_thread(self.server.serve_forever, ()) except Exception, e: @@ -294,6 +292,12 @@ class Core(object): downloads.append(download) return downloads + def get_conf_val(self, cat, var): + if var != "username" and var != "password": + return self.config[cat][var] + else: + raise Exception("not allowed!") + def status_server(self): status = {} status['pause'] = self.thread_list.pause @@ -305,6 +309,9 @@ class Core(object): return status + def file_exists(self, path): #@XXX: security?! + return exists(path) + def add_urls(self, links): self.file_list.extend(links) self.file_list.save() -- cgit v1.2.3 From 523e2857c47cdef1da6b43523bcf7871ed9e1d63 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 26 Nov 2009 22:05:11 +0100 Subject: complete new file_list, cleaned up --- pyLoadCore.py | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b329655a0..16387c302 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -1,22 +1,27 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# -#Copyright (C) 2009 spoob, sebnapi, RaNaN -# -#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 of the License, -#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, see . -# -### + +""" + 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 of the License, + 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, see . + + @author: spoob + @author: sebnapi + @author: RaNaN + @author: mkaay + @version: v0.3 +""" + CURRENT_VERSION = '0.3' import ConfigParser @@ -163,16 +168,14 @@ class Core(object): if self.do_kill: self.logger.info("pyLoad quits") exit() -#################################################################################################################### -###############################################überarbeitet######################################################### -#################################################################################################################### + 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'] } - self.server = SecureXMLRPCServer(server_addr, "ssl.crt", "ssl.key", usermap) + self.server = SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], self.config['ssl']['key'], usermap) self.server.register_introspection_functions() self.server.register_function(self.status_downloads) self.server.register_function(self.status_server) @@ -186,7 +189,8 @@ class Core(object): self.server.register_function(self.is_time_reconnect) self.server.register_function(self.get_conf_val) self.server.register_function(self.file_exists) - self.logger.info("Test Server Started") + self.server.register_function(self.get_server_version) + self.logger.info("SecureXMLRPC Server Started") thread.start_new_thread(self.server.serve_forever, ()) except Exception, e: self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) @@ -273,7 +277,9 @@ class Core(object): elif start < now and end < now and start > end: return True else: return False -##############################################server funktionen#################################################### + #################################### + ########## XMLRPC Methods ########## + #################################### def status_downloads(self): downloads = [] @@ -312,6 +318,9 @@ class Core(object): def file_exists(self, path): #@XXX: security?! return exists(path) + def get_server_version(self): + return CURRENT_VERSION + def add_urls(self, links): self.file_list.extend(links) self.file_list.save() -- cgit v1.2.3 From 80cd07afb67746a0279d6f194102e0d52bdbba29 Mon Sep 17 00:00:00 2001 From: mkaay Date: Fri, 27 Nov 2009 16:55:55 +0100 Subject: fixed file_list --- pyLoadCore.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 16387c302..df4e472c6 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -322,7 +322,8 @@ class Core(object): return CURRENT_VERSION def add_urls(self, links): - self.file_list.extend(links) + for link in links: + self.file_list.collector.addLink(link) self.file_list.save() def del_urls(self, ids): -- cgit v1.2.3 From 7fb23f31ac129442f35d2d98a5ef3f0b387dc8e2 Mon Sep 17 00:00:00 2001 From: mkaay Date: Fri, 27 Nov 2009 23:51:44 +0100 Subject: updated xmlrpc methods --- pyLoadCore.py | 61 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 19 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index df4e472c6..9a9cd8306 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -180,11 +180,12 @@ class Core(object): self.server.register_function(self.status_downloads) self.server.register_function(self.status_server) self.server.register_function(self.kill) - self.server.register_function(self.del_urls) + self.server.register_function(self.del_links) + self.server.register_function(self.del_packages) self.server.register_function(self.add_urls) - self.server.register_function(self.get_urls) - self.server.register_function(self.move_urls_up) - self.server.register_function(self.move_urls_down) + self.server.register_function(self.get_queue) + #self.server.register_function(self.move_urls_up) + #self.server.register_function(self.move_urls_down) self.server.register_function(self.is_time_download) self.server.register_function(self.is_time_reconnect) self.server.register_function(self.get_conf_val) @@ -326,27 +327,49 @@ class Core(object): self.file_list.collector.addLink(link) self.file_list.save() - def del_urls(self, ids): + def del_links(self, ids): for id in ids: - self.file_list.remove_id(id) + try: + self.file_list.collector.removeFile(id) + except: + self.file_list.packages.removeFile(id) + self.file_list.save() + + def del_packages(self, ids): + for id in ids: + self.file_list.packages.removePackage(id) self.file_list.save() def kill(self): self.do_kill = True return True - def get_urls(self): - return self.file_list.data - - def move_urls_up(self, ids): - for id in ids: - self.file_list.move(id) - self.file_list.save() - - def move_urls_down(self, ids): - for id in ids: - self.file_list.move(id, 1) - self.file_list.save() + def get_queue(self): + data = [] + for q in self.file_list.data["queue"]: + ds = { + "id": q.data.id, + "name": q.data.package_name, + "folder": q.data.folder, + "files": [] + } + for f in q.links: + ds["files"].append({ + "name": f.status.name, + "status": f.status.type, + "url": f.url + }) + data.append(ds) + + #def move_urls_up(self, ids): + # for id in ids: + # self.file_list.move(id) + # self.file_list.save() + + #def move_urls_down(self, ids): + # for id in ids: + # self.file_list.move(id, 1) + # self.file_list.save() def read_url_list(self, url_list): """read links from txt""" @@ -355,7 +378,7 @@ class Core(object): links = txt.readlines() for link in links: if link != "\n": - self.file_list.append(link) + self.file_list.collector.addLink(link) new_links += 1 txt.close() -- cgit v1.2.3 From 54b787dd2a35b51952fdcb26df51cb18a0c97060 Mon Sep 17 00:00:00 2001 From: spoob Date: Sat, 28 Nov 2009 14:17:28 +0100 Subject: cleaned and fixed --- pyLoadCore.py | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 9a9cd8306..1a5975566 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -84,17 +84,6 @@ class Core(object): def read_option(self): return self.config - def init_webserver(self): -# if not self.config['webinterface']['activated']: -# return False - return False - try: - self.webserver = WebServer() - self.webserver.start() - except Exception, e: - self.logger.error("Failed starting webserver, no webinterface available: %s" % str(e)) - exit() - def shutdown(self): "abort all downloads and exit" self.thread_list.pause = True @@ -128,7 +117,8 @@ class Core(object): self.do_kill = False translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) - + + #check_file(self, check_name, legend, folder=True, empty=True, essential=False): self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) @@ -136,6 +126,8 @@ class Core(object): self.check_file(self.config['general']['download_folder'], _("folder for downloads")) self.check_file(self.config['general']['link_file'], _("file for links"), False) self.check_file(self.config['general']['failed_file'], _("file for failed links"), False) + self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, False, True) + self.check_file(self.config['ssl']['key'], _("ssl key"), False, False, True) if self.config['general']['debug_mode']: self.init_logger(logging.DEBUG) # logging level @@ -155,11 +147,6 @@ class Core(object): self.file_list = File_List(self) self.thread_list = Thread_List(self) - -# Webserver - #self.self.server() - self.init_webserver() - self.read_url_list(self.config['general']['link_file']) @@ -225,18 +212,26 @@ class Core(object): print "Install", legend if essential: exit() - def check_file(self, check_name, legend, folder=True): + def check_file(self, check_name, legend, folder=True, empty=True, essential=False): """check wether needed files are exists""" if not exists(check_name): - try: - if folder: - mkdir(check_name) - else: - open(check_name, "w") - print _("%s created") % legend - except: - print _("could not create %s") % legend - exit() + created = False + if empty: + try: + if folder: + mkdir(check_name) + else: + open(check_name, "w") + print _("%s created") % legend + created = True + except: + print _("could not create %s: %s") % (legend, check_name) + else: + print _("could not find %s: %s") % (legend, check_name) + if essential and not created: + exit() + + def check_update(self): """checks newst version""" -- cgit v1.2.3 From c31ce407f31aa9e35e70d14be87fa96611906f08 Mon Sep 17 00:00:00 2001 From: spoob Date: Sat, 28 Nov 2009 20:56:08 +0100 Subject: Normal XMLRPC Server available --- pyLoadCore.py | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 1a5975566..df41c7b40 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -54,7 +54,7 @@ except ImportError: from module.file_list import File_List from module.thread_list import Thread_List from module.web.WebServer import WebServer -from module.remote.SecureXMLRPCServer import SecureXMLRPCServer +#from module.remote.SecureXMLRPCServer import SecureXMLRPCServer from module.network.Request import Request import thread @@ -126,8 +126,9 @@ class Core(object): self.check_file(self.config['general']['download_folder'], _("folder for downloads")) self.check_file(self.config['general']['link_file'], _("file for links"), False) self.check_file(self.config['general']['failed_file'], _("file for failed links"), False) - self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, False, True) - self.check_file(self.config['ssl']['key'], _("ssl key"), False, False, True) + if self.config['ssl']['activated']: + self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, False, True) + self.check_file(self.config['ssl']['key'], _("ssl key"), False, False, True) if self.config['general']['debug_mode']: self.init_logger(logging.DEBUG) # logging level @@ -159,10 +160,16 @@ 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'] - } - self.server = SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], self.config['ssl']['key'], usermap) + usermap = { self.config['remote']['username']: self.config['remote']['password'] } + if self.config['ssl']['activated']: + Server = __import__("module.remote.Secure XMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) + self.server = Server.SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], self.config['ssl']['key'], usermap) + self.logger.info("SecureXMLRPC Server Started") + else: + Server = __import__("SimpleXMLRPCServer") + self.server = Server.SimpleXMLRPCServer(server_addr) + self.logger.info("Normal XMLRPC Server Started") + self.server.register_introspection_functions() self.server.register_function(self.status_downloads) self.server.register_function(self.status_server) @@ -178,7 +185,6 @@ class Core(object): self.server.register_function(self.get_conf_val) self.server.register_function(self.file_exists) self.server.register_function(self.get_server_version) - self.logger.info("SecureXMLRPC Server Started") thread.start_new_thread(self.server.serve_forever, ()) except Exception, e: self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) @@ -215,24 +221,22 @@ class Core(object): def check_file(self, check_name, legend, folder=True, empty=True, essential=False): """check wether needed files are exists""" if not exists(check_name): - created = False - if empty: - try: - if folder: - mkdir(check_name) - else: - open(check_name, "w") - print _("%s created") % legend - created = True - except: - print _("could not create %s: %s") % (legend, check_name) - else: - print _("could not find %s: %s") % (legend, check_name) - if essential and not created: - exit() - - - + created = False + if empty: + try: + if folder: + mkdir(check_name) + else: + open(check_name, "w") + print _("%s created") % legend + created = True + except: + print _("could not create %s: %s") % (legend, check_name) + else: + print _("could not find %s: %s") % (legend, check_name) + if essential and not created: + exit() + def check_update(self): """checks newst version""" if not self.config['updates']['search_updates']: -- cgit v1.2.3 From 86eb33e1200d9107a728703531013a658b610f5b Mon Sep 17 00:00:00 2001 From: spoob Date: Sat, 28 Nov 2009 20:59:41 +0100 Subject: Fixed SecureXMLRPC Bug --- pyLoadCore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index df41c7b40..b38772d6d 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -162,9 +162,9 @@ class Core(object): server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) usermap = { self.config['remote']['username']: self.config['remote']['password'] } if self.config['ssl']['activated']: - Server = __import__("module.remote.Secure XMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) + Server = __import__("module.remote.SecureXMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) self.server = Server.SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], self.config['ssl']['key'], usermap) - self.logger.info("SecureXMLRPC Server Started") + self.logger.info("Secure XMLRPC Server Started") else: Server = __import__("SimpleXMLRPCServer") self.server = Server.SimpleXMLRPCServer(server_addr) -- cgit v1.2.3 From 8effa6e3712a11104835aa031242b39a29f291a0 Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 29 Nov 2009 15:18:18 +0100 Subject: links.pkl now in module, nicer terminal kill --- pyLoadCore.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b38772d6d..cb6714f85 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -53,8 +53,6 @@ except ImportError: exit() from module.file_list import File_List from module.thread_list import Thread_List -from module.web.WebServer import WebServer -#from module.remote.SecureXMLRPCServer import SecureXMLRPCServer from module.network.Request import Request import thread @@ -118,7 +116,6 @@ class Core(object): translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) - #check_file(self, check_name, legend, folder=True, empty=True, essential=False): self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) @@ -132,11 +129,9 @@ class Core(object): if self.config['general']['debug_mode']: self.init_logger(logging.DEBUG) # logging level - self.print_test_status = True else: self.init_logger(logging.INFO) # logging level - self.print_test_status = False - + self.check_update() self.logger.info(_("Downloadtime: %s") % self.is_time_download()) # debug only @@ -148,7 +143,7 @@ class Core(object): self.file_list = File_List(self) self.thread_list = Thread_List(self) - + self.read_url_list(self.config['general']['link_file']) while True: @@ -402,4 +397,9 @@ class Core(object): if __name__ == "__main__": pyload_core = Core() - pyload_core.start() + try: + pyload_core.start() + except KeyboardInterrupt: + pyload_core.logger.info("killed pyLoad by Terminal") + exit() + -- cgit v1.2.3 From 672932abf1cc860ebef67fb8385ffdf04aaf5215 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 29 Nov 2009 16:29:53 +0100 Subject: new xmlrpc method --- pyLoadCore.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index cb6714f85..d1677a17b 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -354,6 +354,25 @@ class Core(object): "url": f.url }) data.append(ds) + return data + + def get_collector_packages(self): + data = [] + for q in self.file_list.data["packages"]: + ds = { + "id": q.data.id, + "name": q.data.package_name, + "folder": q.data.folder, + "files": [] + } + for f in q.links: + ds["files"].append({ + "name": f.status.name, + "status": f.status.type, + "url": f.url + }) + data.append(ds) + return data #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From ffd2e9faf08b3af822e1958c33e5f2784548ebb3 Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 29 Nov 2009 17:10:11 +0100 Subject: Better Update Check --- pyLoadCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index d1677a17b..be9232300 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -237,7 +237,7 @@ class Core(object): if not self.config['updates']['search_updates']: return False - newst_version = Request().load("http://update.pyload.org/index.php?do=" + CURRENT_VERSION) + newst_version = Request().load("http://update.pyload.org/s/" + CURRENT_VERSION) if newst_version == "True": if not self.config['updates']['install_updates']: self.logger.info("New Version of pyLoad available") -- cgit v1.2.3 From f7563727e1ccb8d764904806cb9e262ba555f824 Mon Sep 17 00:00:00 2001 From: spoob Date: Mon, 30 Nov 2009 15:18:04 +0100 Subject: Cleaned XMLRPC in Core --- pyLoadCore.py | 92 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index be9232300..add30126b 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -134,17 +134,18 @@ class Core(object): self.check_update() - self.logger.info(_("Downloadtime: %s") % self.is_time_download()) # debug only - path.append(self.plugin_folder) self.create_plugin_index() - self.init_server() - + self.server_methods = ServerMethods(self) self.file_list = File_List(self) self.thread_list = Thread_List(self) - self.read_url_list(self.config['general']['link_file']) + self.init_server() + + self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only + + self.server_methods.read_url_list(self.config['general']['link_file']) while True: sleep(2) @@ -165,21 +166,8 @@ class Core(object): self.server = Server.SimpleXMLRPCServer(server_addr) self.logger.info("Normal XMLRPC Server Started") - self.server.register_introspection_functions() - self.server.register_function(self.status_downloads) - self.server.register_function(self.status_server) - self.server.register_function(self.kill) - self.server.register_function(self.del_links) - self.server.register_function(self.del_packages) - self.server.register_function(self.add_urls) - self.server.register_function(self.get_queue) - #self.server.register_function(self.move_urls_up) - #self.server.register_function(self.move_urls_down) - self.server.register_function(self.is_time_download) - self.server.register_function(self.is_time_reconnect) - self.server.register_function(self.get_conf_val) - self.server.register_function(self.file_exists) - self.server.register_function(self.get_server_version) + self.server.register_instance(self.server_methods) + thread.start_new_thread(self.server.serve_forever, ()) except Exception, e: self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) @@ -275,10 +263,14 @@ class Core(object): #################################### ########## XMLRPC Methods ########## #################################### - + +class ServerMethods(): + def __init__(self, core): + self.core = core + def status_downloads(self): downloads = [] - for pyfile in self.thread_list.py_downloading: + for pyfile in self.core.thread_list.py_downloading: download = {} download['id'] = pyfile.id download['name'] = pyfile.status.filename @@ -295,17 +287,17 @@ class Core(object): def get_conf_val(self, cat, var): if var != "username" and var != "password": - return self.config[cat][var] + return self.core.config[cat][var] else: raise Exception("not allowed!") def status_server(self): status = {} - status['pause'] = self.thread_list.pause - status['queue'] = len(self.file_list.files) + status['pause'] = self.core.thread_list.pause + status['queue'] = len(self.core.file_list.files) status['speed'] = 0 - for pyfile in self.thread_list.py_downloading: + for pyfile in self.core.thread_list.py_downloading: status['speed'] += pyfile.status.get_speed() return status @@ -318,29 +310,29 @@ class Core(object): def add_urls(self, links): for link in links: - self.file_list.collector.addLink(link) - self.file_list.save() + self.core.file_list.collector.addLink(link) + self.core.file_list.save() def del_links(self, ids): for id in ids: try: - self.file_list.collector.removeFile(id) + self.core.file_list.collector.removeFile(id) except: - self.file_list.packages.removeFile(id) - self.file_list.save() + self.core.file_list.packages.removeFile(id) + self.core.file_list.save() def del_packages(self, ids): for id in ids: - self.file_list.packages.removePackage(id) - self.file_list.save() + self.core.file_list.packages.removePackage(id) + self.core.file_list.save() def kill(self): - self.do_kill = True + self.core.do_kill = True return True def get_queue(self): data = [] - for q in self.file_list.data["queue"]: + for q in self.core.file_list.data["queue"]: ds = { "id": q.data.id, "name": q.data.package_name, @@ -358,7 +350,7 @@ class Core(object): def get_collector_packages(self): data = [] - for q in self.file_list.data["packages"]: + for q in self.core.file_list.data["packages"]: ds = { "id": q.data.id, "name": q.data.package_name, @@ -376,42 +368,42 @@ class Core(object): #def move_urls_up(self, ids): # for id in ids: - # self.file_list.move(id) - # self.file_list.save() + # self.core.file_list.move(id) + # self.core.file_list.save() #def move_urls_down(self, ids): # for id in ids: - # self.file_list.move(id, 1) - # self.file_list.save() + # self.core.file_list.move(id, 1) + # self.core.file_list.save() def read_url_list(self, url_list): """read links from txt""" - txt = open(self.config['general']['link_file'], 'r') + txt = open(self.core.config['general']['link_file'], 'r') new_links = 0 links = txt.readlines() for link in links: if link != "\n": - self.file_list.collector.addLink(link) + self.core.file_list.collector.addLink(link) new_links += 1 txt.close() - self.file_list.save() + self.core.file_list.save() if new_links: - self.logger.info("Parsed link from %s: %i" % (self.config['general']['link_file'], new_links)) + self.core.logger.info("Parsed link from %s: %i" % (self.core.config['general']['link_file'], new_links)) - txt = open(self.config['general']['link_file'], 'w') + txt = open(self.core.config['general']['link_file'], 'w') txt.write("") txt.close() def is_time_download(self): - start = self.config['downloadTime']['start'].split(":") - end = self.config['downloadTime']['end'].split(":") - return self.compare_time(start, end) + start = self.core.config['downloadTime']['start'].split(":") + end = self.core.config['downloadTime']['end'].split(":") + return self.core.compare_time(start, end) def is_time_reconnect(self): - start = self.config['reconnectTime']['start'].split(":") - end = self.config['reconnectTime']['end'].split(":") + start = self.core.config['reconnectTime']['start'].split(":") + end = self.core.config['reconnectTime']['end'].split(":") return self.compare_time(start, end) if __name__ == "__main__": -- cgit v1.2.3 From f3c2e597ebb63094c43ec39acb67a23a1cc2c141 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 30 Nov 2009 17:47:42 +0100 Subject: added xmlrpc auth without ssl --- pyLoadCore.py | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index add30126b..1f048c268 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -145,32 +145,54 @@ class Core(object): self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only - self.server_methods.read_url_list(self.config['general']['link_file']) + self.read_url_list(self.config['general']['link_file']) while True: sleep(2) if self.do_kill: self.logger.info("pyLoad quits") exit() + + def read_url_list(self, url_list): + """read links from txt""" + txt = open(url_list, 'r') + new_links = 0 + links = txt.readlines() + for link in links: + if link != "\n": + self.file_list.collector.addLink(link) + new_links += 1 + + txt.close() + + self.file_list.save() + if new_links: + self.logger.info("Parsed link from %s: %i" % (url_list, new_links)) + + txt = open(url_list, 'w') + txt.write("") + txt.close() 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']} + Server = __import__("module.remote.SecureXMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) if self.config['ssl']['activated']: - Server = __import__("module.remote.SecureXMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) self.server = Server.SecureXMLRPCServer(server_addr, self.config['ssl']['cert'], self.config['ssl']['key'], usermap) self.logger.info("Secure XMLRPC Server Started") else: - Server = __import__("SimpleXMLRPCServer") - self.server = Server.SimpleXMLRPCServer(server_addr) - self.logger.info("Normal XMLRPC Server Started") + self.server = Server.AuthXMLRPCServer(server_addr, usermap) + self.logger.info("Auth XMLRPC Server Started") self.server.register_instance(self.server_methods) thread.start_new_thread(self.server.serve_forever, ()) except Exception, e: self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) + if self.config['general']['debug_mode']: + import traceback + traceback.print_exc() def init_logger(self, level): @@ -375,26 +397,6 @@ class ServerMethods(): # for id in ids: # self.core.file_list.move(id, 1) # self.core.file_list.save() - - def read_url_list(self, url_list): - """read links from txt""" - txt = open(self.core.config['general']['link_file'], 'r') - new_links = 0 - links = txt.readlines() - for link in links: - if link != "\n": - self.core.file_list.collector.addLink(link) - new_links += 1 - - txt.close() - - self.core.file_list.save() - if new_links: - self.core.logger.info("Parsed link from %s: %i" % (self.core.config['general']['link_file'], new_links)) - - txt = open(self.core.config['general']['link_file'], 'w') - txt.write("") - txt.close() def is_time_download(self): start = self.core.config['downloadTime']['start'].split(":") -- cgit v1.2.3 From 0511d85691e8cf1c0c70045cf23e8abc6fc7cf40 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 30 Nov 2009 19:24:07 +0100 Subject: WIP: package system for cli --- pyLoadCore.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 1f048c268..6532e5b91 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -335,6 +335,20 @@ class ServerMethods(): self.core.file_list.collector.addLink(link) self.core.file_list.save() + def new_package(self, name): + id = self.core.file_list.packager.addNewPackage(name) + self.core.file_list.save() + return id + + def get_package_data(self, id): + return self.core.file_list.packager.getPackageData(id) + + def get_package_files(self, id): + return self.core.file_list.packager.getPackageFiles(id) + + def get_file_info(self, id): + return self.core.file_list.getFileInfo(id) + def del_links(self, ids): for id in ids: try: @@ -370,7 +384,7 @@ class ServerMethods(): data.append(ds) return data - def get_collector_packages(self): + def get_packages_collector(self): data = [] for q in self.core.file_list.data["packages"]: ds = { @@ -388,6 +402,12 @@ class ServerMethods(): data.append(ds) return data + def get_collector_files(self): + files = [] + for f in self.core.file_list.data["collector"]: + files.append(f.id) + return files + #def move_urls_up(self, ids): # for id in ids: # self.core.file_list.move(id) -- cgit v1.2.3 From 7caec14b0a307df9f2bd9ea6a9db6977a836145b Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 30 Nov 2009 21:25:33 +0100 Subject: WIP: package system second draft - unstable --- pyLoadCore.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 6532e5b91..39f440442 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -384,22 +384,10 @@ class ServerMethods(): data.append(ds) return data - def get_packages_collector(self): + def get_collector_packages(self): data = [] for q in self.core.file_list.data["packages"]: - ds = { - "id": q.data.id, - "name": q.data.package_name, - "folder": q.data.folder, - "files": [] - } - for f in q.links: - ds["files"].append({ - "name": f.status.name, - "status": f.status.type, - "url": f.url - }) - data.append(ds) + data.append(q.data) return data def get_collector_files(self): @@ -407,6 +395,18 @@ class ServerMethods(): for f in self.core.file_list.data["collector"]: files.append(f.id) return files + + def move_file_2_package(self, fid, pid): + try: + pyfile = self.core.file_list.collector.getFile(fid) + self.core.file_list.packager.addFileToPackage(pid, pyfile) + except: + return + else: + self.core.file_list.collector.removeFile(fid) + + def push_package_2_queue(self, id): + self.core.file_list.packager.pushPackage2Queue(id) #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From 9ecbb58e7ea06cb604745e25627e2fb4709fa442 Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 2 Dec 2009 15:37:25 +0100 Subject: New Update Function, pycurl able to just load headers, little fixes --- pyLoadCore.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 39f440442..b78cf5b5c 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -46,14 +46,10 @@ from time import sleep import urllib2 from imp import find_module from re import sub -try: - find_module("Crypto") -except ImportError: - print "Install pycrypto to use pyLoad" - exit() from module.file_list import File_List from module.thread_list import Thread_List from module.network.Request import Request +import module.remote.SecureXMLRPCServer as Server import thread class Core(object): @@ -116,6 +112,7 @@ class Core(object): translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) + self.check_install("Crypto", "pycrypto to decode container files") self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) @@ -177,7 +174,6 @@ class Core(object): try: server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) usermap = { self.config['remote']['username']: self.config['remote']['password']} - Server = __import__("module.remote.SecureXMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) 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") @@ -244,19 +240,31 @@ class Core(object): def check_update(self): """checks newst version""" - if not self.config['updates']['search_updates']: - return False - - newst_version = Request().load("http://update.pyload.org/s/" + CURRENT_VERSION) - if newst_version == "True": - if not self.config['updates']['install_updates']: - self.logger.info("New Version of pyLoad available") + if self.config['updates']['search_updates']: + version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" %(CURRENT_VERSION, self.config['updates']['install_updates'])) + if version_check == "": + self.logger.info("No Updates for pyLoad") + return False else: - updater = __import__("pyLoadUpdater") - updater.main() + if self.config['updates']['install_updates']: + try: + tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name + 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/") + return True + + except: + self.logger.info("Auto install Faild") + return False + + else: + self.logger.info("New pyLoad Version %s available" % version_check) + return True else: - self.logger.info("No Updates for pyLoad") - + return False + def create_plugin_index(self): for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): plugin_pattern = "" -- cgit v1.2.3 From 106e79456886563e4ee4ed43027bc69984f65928 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 2 Dec 2009 20:36:43 +0100 Subject: new bottle.py, re implemented webserver(not ready yet) --- pyLoadCore.py | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b78cf5b5c..fc050a309 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -46,10 +46,15 @@ from time import sleep import urllib2 from imp import find_module from re import sub +try: + find_module("Crypto") +except ImportError: + print "Install pycrypto to use pyLoad" + exit() from module.file_list import File_List from module.thread_list import Thread_List from module.network.Request import Request -import module.remote.SecureXMLRPCServer as Server +from module.web import WebServer import thread class Core(object): @@ -112,7 +117,6 @@ class Core(object): translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) - self.check_install("Crypto", "pycrypto to decode container files") self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) @@ -140,6 +144,8 @@ class Core(object): self.init_server() + self.init_webserver() + self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only self.read_url_list(self.config['general']['link_file']) @@ -174,6 +180,7 @@ class Core(object): try: server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) usermap = { self.config['remote']['username']: self.config['remote']['password']} + Server = __import__("module.remote.SecureXMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) 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") @@ -240,31 +247,19 @@ class Core(object): def check_update(self): """checks newst version""" - if self.config['updates']['search_updates']: - version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" %(CURRENT_VERSION, self.config['updates']['install_updates'])) - if version_check == "": - self.logger.info("No Updates for pyLoad") - return False + if not self.config['updates']['search_updates']: + return False + + newst_version = Request().load("http://update.pyload.org/s/" + CURRENT_VERSION) + if newst_version == "True": + if not self.config['updates']['install_updates']: + self.logger.info("New Version of pyLoad available") else: - if self.config['updates']['install_updates']: - try: - tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name - 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/") - return True - - except: - self.logger.info("Auto install Faild") - return False - - else: - self.logger.info("New pyLoad Version %s available" % version_check) - return True + updater = __import__("pyLoadUpdater") + updater.main() else: - return False - + self.logger.info("No Updates for pyLoad") + def create_plugin_index(self): for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): plugin_pattern = "" @@ -289,7 +284,15 @@ class Core(object): elif start > end and (now > start or now < end): return True elif start < now and end < now and start > end: return True else: return False - + + + def init_webserver(self): + self.webserver = WebServer.WebServer(self) + if self.config['webinterface']['activated']: + self.webserver.start() + + + #################################### ########## XMLRPC Methods ########## #################################### @@ -436,6 +439,8 @@ class ServerMethods(): end = self.core.config['reconnectTime']['end'].split(":") return self.compare_time(start, end) + + if __name__ == "__main__": pyload_core = Core() try: -- cgit v1.2.3 From a2e0413bc50ebdab023c2dbb71f55487bdca7447 Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 2 Dec 2009 23:02:59 +0100 Subject: Better Update System --- pyLoadCore.py | 57 ++++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index fc050a309..b78cf5b5c 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -46,15 +46,10 @@ from time import sleep import urllib2 from imp import find_module from re import sub -try: - find_module("Crypto") -except ImportError: - print "Install pycrypto to use pyLoad" - exit() from module.file_list import File_List from module.thread_list import Thread_List from module.network.Request import Request -from module.web import WebServer +import module.remote.SecureXMLRPCServer as Server import thread class Core(object): @@ -117,6 +112,7 @@ class Core(object): translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) + self.check_install("Crypto", "pycrypto to decode container files") self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) @@ -144,8 +140,6 @@ class Core(object): self.init_server() - self.init_webserver() - self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only self.read_url_list(self.config['general']['link_file']) @@ -180,7 +174,6 @@ class Core(object): try: server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) usermap = { self.config['remote']['username']: self.config['remote']['password']} - Server = __import__("module.remote.SecureXMLRPCServer", globals(), locals(), "SecureXMLRPCServer", -1) 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") @@ -247,19 +240,31 @@ class Core(object): def check_update(self): """checks newst version""" - if not self.config['updates']['search_updates']: - return False - - newst_version = Request().load("http://update.pyload.org/s/" + CURRENT_VERSION) - if newst_version == "True": - if not self.config['updates']['install_updates']: - self.logger.info("New Version of pyLoad available") + if self.config['updates']['search_updates']: + version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" %(CURRENT_VERSION, self.config['updates']['install_updates'])) + if version_check == "": + self.logger.info("No Updates for pyLoad") + return False else: - updater = __import__("pyLoadUpdater") - updater.main() + if self.config['updates']['install_updates']: + try: + tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name + 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/") + return True + + except: + self.logger.info("Auto install Faild") + return False + + else: + self.logger.info("New pyLoad Version %s available" % version_check) + return True else: - self.logger.info("No Updates for pyLoad") - + return False + def create_plugin_index(self): for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): plugin_pattern = "" @@ -284,15 +289,7 @@ class Core(object): elif start > end and (now > start or now < end): return True elif start < now and end < now and start > end: return True else: return False - - - def init_webserver(self): - self.webserver = WebServer.WebServer(self) - if self.config['webinterface']['activated']: - self.webserver.start() - - - + #################################### ########## XMLRPC Methods ########## #################################### @@ -439,8 +436,6 @@ class ServerMethods(): end = self.core.config['reconnectTime']['end'].split(":") return self.compare_time(start, end) - - if __name__ == "__main__": pyload_core = Core() try: -- cgit v1.2.3 From a649d73a1bd2a9b45eb35d535d40e2454238417c Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 3 Dec 2009 18:10:48 +0100 Subject: little webinterface fixes --- pyLoadCore.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b78cf5b5c..7218586e0 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -23,7 +23,6 @@ """ CURRENT_VERSION = '0.3' - import ConfigParser import gettext from glob import glob @@ -43,13 +42,14 @@ from sys import path from sys import stdout import time from time import sleep -import urllib2 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 class Core(object): @@ -113,6 +113,7 @@ class Core(object): translation.install(unicode=True) self.check_install("Crypto", "pycrypto to decode container files") + self.check_install("Image", "Python Image Libary (PIL) for captha reading") self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) @@ -139,6 +140,7 @@ class Core(object): self.thread_list = Thread_List(self) self.init_server() + self.init_webserver() self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only @@ -290,6 +292,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() #################################### ########## XMLRPC Methods ########## #################################### @@ -324,7 +330,7 @@ class ServerMethods(): def status_server(self): status = {} status['pause'] = self.core.thread_list.pause - status['queue'] = len(self.core.file_list.files) + status['queue'] = len(self.core.file_list.data['queue']) status['speed'] = 0 for pyfile in self.core.thread_list.py_downloading: @@ -343,6 +349,17 @@ class ServerMethods(): self.core.file_list.collector.addLink(link) self.core.file_list.save() + 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) + + self.push_package_2_queue(pid) + def new_package(self, name): id = self.core.file_list.packager.addNewPackage(name) self.core.file_list.save() -- cgit v1.2.3 From 21e4a31c9da1d0f6bcd8672a3df8c90b64f28f8e Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 3 Dec 2009 18:15:21 +0100 Subject: improved read_url_list --- pyLoadCore.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 7218586e0..075b2e2f9 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -157,13 +157,16 @@ class Core(object): txt = open(url_list, 'r') new_links = 0 links = txt.readlines() + pid = self.file_list.packager.addNewPackage(package_name="links.txt") for link in links: if link != "\n": - self.file_list.collector.addLink(link) + lid = self.file_list.collector.addLink(link) + self.file_list.packager.addFileToPackage(pid, fl.collector.popFile(lid)) new_links += 1 txt.close() - + + self.file_list.packager.pushPackage2Queue(pid) self.file_list.save() if new_links: self.logger.info("Parsed link from %s: %i" % (url_list, new_links)) -- cgit v1.2.3 From 8e3759edefbb7a36b0024a89eee45461c2f449e9 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 3 Dec 2009 21:31:26 +0100 Subject: base for new gui --- pyLoadCore.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 075b2e2f9..e66e29c15 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -166,10 +166,12 @@ class Core(object): txt.close() - self.file_list.packager.pushPackage2Queue(pid) - self.file_list.save() if new_links: self.logger.info("Parsed link from %s: %i" % (url_list, new_links)) + self.file_list.packager.pushPackage2Queue(pid) + else: + self.file_list.packager.removePackage(pid) + self.file_list.save() txt = open(url_list, 'w') txt.write("") @@ -397,19 +399,7 @@ class ServerMethods(): def get_queue(self): data = [] for q in self.core.file_list.data["queue"]: - ds = { - "id": q.data.id, - "name": q.data.package_name, - "folder": q.data.folder, - "files": [] - } - for f in q.links: - ds["files"].append({ - "name": f.status.name, - "status": f.status.type, - "url": f.url - }) - data.append(ds) + data.append(q.data) return data def get_collector_packages(self): -- cgit v1.2.3 From f98a9eea978ccf56d41f4ce355f2b514fc9e4af1 Mon Sep 17 00:00:00 2001 From: spoob Date: Thu, 3 Dec 2009 23:33:46 +0100 Subject: Convert read_url_list to new Plugin --- pyLoadCore.py | 116 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 60 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index e66e29c15..eedb547bf 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -47,7 +47,7 @@ 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 +#~ from module.web.WebServer import WebServer import module.remote.SecureXMLRPCServer as Server import thread @@ -130,7 +130,6 @@ class Core(object): else: self.init_logger(logging.INFO) # logging level - self.check_update() path.append(self.plugin_folder) self.create_plugin_index() @@ -139,44 +138,27 @@ class Core(object): self.file_list = File_List(self) self.thread_list = Thread_List(self) + self.server_methods.check_update() + self.init_server() - self.init_webserver() + #~ self.init_webserver() # start webinterface like cli, gui etc + self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only - self.read_url_list(self.config['general']['link_file']) - + #read url list @mkaay: pid, lid? + linkFile = self.config['general']['link_file'] + pid = self.file_list.packager.addNewPackage(package_name=linkFile) + lid = self.file_list.collector.addLink(linkFile) + self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) + self.file_list.packager.pushPackage2Queue(pid) + while True: sleep(2) if self.do_kill: self.logger.info("pyLoad quits") exit() - - def read_url_list(self, url_list): - """read links from txt""" - txt = open(url_list, 'r') - new_links = 0 - links = txt.readlines() - pid = self.file_list.packager.addNewPackage(package_name="links.txt") - for link in links: - if link != "\n": - lid = self.file_list.collector.addLink(link) - self.file_list.packager.addFileToPackage(pid, fl.collector.popFile(lid)) - new_links += 1 - - txt.close() - - if new_links: - self.logger.info("Parsed link from %s: %i" % (url_list, new_links)) - self.file_list.packager.pushPackage2Queue(pid) - else: - self.file_list.packager.removePackage(pid) - self.file_list.save() - txt = open(url_list, 'w') - txt.write("") - txt.close() - def init_server(self): try: server_addr = (self.config['remote']['listenaddr'], int(self.config['remote']['port'])) @@ -244,34 +226,20 @@ class Core(object): print _("could not find %s: %s") % (legend, check_name) if essential and not created: exit() - - def check_update(self): - """checks newst version""" - if self.config['updates']['search_updates']: - version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" %(CURRENT_VERSION, self.config['updates']['install_updates'])) - if version_check == "": - self.logger.info("No Updates for pyLoad") - return False - else: - if self.config['updates']['install_updates']: - try: - tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name - 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/") - return True - except: - self.logger.info("Auto install Faild") - return False + def restart(self): + pass + + #~ def update(self, file_update=None): + #~ try: + #~ if not file_update: + #~ tmp_zip = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name + #~ file_update = Request().download("http://update.pyload.org/index.php?download=True", tmp_zip) + #~ __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip,"Test/") + #~ self.logger.info(_("Updated pyLoad")) + #~ except: + #~ self.logger.info("Error on updating pyLoad") - else: - self.logger.info("New pyLoad Version %s available" % version_check) - return True - else: - return False - def create_plugin_index(self): for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): plugin_pattern = "" @@ -297,10 +265,11 @@ 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 ########## #################################### @@ -309,6 +278,33 @@ class ServerMethods(): def __init__(self, core): self.core = core + 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'])) + if version_check == "": + self.core.logger.info("No Updates for pyLoad") + return False + else: + if self.core.config['updates']['install_updates']: + try: + tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name + 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/") + return True + + except: + self.logger.core.info("Auto install Faild") + return False + + else: + self.core.logger.info("New pyLoad Version %s available" % version_check) + return True + else: + return False + def status_downloads(self): downloads = [] for pyfile in self.core.thread_list.py_downloading: -- cgit v1.2.3 From a6c7715dfb4946a4a25edd4f8bc3cc2e2249e4f9 Mon Sep 17 00:00:00 2001 From: spoob Date: Sat, 5 Dec 2009 20:31:00 +0100 Subject: No OpenSSL needed to run --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index eedb547bf..e97b1fcaf 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -122,6 +122,7 @@ class Core(object): self.check_file(self.config['general']['link_file'], _("file for links"), False) self.check_file(self.config['general']['failed_file'], _("file for failed links"), False) if self.config['ssl']['activated']: + self.check_install("OpenSSL", "OpenSLL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, False, True) self.check_file(self.config['ssl']['key'], _("ssl key"), False, False, True) -- cgit v1.2.3 From 2c7203032324820c122b1e7b77604212391f75f9 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 10 Dec 2009 15:44:37 +0100 Subject: cleaned some code, pyLoad Script Support (closed #16) --- pyLoadCore.py | 61 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 25 deletions(-) (limited to 'pyLoadCore.py') 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): -- cgit v1.2.3 From 6fdfdd1f85b0e2d95bdc8955459c0465833831d6 Mon Sep 17 00:00:00 2001 From: spoob Date: Thu, 10 Dec 2009 21:38:03 +0100 Subject: create automatic script folders --- pyLoadCore.py | 97 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 39 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index d78a195da..d806696ff 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -32,6 +32,7 @@ import logging.handlers from os import chdir from os import listdir from os import mkdir +from os import makedirs from os import sep from os.path import abspath from os.path import basename @@ -118,33 +119,34 @@ class Core(object): self.check_install("pycurl", "pycurl for lower memory footprint while downloading") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) - self.check_file(self.config['log']['log_folder'], _("folder for logs")) - self.check_file(self.config['general']['download_folder'], _("folder for downloads")) - self.check_file(self.config['general']['link_file'], _("file for links"), False) - self.check_file(self.config['general']['failed_file'], _("file for failed links"), False) + self.check_file(self.config['log']['log_folder'], _("folder for logs"), True) + self.check_file(self.config['general']['download_folder'], _("folder for downloads"), True) + self.check_file(self.config['general']['link_file'], _("file for links")) + self.check_file(self.config['general']['failed_file'], _("file for failed links")) + script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] + self.check_file(script_folders, _("folders for scripts"), True) if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSLL for secure connection", True) - self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, False, True) - self.check_file(self.config['ssl']['key'], _("ssl key"), False, False, True) + self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) + self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) if self.config['general']['debug_mode']: self.init_logger(logging.DEBUG) # logging level else: self.init_logger(logging.INFO) # logging level - - self.init_scripts() + 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 @@ -201,16 +203,18 @@ class Core(object): def init_scripts(self): - """ scan directory for scripts to execute""" + """ 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)) + 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'))) + for script_type, script_name in self.scripts.iteritems(): + if script_name != []: + self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name))) def check_install(self, check_name, legend, python=True, essential=False): """check wether needed tools are installed""" @@ -224,24 +228,39 @@ class Core(object): print "Install", legend if essential: exit() - def check_file(self, check_name, legend, folder=True, empty=True, essential=False): + def check_file(self, check_names, description="", folder=False, empty=True, essential=False): """check wether needed files are exists""" - if not exists(check_name): - created = False - if empty: - try: - if folder: - mkdir(check_name) - else: - open(check_name, "w") - print _("%s created") % legend - created = True - except: - print _("could not create %s: %s") % (legend, check_name) + tmp_names = [] + if not type(check_names) == list: + tmp_names.append(check_names) + else: + tmp_names.extend(check_names) + file_created = True + file_exists = True + for tmp_name in tmp_names: + if not exists(tmp_name): + file_exists = False + if empty: + try: + if folder: + tmp_name = tmp_name.replace("/", sep) + makedirs(tmp_name) + else: + open(tmp_name, "w") + except: + file_created = False + else: + file_created = False + if not file_exists: + if file_created: + print _("%s created") % description else: - print _("could not find %s: %s") % (legend, check_name) - if essential and not created: - exit() + if not empty: + print _("could not find %s: %s") % (description, tmp_name) + else: + print _("could not create %s: %s") % (description, tmp_name) + if essential: + exit() def restart(self): pass @@ -281,10 +300,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 ########## -- cgit v1.2.3 From 95d09b338ac7aed2b387bf143a5cfd1c4b29f612 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 15 Dec 2009 17:48:30 +0100 Subject: new Django webinterface(in development), small fixes --- pyLoadCore.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index d806696ff..b39f2b667 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -38,6 +38,7 @@ from os.path import abspath from os.path import basename from os.path import dirname from os.path import exists +from os.path import join from re import sub import subprocess from sys import argv @@ -52,7 +53,7 @@ from module.file_list import File_List from module.network.Request import Request import module.remote.SecureXMLRPCServer as Server from module.thread_list import Thread_List -from module.web.WebServer import WebServer +from module.web.ServerThread import WebServer class Core(object): """ pyLoad Core """ @@ -65,7 +66,7 @@ class Core(object): def read_config(self): """ read config and sets preferences """ self.configfile = ConfigParser.SafeConfigParser() - self.configfile.read('config') + self.configfile.read(join(self.path,'config')) for section in self.configfile.sections(): self.config[section] = {} for option in self.configfile.options(section): @@ -75,7 +76,7 @@ class Core(object): def set_option(self, section, option, value): self.config[option] = value self.configfile.set(section, option, str(value)) - self.configfile.write(open('config', "wb")) + self.configfile.write(open(join(self.path,'config'), "wb")) def read_option(self): return self.config @@ -102,7 +103,7 @@ class Core(object): def start(self): """ starts the machine""" - chdir(dirname(abspath(__file__)) + sep) + self.path = dirname(__file__) self.config = {} self.plugin_folder = "module" + sep + "plugins" @@ -117,6 +118,7 @@ class Core(object): self.check_install("Crypto", "pycrypto to decode container files") self.check_install("Image", "Python Image Libary (PIL) for captha reading") self.check_install("pycurl", "pycurl for lower memory footprint while downloading") + self.check_install("django", "Django for webinterface") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) self.check_file(self.config['log']['log_folder'], _("folder for logs"), True) @@ -146,7 +148,7 @@ class Core(object): 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 @@ -184,18 +186,27 @@ class Core(object): import traceback traceback.print_exc() + + def init_webserver(self): + if self.config['webinterface']['activated']: + self.webserver = WebServer(self) + self.webserver.start() + + def init_logger(self, level): - file_handler = logging.handlers.RotatingFileHandler(self.config['log']['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log']['log_count'])) #100 kib each + console = logging.StreamHandler(stdout) frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") - file_handler.setFormatter(frm) + console.setFormatter(frm) self.logger = logging.getLogger("log") # settable in config if self.config['log']['file_log']: + file_handler = logging.handlers.RotatingFileHandler(self.config['log']['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log']['log_count'])) #100 kib each + file_handler.setFormatter(frm) self.logger.addHandler(file_handler) self.logger.addHandler(console) #if console logging @@ -206,7 +217,7 @@ class Core(object): """ scan directory for scripts to execute""" f = lambda x: False if x.startswith("#") or x.endswith("~") else True self.scripts = {} - + #@TODO: windows save?! 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'))) -- cgit v1.2.3 From 4e86c166dc20a8f4d1000e65120508c425f5b794 Mon Sep 17 00:00:00 2001 From: spoob Date: Tue, 15 Dec 2009 22:47:26 +0100 Subject: Fixed LinkList.py and .part renaming --- pyLoadCore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b39f2b667..72f938c37 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -106,9 +106,10 @@ class Core(object): self.path = dirname(__file__) self.config = {} - self.plugin_folder = "module" + sep + "plugins" self.plugins_avaible = {} + self.plugin_folder = join("module", "plugins") + self.read_config() self.do_kill = False @@ -148,7 +149,7 @@ class Core(object): 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 -- cgit v1.2.3 From f89a0fcfbcca01067175ba7a67c14eb95bd60d6f Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 16 Dec 2009 17:13:46 +0100 Subject: gui server status --- pyLoadCore.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 72f938c37..3d399a0c2 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -129,7 +129,7 @@ class Core(object): script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] self.check_file(script_folders, _("folders for scripts"), True) if self.config['ssl']['activated']: - self.check_install("OpenSSL", "OpenSLL for secure connection", True) + self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) @@ -155,6 +155,8 @@ class Core(object): self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only #read url list @mkaay: pid, lid? + # pid = package id + # lid = link/file id linkFile = self.config['general']['link_file'] pid = self.file_list.packager.addNewPackage(package_name=linkFile) lid = self.file_list.collector.addLink(linkFile) @@ -195,14 +197,9 @@ class Core(object): def init_logger(self, level): - - console = logging.StreamHandler(stdout) - frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") - console.setFormatter(frm) - self.logger = logging.getLogger("log") # settable in config if self.config['log']['file_log']: @@ -378,7 +375,7 @@ class ServerMethods(): def status_server(self): status = {} status['pause'] = self.core.thread_list.pause - status['queue'] = len(self.core.file_list.data['queue']) + status['queue'] = self.core.file_list.countDownloads() status['speed'] = 0 for pyfile in self.core.thread_list.py_downloading: -- cgit v1.2.3 From 1a073d1f8e249dc3428632ba67b96024a4f1eb50 Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 16 Dec 2009 17:42:17 +0100 Subject: fixed speed display, optimized some code --- pyLoadCore.py | 1 - 1 file changed, 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 3d399a0c2..fa9eb3d85 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -362,7 +362,6 @@ class ServerMethods(): download['percent'] = pyfile.status.percent() download['status'] = pyfile.status.type download['wait_until'] = pyfile.status.waituntil - download['plugin'] = pyfile.status.plugin downloads.append(download) return downloads -- cgit v1.2.3 From 3db583f5f10a72e53ecd8d282ec5db1e3f4cd4dd Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 16 Dec 2009 22:49:20 +0100 Subject: Webinterface authsystem --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index fa9eb3d85..ee8cd8109 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -375,6 +375,7 @@ class ServerMethods(): status = {} status['pause'] = self.core.thread_list.pause status['queue'] = self.core.file_list.countDownloads() + status['total'] = len(self.core.file_list.data['queue']) status['speed'] = 0 for pyfile in self.core.thread_list.py_downloading: -- cgit v1.2.3 From aea618c1bffe9ea6eb44b8555f17349b39dfe22b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 16 Dec 2009 23:45:21 +0100 Subject: new functions for interacting with core --- pyLoadCore.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index ee8cd8109..c5be49c1a 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -122,12 +122,16 @@ class Core(object): self.check_install("django", "Django for webinterface") self.check_install("tesseract", "tesseract for captcha reading", False) self.check_install("gocr", "gocr for captcha reading", False) + self.check_file(self.config['log']['log_folder'], _("folder for logs"), True) self.check_file(self.config['general']['download_folder'], _("folder for downloads"), True) self.check_file(self.config['general']['link_file'], _("file for links")) self.check_file(self.config['general']['failed_file'], _("file for failed links")) - script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] + + script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] # @TODO: windows save? + self.check_file(script_folders, _("folders for scripts"), True) + if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) @@ -371,6 +375,12 @@ class ServerMethods(): else: raise Exception("not allowed!") + def pause_server(self): + self.core.thread_list.pause = True + + def unpause_server(self): + self.core.thread_list.pause = False + def status_server(self): status = {} status['pause'] = self.core.thread_list.pause -- cgit v1.2.3 From 502a9567941d562883a9464555a64a40590d7eed Mon Sep 17 00:00:00 2001 From: spoob Date: Thu, 17 Dec 2009 15:30:25 +0100 Subject: Little Rapidshare Fix --- pyLoadCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index c5be49c1a..371c0d8fb 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -153,7 +153,7 @@ class Core(object): 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 -- cgit v1.2.3 From d08271cbb66f3ccbd8f3c5cf707008388ff4297e Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 21:33:13 +0100 Subject: new xml config for core --- pyLoadCore.py | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 371c0d8fb..7e1b9ebfc 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -23,7 +23,6 @@ """ CURRENT_VERSION = '0.3' -import ConfigParser import gettext from glob import glob from imp import find_module @@ -54,6 +53,7 @@ from module.network.Request import Request import module.remote.SecureXMLRPCServer as Server from module.thread_list import Thread_List from module.web.ServerThread import WebServer +from module.XMLConfigParser import XMLConfigParser class Core(object): """ pyLoad Core """ @@ -62,24 +62,6 @@ class Core(object): if argv[1] == "-v": print "pyLoad", CURRENT_VERSION exit() - - def read_config(self): - """ read config and sets preferences """ - self.configfile = ConfigParser.SafeConfigParser() - self.configfile.read(join(self.path,'config')) - for section in self.configfile.sections(): - self.config[section] = {} - for option in self.configfile.options(section): - self.config[section][option] = self.configfile.get(section, option) - self.config[section][option] = False if self.config[section][option].lower() == 'false' else self.config[section][option] - - def set_option(self, section, option, value): - self.config[option] = value - self.configfile.set(section, option, str(value)) - self.configfile.write(open(join(self.path,'config'), "wb")) - - def read_option(self): - return self.config def shutdown(self): "abort all downloads and exit" @@ -110,8 +92,9 @@ class Core(object): self.plugin_folder = join("module", "plugins") - self.read_config() - + self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) + self.config = self.xmlconfig.getConfig() + self.do_kill = False translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) -- cgit v1.2.3 From 70cd6a9f822308a416fefb051c4bbb83e6fd37e4 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 22:56:56 +0100 Subject: create only one links.txt package --- pyLoadCore.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 7e1b9ebfc..fc196c587 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -145,7 +145,19 @@ class Core(object): # pid = package id # lid = link/file id linkFile = self.config['general']['link_file'] - pid = self.file_list.packager.addNewPackage(package_name=linkFile) + packs = self.server_methods.get_queue() + found = False + print linkFile + for data in packs: + print data["package_name"] + if data["package_name"] == linkFile: + found = data["id"] + print "found", found + break + if found == False: + pid = self.file_list.packager.addNewPackage(package_name=linkFile) + else: + pid = found lid = self.file_list.collector.addLink(linkFile) self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) self.file_list.packager.pushPackage2Queue(pid) -- cgit v1.2.3 From 2f3cc86bc06d55abc4f6fb55ee38eb5b83366335 Mon Sep 17 00:00:00 2001 From: spoob Date: Thu, 17 Dec 2009 23:10:14 +0100 Subject: Removed prints --- pyLoadCore.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index fc196c587..0a30c1849 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -147,12 +147,9 @@ class Core(object): linkFile = self.config['general']['link_file'] packs = self.server_methods.get_queue() found = False - print linkFile for data in packs: - print data["package_name"] if data["package_name"] == linkFile: found = data["id"] - print "found", found break if found == False: pid = self.file_list.packager.addNewPackage(package_name=linkFile) -- cgit v1.2.3 From a9a0ab594e4ea05532ff089b8eee7bf20ea571be Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 17 Dec 2009 23:52:22 +0100 Subject: new web JSON functions --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 0a30c1849..5550c9b9b 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -358,6 +358,7 @@ class ServerMethods(): download['percent'] = pyfile.status.percent() download['status'] = pyfile.status.type download['wait_until'] = pyfile.status.waituntil + download['package'] = pyfile.package.data["package_name"] downloads.append(download) return downloads -- cgit v1.2.3 From 1d7dc2ca5db0119e01547cd7b01fb77720450d1c Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 19 Dec 2009 00:26:38 +0100 Subject: cleaned --- pyLoadCore.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 5550c9b9b..7b7e2754d 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -28,12 +28,9 @@ 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 makedirs from os import sep -from os.path import abspath from os.path import basename from os.path import dirname from os.path import exists -- cgit v1.2.3 From adcc953b4dd2dce1f91bd7cd11105e9f0653f704 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 19 Dec 2009 15:13:10 +0100 Subject: fixed reconnect --- pyLoadCore.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 7b7e2754d..946df9915 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -306,11 +306,22 @@ class Core(object): #~ self.webserver = WebServer(self) #~ if self.config['webinterface']['activated']: #~ self.webserver.start() + + + def is_download_time(self): + start = self.core.config['downloadTime']['start'].split(":") + end = self.core.config['downloadTime']['end'].split(":") + return self.core.compare_time(start, end) + + def is_reconnect_time(self): + start = self.core.config['reconnectTime']['start'].split(":") + end = self.core.config['reconnectTime']['end'].split(":") + return self.compare_time(start, end) + #################################### ########## XMLRPC Methods ########## #################################### - class ServerMethods(): def __init__(self, core): self.core = core @@ -472,16 +483,6 @@ class ServerMethods(): # self.core.file_list.move(id, 1) # self.core.file_list.save() - def is_time_download(self): - start = self.core.config['downloadTime']['start'].split(":") - end = self.core.config['downloadTime']['end'].split(":") - return self.core.compare_time(start, end) - - def is_time_reconnect(self): - start = self.core.config['reconnectTime']['start'].split(":") - end = self.core.config['reconnectTime']['end'].split(":") - return self.compare_time(start, end) - if __name__ == "__main__": pyload_core = Core() try: -- cgit v1.2.3 From c521e6445bc8e6b91440813b90d1fdedd76c9721 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 19 Dec 2009 15:25:50 +0100 Subject: real reconnect fix ;-) --- pyLoadCore.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 946df9915..7b7e2754d 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -306,22 +306,11 @@ class Core(object): #~ self.webserver = WebServer(self) #~ if self.config['webinterface']['activated']: #~ self.webserver.start() - - - def is_download_time(self): - start = self.core.config['downloadTime']['start'].split(":") - end = self.core.config['downloadTime']['end'].split(":") - return self.core.compare_time(start, end) - - def is_reconnect_time(self): - start = self.core.config['reconnectTime']['start'].split(":") - end = self.core.config['reconnectTime']['end'].split(":") - return self.compare_time(start, end) - #################################### ########## XMLRPC Methods ########## #################################### + class ServerMethods(): def __init__(self, core): self.core = core @@ -483,6 +472,16 @@ class ServerMethods(): # self.core.file_list.move(id, 1) # self.core.file_list.save() + def is_time_download(self): + start = self.core.config['downloadTime']['start'].split(":") + end = self.core.config['downloadTime']['end'].split(":") + return self.core.compare_time(start, end) + + def is_time_reconnect(self): + start = self.core.config['reconnectTime']['start'].split(":") + end = self.core.config['reconnectTime']['end'].split(":") + return self.compare_time(start, end) + if __name__ == "__main__": pyload_core = Core() try: -- cgit v1.2.3 From 2b6db7950916f29eea39224104fed284ad4222c7 Mon Sep 17 00:00:00 2001 From: Wugy Date: Sat, 19 Dec 2009 17:14:05 +0100 Subject: active download list 40% --- pyLoadCore.py | 984 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 492 insertions(+), 492 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 7b7e2754d..3e6662d17 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -1,492 +1,492 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -""" - 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 of the License, - 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, see . - - @author: spoob - @author: sebnapi - @author: RaNaN - @author: mkaay - @version: v0.3 -""" - -CURRENT_VERSION = '0.3' -import gettext -from glob import glob -from imp import find_module -import logging -import logging.handlers -from os import listdir -from os import makedirs -from os import sep -from os.path import basename -from os.path import dirname -from os.path import exists -from os.path import join -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 module.file_list import File_List -from module.network.Request import Request -import module.remote.SecureXMLRPCServer as Server -from module.thread_list import Thread_List -from module.web.ServerThread import WebServer -from module.XMLConfigParser import XMLConfigParser - -class Core(object): - """ pyLoad Core """ - def __init__(self): - if len(argv) > 1: - if argv[1] == "-v": - print "pyLoad", CURRENT_VERSION - exit() - - def shutdown(self): - "abort all downloads and exit" - self.thread_list.pause = True - - for pyfile in self.thread_list.py_downloading: - pyfile.plugin.req.abort = True - - while self.thread_list.py_downloading: - sleep(1) - self.logger.info("Going to shutdown pyLoad") - exit() - - def toggle_pause(self): - if self.thread_list.pause: - self.thread_list.pause = False - return False - elif not self.thread_list.pause: - self.thread_list.pause = True - return True - - def start(self): - """ starts the machine""" - self.path = dirname(__file__) - - self.config = {} - self.plugins_avaible = {} - - self.plugin_folder = join("module", "plugins") - - self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) - self.config = self.xmlconfig.getConfig() - - self.do_kill = False - translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) - translation.install(unicode=True) - - self.check_install("Crypto", "pycrypto to decode container files") - self.check_install("Image", "Python Image Libary (PIL) for captha reading") - self.check_install("pycurl", "pycurl for lower memory footprint while downloading") - self.check_install("django", "Django for webinterface") - self.check_install("tesseract", "tesseract for captcha reading", False) - self.check_install("gocr", "gocr for captcha reading", False) - - self.check_file(self.config['log']['log_folder'], _("folder for logs"), True) - self.check_file(self.config['general']['download_folder'], _("folder for downloads"), True) - self.check_file(self.config['general']['link_file'], _("file for links")) - self.check_file(self.config['general']['failed_file'], _("file for failed links")) - - script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] # @TODO: windows save? - - self.check_file(script_folders, _("folders for scripts"), True) - - if self.config['ssl']['activated']: - self.check_install("OpenSSL", "OpenSSL for secure connection", True) - self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) - self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) - - if self.config['general']['debug_mode']: - self.init_logger(logging.DEBUG) # logging level - else: - self.init_logger(logging.INFO) # logging level - - self.init_scripts() - path.append(self.plugin_folder) - self.create_plugin_index() - - 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.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only - - #read url list @mkaay: pid, lid? - # pid = package id - # lid = link/file id - linkFile = self.config['general']['link_file'] - packs = self.server_methods.get_queue() - found = False - for data in packs: - if data["package_name"] == linkFile: - found = data["id"] - break - if found == False: - pid = self.file_list.packager.addNewPackage(package_name=linkFile) - else: - pid = found - lid = self.file_list.collector.addLink(linkFile) - self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) - self.file_list.packager.pushPackage2Queue(pid) - - while True: - sleep(2) - if self.do_kill: - self.logger.info("pyLoad quits") - exit() - - 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']} - 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") - else: - self.server = Server.AuthXMLRPCServer(server_addr, usermap) - self.logger.info("Auth XMLRPC Server Started") - - self.server.register_instance(self.server_methods) - - thread.start_new_thread(self.server.serve_forever, ()) - except Exception, e: - self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) - if self.config['general']['debug_mode']: - import traceback - traceback.print_exc() - - - def init_webserver(self): - if self.config['webinterface']['activated']: - self.webserver = WebServer(self) - self.webserver.start() - - - def init_logger(self, level): - console = logging.StreamHandler(stdout) - frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") - console.setFormatter(frm) - self.logger = logging.getLogger("log") # settable in config - - if self.config['log']['file_log']: - file_handler = logging.handlers.RotatingFileHandler(self.config['log']['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log']['log_count'])) #100 kib each - file_handler.setFormatter(frm) - self.logger.addHandler(file_handler) - - 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 = {} - #@TODO: windows save?! - 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'))) - - for script_type, script_name in self.scripts.iteritems(): - if script_name != []: - self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name))) - - def check_install(self, check_name, legend, python=True, essential=False): - """check wether needed tools are installed""" - try: - if python: - find_module(check_name) - else: - pipe = subprocess.PIPE - subprocess.Popen(check_name, stdout=pipe, stderr=pipe) - except: - print "Install", legend - if essential: exit() - - def check_file(self, check_names, description="", folder=False, empty=True, essential=False): - """check wether needed files are exists""" - tmp_names = [] - if not type(check_names) == list: - tmp_names.append(check_names) - else: - tmp_names.extend(check_names) - file_created = True - file_exists = True - for tmp_name in tmp_names: - if not exists(tmp_name): - file_exists = False - if empty: - try: - if folder: - tmp_name = tmp_name.replace("/", sep) - makedirs(tmp_name) - else: - open(tmp_name, "w") - except: - file_created = False - else: - file_created = False - if not file_exists: - if file_created: - print _("%s created") % description - else: - if not empty: - print _("could not find %s: %s") % (description, tmp_name) - else: - print _("could not create %s: %s") % (description, tmp_name) - if essential: - exit() - - def restart(self): - pass - - #~ def update(self, file_update=None): - #~ try: - #~ if not file_update: - #~ tmp_zip = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name - #~ file_update = Request().download("http://update.pyload.org/index.php?download=True", tmp_zip) - #~ __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip,"Test/") - #~ self.logger.info(_("Updated pyLoad")) - #~ except: - #~ self.logger.info("Error on updating pyLoad") - - def create_plugin_index(self): - for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): - plugin_pattern = "" - plugin_file = sub("(\.pyc|\.py)", "", basename(file_handler)) - if plugin_file == "DLC": - plugin_pattern = "(?!http://).*\.dlc" - else: - for line in open(file_handler, "r").readlines(): - if "props['pattern']" in line: - plugin_pattern = line.split("r\"")[1].split("\"")[0] - break - if plugin_pattern != "": - self.plugins_avaible[plugin_file] = plugin_pattern - self.logger.debug(plugin_file + _(" added")) - self.logger.info(_("created index of plugins")) - - def compare_time(self, start, end): - if start == end: return True - - now = time.localtime()[3:5] - if start < now and end > now: return True - elif start > end and (now > start or now < end): return True - 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() - - #################################### - ########## XMLRPC Methods ########## - #################################### - -class ServerMethods(): - def __init__(self, core): - self.core = core - - 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'])) - if version_check == "": - self.core.logger.info("No Updates for pyLoad") - return False - else: - if self.core.config['updates']['install_updates']: - try: - tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name - 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/") - return True - - except: - self.logger.core.info("Auto install Faild") - return False - - else: - self.core.logger.info("New pyLoad Version %s available" % version_check) - return True - else: - return False - - def status_downloads(self): - downloads = [] - for pyfile in self.core.thread_list.py_downloading: - download = {} - download['id'] = pyfile.id - download['name'] = pyfile.status.filename - download['speed'] = pyfile.status.get_speed() - download['eta'] = pyfile.status.get_ETA() - download['kbleft'] = pyfile.status.kB_left() - download['size'] = pyfile.status.size() - download['percent'] = pyfile.status.percent() - download['status'] = pyfile.status.type - download['wait_until'] = pyfile.status.waituntil - download['package'] = pyfile.package.data["package_name"] - downloads.append(download) - return downloads - - def get_conf_val(self, cat, var): - if var != "username" and var != "password": - return self.core.config[cat][var] - else: - raise Exception("not allowed!") - - def pause_server(self): - self.core.thread_list.pause = True - - def unpause_server(self): - self.core.thread_list.pause = False - - def status_server(self): - status = {} - status['pause'] = self.core.thread_list.pause - status['queue'] = self.core.file_list.countDownloads() - status['total'] = len(self.core.file_list.data['queue']) - status['speed'] = 0 - - for pyfile in self.core.thread_list.py_downloading: - status['speed'] += pyfile.status.get_speed() - - return status - - def file_exists(self, path): #@XXX: security?! - return exists(path) - - def get_server_version(self): - return CURRENT_VERSION - - def add_urls(self, links): - for link in links: - self.core.file_list.collector.addLink(link) - self.core.file_list.save() - - def add_package(self, name, links): - pid = self.new_package(name) - self.core.file_list.packager.pushPackage2Queue(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): - id = self.core.file_list.packager.addNewPackage(name) - self.core.file_list.save() - return id - - def get_package_data(self, id): - return self.core.file_list.packager.getPackageData(id) - - def get_package_files(self, id): - return self.core.file_list.packager.getPackageFiles(id) - - def get_file_info(self, id): - return self.core.file_list.getFileInfo(id) - - def del_links(self, ids): - for id in ids: - try: - self.core.file_list.collector.removeFile(id) - except: - self.core.file_list.packages.removeFile(id) - self.core.file_list.save() - - def del_packages(self, ids): - for id in ids: - self.core.file_list.packages.removePackage(id) - self.core.file_list.save() - - def kill(self): - self.core.do_kill = True - return True - - def get_queue(self): - data = [] - for q in self.core.file_list.data["queue"]: - data.append(q.data) - return data - - def get_collector_packages(self): - data = [] - for q in self.core.file_list.data["packages"]: - data.append(q.data) - return data - - def get_collector_files(self): - files = [] - for f in self.core.file_list.data["collector"]: - files.append(f.id) - return files - - def move_file_2_package(self, fid, pid): - try: - pyfile = self.core.file_list.collector.getFile(fid) - self.core.file_list.packager.addFileToPackage(pid, pyfile) - except: - return - else: - self.core.file_list.collector.removeFile(fid) - - def push_package_2_queue(self, id): - self.core.file_list.packager.pushPackage2Queue(id) - - #def move_urls_up(self, ids): - # for id in ids: - # self.core.file_list.move(id) - # self.core.file_list.save() - - #def move_urls_down(self, ids): - # for id in ids: - # self.core.file_list.move(id, 1) - # self.core.file_list.save() - - def is_time_download(self): - start = self.core.config['downloadTime']['start'].split(":") - end = self.core.config['downloadTime']['end'].split(":") - return self.core.compare_time(start, end) - - def is_time_reconnect(self): - start = self.core.config['reconnectTime']['start'].split(":") - end = self.core.config['reconnectTime']['end'].split(":") - return self.compare_time(start, end) - -if __name__ == "__main__": - pyload_core = Core() - try: - pyload_core.start() - except KeyboardInterrupt: - pyload_core.logger.info("killed pyLoad by Terminal") - exit() - +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + 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 of the License, + 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, see . + + @author: spoob + @author: sebnapi + @author: RaNaN + @author: mkaay + @version: v0.3 +""" + +CURRENT_VERSION = '0.3' +import gettext +from glob import glob +from imp import find_module +import logging +import logging.handlers +from os import listdir +from os import makedirs +from os import sep +from os.path import basename +from os.path import dirname +from os.path import exists +from os.path import join +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 module.file_list import File_List +from module.network.Request import Request +import module.remote.SecureXMLRPCServer as Server +from module.thread_list import Thread_List +from module.web.ServerThread import WebServer +from module.XMLConfigParser import XMLConfigParser + +class Core(object): + """ pyLoad Core """ + def __init__(self): + if len(argv) > 1: + if argv[1] == "-v": + print "pyLoad", CURRENT_VERSION + exit() + + def shutdown(self): + "abort all downloads and exit" + self.thread_list.pause = True + + for pyfile in self.thread_list.py_downloading: + pyfile.plugin.req.abort = True + + while self.thread_list.py_downloading: + sleep(1) + self.logger.info("Going to shutdown pyLoad") + exit() + + def toggle_pause(self): + if self.thread_list.pause: + self.thread_list.pause = False + return False + elif not self.thread_list.pause: + self.thread_list.pause = True + return True + + def start(self): + """ starts the machine""" + self.path = dirname(__file__) + + self.config = {} + self.plugins_avaible = {} + + self.plugin_folder = join("module", "plugins") + + self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) + self.config = self.xmlconfig.getConfig() + + self.do_kill = False + translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) + translation.install(unicode=True) + + self.check_install("Crypto", "pycrypto to decode container files") + self.check_install("Image", "Python Image Libary (PIL) for captha reading") + self.check_install("pycurl", "pycurl for lower memory footprint while downloading") + self.check_install("django", "Django for webinterface") + self.check_install("tesseract", "tesseract for captcha reading", False) + self.check_install("gocr", "gocr for captcha reading", False) + + self.check_file(self.config['log']['log_folder'], _("folder for logs"), True) + self.check_file(self.config['general']['download_folder'], _("folder for downloads"), True) + self.check_file(self.config['general']['link_file'], _("file for links")) + self.check_file(self.config['general']['failed_file'], _("file for failed links")) + + script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] # @TODO: windows save? + + self.check_file(script_folders, _("folders for scripts"), True) + + if self.config['ssl']['activated']: + self.check_install("OpenSSL", "OpenSSL for secure connection", True) + self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) + self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) + + if self.config['general']['debug_mode']: + self.init_logger(logging.DEBUG) # logging level + else: + self.init_logger(logging.INFO) # logging level + + self.init_scripts() + path.append(self.plugin_folder) + self.create_plugin_index() + + 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.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only + + #read url list @mkaay: pid, lid? + # pid = package id + # lid = link/file id + linkFile = self.config['general']['link_file'] + packs = self.server_methods.get_queue() + found = False + for data in packs: + if data["package_name"] == linkFile: + found = data["id"] + break + if found == False: + pid = self.file_list.packager.addNewPackage(package_name=linkFile) + else: + pid = found + lid = self.file_list.collector.addLink(linkFile) + self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) + self.file_list.packager.pushPackage2Queue(pid) + + while True: + sleep(2) + if self.do_kill: + self.logger.info("pyLoad quits") + exit() + + 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']} + 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") + else: + self.server = Server.AuthXMLRPCServer(server_addr, usermap) + self.logger.info("Auth XMLRPC Server Started") + + self.server.register_instance(self.server_methods) + + thread.start_new_thread(self.server.serve_forever, ()) + except Exception, e: + self.logger.error("Failed starting socket server, CLI and GUI will not be available: %s" % str(e)) + if self.config['general']['debug_mode']: + import traceback + traceback.print_exc() + + + def init_webserver(self): + if self.config['webinterface']['activated']: + self.webserver = WebServer(self) + self.webserver.start() + + + def init_logger(self, level): + console = logging.StreamHandler(stdout) + frm = logging.Formatter("%(asctime)s: %(levelname)-8s %(message)s", "%d.%m.%Y %H:%M:%S") + console.setFormatter(frm) + self.logger = logging.getLogger("log") # settable in config + + if self.config['log']['file_log']: + file_handler = logging.handlers.RotatingFileHandler(self.config['log']['log_folder'] + sep + 'log.txt', maxBytes=102400, backupCount=int(self.config['log']['log_count'])) #100 kib each + file_handler.setFormatter(frm) + self.logger.addHandler(file_handler) + + 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 = {} + #@TODO: windows save?! + 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'))) + + for script_type, script_name in self.scripts.iteritems(): + if script_name != []: + self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name))) + + def check_install(self, check_name, legend, python=True, essential=False): + """check wether needed tools are installed""" + try: + if python: + find_module(check_name) + else: + pipe = subprocess.PIPE + subprocess.Popen(check_name, stdout=pipe, stderr=pipe) + except: + print "Install", legend + if essential: exit() + + def check_file(self, check_names, description="", folder=False, empty=True, essential=False): + """check wether needed files are exists""" + tmp_names = [] + if not type(check_names) == list: + tmp_names.append(check_names) + else: + tmp_names.extend(check_names) + file_created = True + file_exists = True + for tmp_name in tmp_names: + if not exists(tmp_name): + file_exists = False + if empty: + try: + if folder: + tmp_name = tmp_name.replace("/", sep) + makedirs(tmp_name) + else: + open(tmp_name, "w") + except: + file_created = False + else: + file_created = False + if not file_exists: + if file_created: + print _("%s created") % description + else: + if not empty: + print _("could not find %s: %s") % (description, tmp_name) + else: + print _("could not create %s: %s") % (description, tmp_name) + if essential: + exit() + + def restart(self): + pass + + #~ def update(self, file_update=None): + #~ try: + #~ if not file_update: + #~ tmp_zip = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name + #~ file_update = Request().download("http://update.pyload.org/index.php?download=True", tmp_zip) + #~ __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip,"Test/") + #~ self.logger.info(_("Updated pyLoad")) + #~ except: + #~ self.logger.info("Error on updating pyLoad") + + def create_plugin_index(self): + for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): + plugin_pattern = "" + plugin_file = sub("(\.pyc|\.py)", "", basename(file_handler)) + if plugin_file == "DLC": + plugin_pattern = "(?!http://).*\.dlc" + else: + for line in open(file_handler, "r").readlines(): + if "props['pattern']" in line: + plugin_pattern = line.split("r\"")[1].split("\"")[0] + break + if plugin_pattern != "": + self.plugins_avaible[plugin_file] = plugin_pattern + self.logger.debug(plugin_file + _(" added")) + self.logger.info(_("created index of plugins")) + + def compare_time(self, start, end): + if start == end: return True + + now = time.localtime()[3:5] + if start < now and end > now: return True + elif start > end and (now > start or now < end): return True + 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() + + #################################### + ########## XMLRPC Methods ########## + #################################### + +class ServerMethods(): + def __init__(self, core): + self.core = core + + 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'])) + if version_check == "": + self.core.logger.info("No Updates for pyLoad") + return False + else: + if self.core.config['updates']['install_updates']: + try: + tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name + 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/") + return True + + except: + self.logger.core.info("Auto install Faild") + return False + + else: + self.core.logger.info("New pyLoad Version %s available" % version_check) + return True + else: + return False + + def status_downloads(self): + downloads = [] + for pyfile in self.core.thread_list.py_downloading: + download = {} + download['id'] = pyfile.id + download['name'] = pyfile.status.filename + download['speed'] = pyfile.status.get_speed() + download['eta'] = pyfile.status.get_ETA() + download['kbleft'] = pyfile.status.kB_left() + download['size'] = pyfile.status.size() / 1000 + download['percent'] = pyfile.status.percent() + download['status'] = pyfile.status.type + download['wait_until'] = pyfile.status.waituntil + download['package'] = pyfile.package.data["package_name"] + downloads.append(download) + return downloads + + def get_conf_val(self, cat, var): + if var != "username" and var != "password": + return self.core.config[cat][var] + else: + raise Exception("not allowed!") + + def pause_server(self): + self.core.thread_list.pause = True + + def unpause_server(self): + self.core.thread_list.pause = False + + def status_server(self): + status = {} + status['pause'] = self.core.thread_list.pause + status['queue'] = self.core.file_list.countDownloads() + status['total'] = len(self.core.file_list.data['queue']) + status['speed'] = 0 + + for pyfile in self.core.thread_list.py_downloading: + status['speed'] += pyfile.status.get_speed() + + return status + + def file_exists(self, path): #@XXX: security?! + return exists(path) + + def get_server_version(self): + return CURRENT_VERSION + + def add_urls(self, links): + for link in links: + self.core.file_list.collector.addLink(link) + self.core.file_list.save() + + def add_package(self, name, links): + pid = self.new_package(name) + self.core.file_list.packager.pushPackage2Queue(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): + id = self.core.file_list.packager.addNewPackage(name) + self.core.file_list.save() + return id + + def get_package_data(self, id): + return self.core.file_list.packager.getPackageData(id) + + def get_package_files(self, id): + return self.core.file_list.packager.getPackageFiles(id) + + def get_file_info(self, id): + return self.core.file_list.getFileInfo(id) + + def del_links(self, ids): + for id in ids: + try: + self.core.file_list.collector.removeFile(id) + except: + self.core.file_list.packages.removeFile(id) + self.core.file_list.save() + + def del_packages(self, ids): + for id in ids: + self.core.file_list.packages.removePackage(id) + self.core.file_list.save() + + def kill(self): + self.core.do_kill = True + return True + + def get_queue(self): + data = [] + for q in self.core.file_list.data["queue"]: + data.append(q.data) + return data + + def get_collector_packages(self): + data = [] + for q in self.core.file_list.data["packages"]: + data.append(q.data) + return data + + def get_collector_files(self): + files = [] + for f in self.core.file_list.data["collector"]: + files.append(f.id) + return files + + def move_file_2_package(self, fid, pid): + try: + pyfile = self.core.file_list.collector.getFile(fid) + self.core.file_list.packager.addFileToPackage(pid, pyfile) + except: + return + else: + self.core.file_list.collector.removeFile(fid) + + def push_package_2_queue(self, id): + self.core.file_list.packager.pushPackage2Queue(id) + + #def move_urls_up(self, ids): + # for id in ids: + # self.core.file_list.move(id) + # self.core.file_list.save() + + #def move_urls_down(self, ids): + # for id in ids: + # self.core.file_list.move(id, 1) + # self.core.file_list.save() + + def is_time_download(self): + start = self.core.config['downloadTime']['start'].split(":") + end = self.core.config['downloadTime']['end'].split(":") + return self.core.compare_time(start, end) + + def is_time_reconnect(self): + start = self.core.config['reconnectTime']['start'].split(":") + end = self.core.config['reconnectTime']['end'].split(":") + return self.compare_time(start, end) + +if __name__ == "__main__": + pyload_core = Core() + try: + pyload_core.start() + except KeyboardInterrupt: + pyload_core.logger.info("killed pyLoad by Terminal") + exit() + -- cgit v1.2.3 From fc5ae79bf0e0fc2c43b9b748c4d00037077f21a6 Mon Sep 17 00:00:00 2001 From: Wugy Date: Sat, 19 Dec 2009 19:27:42 +0100 Subject: webinterface - activ Downloads List - Code completed --- pyLoadCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 3e6662d17..1951d6db1 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -351,7 +351,7 @@ class ServerMethods(): download['speed'] = pyfile.status.get_speed() download['eta'] = pyfile.status.get_ETA() download['kbleft'] = pyfile.status.kB_left() - download['size'] = pyfile.status.size() / 1000 + download['size'] = pyfile.status.size() download['percent'] = pyfile.status.percent() download['status'] = pyfile.status.type download['wait_until'] = pyfile.status.waituntil -- cgit v1.2.3 From 18d827faf2960efcfb2e1196375e5542e25d20ab Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 20 Dec 2009 00:27:02 +0100 Subject: reimplemented old CLI --- pyLoadCore.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 1951d6db1..97ca25ffd 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -302,11 +302,6 @@ 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() - #################################### ########## XMLRPC Methods ########## #################################### @@ -371,6 +366,12 @@ class ServerMethods(): def unpause_server(self): self.core.thread_list.pause = False + def toggle_pause(self): + if self.core.thread_list.pause: + self.core.thread_list.pause = False + else: + self.core.thread_list.pause = True + def status_server(self): status = {} status['pause'] = self.core.thread_list.pause -- cgit v1.2.3 From 3e52baca1b622694e072eff87be825770ff9760f Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 20 Dec 2009 19:09:48 +0100 Subject: new cli working --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 97ca25ffd..e7911a65b 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -375,6 +375,7 @@ class ServerMethods(): def status_server(self): status = {} status['pause'] = self.core.thread_list.pause + status['activ'] = len(self.core.thread_list.py_downloading) status['queue'] = self.core.file_list.countDownloads() status['total'] = len(self.core.file_list.data['queue']) status['speed'] = 0 -- cgit v1.2.3 From ff9a9560fef2d4a977a994d967e2848c1b62d206 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 20 Dec 2009 20:00:40 +0100 Subject: fixed file_list, clean exit? --- pyLoadCore.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index e7911a65b..fbce78aaf 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -158,9 +158,8 @@ class Core(object): while True: sleep(2) - if self.do_kill: - self.logger.info("pyLoad quits") - exit() + if self.do_kill: + raise KeyboardInterrupt def init_server(self): try: @@ -489,6 +488,6 @@ if __name__ == "__main__": try: pyload_core.start() except KeyboardInterrupt: - pyload_core.logger.info("killed pyLoad by Terminal") + pyload_core.logger.info("killed pyLoad") exit() -- cgit v1.2.3 From c003c8a342cbe9609f8e6b21669a8b4a90a213bf Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 20 Dec 2009 20:54:30 +0100 Subject: fixed file_list again, webserver terminates correctly when killing pyload over xmlrpc --- pyLoadCore.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index fbce78aaf..50c5d2c55 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -158,8 +158,11 @@ class Core(object): while True: sleep(2) - if self.do_kill: - raise KeyboardInterrupt + if self.do_kill: + self.logger.info("pyLoad quits") + self.webserver.quit() + self.webserver.join() + exit() def init_server(self): try: @@ -421,12 +424,12 @@ class ServerMethods(): try: self.core.file_list.collector.removeFile(id) except: - self.core.file_list.packages.removeFile(id) + self.core.file_list.packager.removeFile(id) self.core.file_list.save() def del_packages(self, ids): for id in ids: - self.core.file_list.packages.removePackage(id) + self.core.file_list.packager.removePackage(id) self.core.file_list.save() def kill(self): @@ -488,6 +491,6 @@ if __name__ == "__main__": try: pyload_core.start() except KeyboardInterrupt: - pyload_core.logger.info("killed pyLoad") + pyload_core.logger.info("killed pyLoad by Terminal") exit() -- cgit v1.2.3 From 62965d0668e81fc801c4be2d61c1a0b64b0edca8 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 20 Dec 2009 23:43:21 +0100 Subject: cli + web fixes --- pyLoadCore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 50c5d2c55..2a9cbbc59 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -159,8 +159,8 @@ class Core(object): while True: sleep(2) if self.do_kill: - self.logger.info("pyLoad quits") - self.webserver.quit() + self.logger.info("pyLoad quits") + self.webserver.quit() self.webserver.join() exit() -- cgit v1.2.3 From 20f7c0e65607f2fb8607ed0e5e96181a36be76ca Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 14:24:51 +0100 Subject: new update threads, link dock works now --- pyLoadCore.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 2a9cbbc59..4df3f852e 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -394,8 +394,10 @@ class ServerMethods(): return CURRENT_VERSION def add_urls(self, links): - for link in links: - self.core.file_list.collector.addLink(link) + for link in links: + link = link.strip() + if link.startswith("http") or exists(link): + self.core.file_list.collector.addLink(link) self.core.file_list.save() def add_package(self, name, links): -- cgit v1.2.3 From 4c98db9a0eb0ca1ca70c4886b907e79682bfad82 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 14:41:23 +0100 Subject: pause/start button works --- pyLoadCore.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 4df3f852e..9eb385553 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -372,7 +372,8 @@ class ServerMethods(): if self.core.thread_list.pause: self.core.thread_list.pause = False else: - self.core.thread_list.pause = True + self.core.thread_list.pause = True + return self.core.thread_list.pause def status_server(self): status = {} -- cgit v1.2.3 From 7dd0c96037b0f91f761126d20e477e0e83e20825 Mon Sep 17 00:00:00 2001 From: Wugy Date: Mon, 21 Dec 2009 18:15:56 +0100 Subject: total progressbar bullshit --- pyLoadCore.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 9eb385553..2a9cbbc59 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -372,8 +372,7 @@ class ServerMethods(): if self.core.thread_list.pause: self.core.thread_list.pause = False else: - self.core.thread_list.pause = True - return self.core.thread_list.pause + self.core.thread_list.pause = True def status_server(self): status = {} @@ -395,10 +394,8 @@ class ServerMethods(): return CURRENT_VERSION def add_urls(self, links): - for link in links: - link = link.strip() - if link.startswith("http") or exists(link): - self.core.file_list.collector.addLink(link) + for link in links: + self.core.file_list.collector.addLink(link) self.core.file_list.save() def add_package(self, name, links): -- cgit v1.2.3 From 63d4273065f475719e63e5785abdbf11be43dae3 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 21 Dec 2009 19:19:28 +0100 Subject: reverted files, pyload.db fix --- pyLoadCore.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 2a9cbbc59..eb43ce840 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -43,7 +43,8 @@ from sys import path from sys import stdout import thread import time -from time import sleep +from time import sleep +from shutil import copyfile from module.file_list import File_List from module.network.Request import Request @@ -185,7 +186,11 @@ class Core(object): traceback.print_exc() - def init_webserver(self): + def init_webserver(self): + pyloadDBFile = join(self.path, "module", "web", "pyload.db") + pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db") + if not exists(pyloadDBFile): + copyfile(pyloadDefaultDBFile, pyloadDBFile) if self.config['webinterface']['activated']: self.webserver = WebServer(self) self.webserver.start() @@ -372,7 +377,8 @@ class ServerMethods(): if self.core.thread_list.pause: self.core.thread_list.pause = False else: - self.core.thread_list.pause = True + self.core.thread_list.pause = True + return self.core.thread_list.pause def status_server(self): status = {} @@ -394,8 +400,10 @@ class ServerMethods(): return CURRENT_VERSION def add_urls(self, links): - for link in links: - self.core.file_list.collector.addLink(link) + for link in links: + link = link.strip() + if link.startswith("http") or exists(link): + self.core.file_list.collector.addLink(link) self.core.file_list.save() def add_package(self, name, links): -- cgit v1.2.3 From 9453269684b8d17411d8bbc4ecd0c7958670ff42 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 21 Dec 2009 19:59:59 +0100 Subject: log view, progressbar test --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) mode change 100755 => 100644 pyLoadCore.py (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py old mode 100755 new mode 100644 index eb43ce840..8ca45f2e2 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -412,6 +412,7 @@ class ServerMethods(): 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) + self.core.file_list.save() def new_package(self, name): id = self.core.file_list.packager.addNewPackage(name) -- cgit v1.2.3 From a5ff0482ede8bd7bd932482887f2f7cdae5039d9 Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 23 Dec 2009 00:04:36 +0100 Subject: core: downloadlimit is not far away ;) gui: restart download action --- pyLoadCore.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 8ca45f2e2..232adc253 100644 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -473,7 +473,14 @@ class ServerMethods(): self.core.file_list.collector.removeFile(fid) def push_package_2_queue(self, id): - self.core.file_list.packager.pushPackage2Queue(id) + self.core.file_list.packager.pushPackage2Queue(id) + + def restart_package(self, packid): + for id in self.core.file_list.packager.getPackageFiles(packid): + self.core.file_list.packager.resetFileStatus(id) + + def restart_file(self, fileid): + self.core.file_list.packager.resetFileStatus(fileid) #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From 5ee3579572b60bb8f9e6475a517d69462b0cfe29 Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 23 Dec 2009 21:04:06 +0100 Subject: download speed limit --- pyLoadCore.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 232adc253..85ca5a5fe 100644 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -90,7 +90,7 @@ class Core(object): self.plugin_folder = join("module", "plugins") - self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) + self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml"), join(self.path,"module","config","core_default.xml")) self.config = self.xmlconfig.getConfig() self.do_kill = False @@ -116,7 +116,9 @@ class Core(object): if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) - self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) + self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) + + self.downloadSpeedLimit = int(self.xmlconfig.get("general", "download_speed_limit", 0)) if self.config['general']['debug_mode']: self.init_logger(logging.DEBUG) # logging level @@ -307,7 +309,10 @@ class Core(object): if start < now and end > now: return True elif start > end and (now > start or now < end): return True elif start < now and end < now and start > end: return True - else: return False + else: return False + + def getMaxSpeed(self): + return self.downloadSpeedLimit #################################### ########## XMLRPC Methods ########## -- cgit v1.2.3 From 5c7e9f0f1325523347a52869cebbf03463550bca Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 24 Dec 2009 01:41:13 +0100 Subject: clean shutdown --- pyLoadCore.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 85ca5a5fe..c5bf7ed0a 100644 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -161,10 +161,9 @@ class Core(object): while True: sleep(2) - if self.do_kill: + if self.do_kill: + self.shutdown() self.logger.info("pyLoad quits") - self.webserver.quit() - self.webserver.join() exit() def init_server(self): @@ -312,7 +311,17 @@ class Core(object): else: return False def getMaxSpeed(self): - return self.downloadSpeedLimit + return self.downloadSpeedLimit + + def shutdown(self): + self.logger.info("shutting down...") + self.webserver.quit() + self.webserver.join() + self.thread_list.stopAllDownloads() + for thread in self.thread_list.threads: + thread.shutdown = True + thread.join(15) + self.file_list.save() #################################### ########## XMLRPC Methods ########## @@ -511,7 +520,8 @@ if __name__ == "__main__": pyload_core = Core() try: pyload_core.start() - except KeyboardInterrupt: + except KeyboardInterrupt: + pyload_core.shutdown() pyload_core.logger.info("killed pyLoad by Terminal") exit() -- cgit v1.2.3 From 504b313112be6a82d6eee418ae059646ecfc4b30 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 20:18:11 +0100 Subject: fixed ddl-music, cleaned up, new status (starting), some more fixes --- pyLoadCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 pyLoadCore.py (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py old mode 100644 new mode 100755 index c5bf7ed0a..7cf83389e --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -522,6 +522,6 @@ if __name__ == "__main__": pyload_core.start() except KeyboardInterrupt: pyload_core.shutdown() - pyload_core.logger.info("killed pyLoad by Terminal") + pyload_core.logger.info("killed pyLoad from Terminal") exit() -- cgit v1.2.3 From b5d1c47ac2590fe4314d7e96d58443c30463746c Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 22:35:20 +0100 Subject: gui contaoner upload, closes #39 --- pyLoadCore.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 7cf83389e..9e9da2c4b 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -44,7 +44,8 @@ from sys import stdout import thread import time from time import sleep -from shutil import copyfile +from shutil import copyfile +from tempfile import NamedTemporaryFile from module.file_list import File_List from module.network.Request import Request @@ -494,7 +495,17 @@ class ServerMethods(): self.core.file_list.packager.resetFileStatus(id) def restart_file(self, fileid): - self.core.file_list.packager.resetFileStatus(fileid) + self.core.file_list.packager.resetFileStatus(fileid) + + def upload_container(self, filename, type, content): + th = NamedTemporaryFile(mode="w", suffix="."+type, delete=False) + th.write(content) + path = th.name + th.close() + pid = self.core.file_list.packager.addNewPackage(filename) + cid = self.core.file_list.collector.addLink(path) + self.move_file_2_package(cid, pid) + self.core.file_list.save() #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From bdf65f8628474b424c6e47ba9febe70fcfa96fe4 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 26 Dec 2009 23:35:51 +0100 Subject: closes #42 --- pyLoadCore.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 9e9da2c4b..0ad952e7d 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -32,15 +32,18 @@ from os import listdir from os import makedirs from os import sep from os.path import basename +from os.path import abspath from os.path import dirname from os.path import exists -from os.path import join +from os.path import join +from os import execv from re import sub import subprocess from sys import argv from sys import exit from sys import path -from sys import stdout +from sys import stdout +from sys import executable import thread import time from time import sleep @@ -62,18 +65,6 @@ class Core(object): print "pyLoad", CURRENT_VERSION exit() - def shutdown(self): - "abort all downloads and exit" - self.thread_list.pause = True - - for pyfile in self.thread_list.py_downloading: - pyfile.plugin.req.abort = True - - while self.thread_list.py_downloading: - sleep(1) - self.logger.info("Going to shutdown pyLoad") - exit() - def toggle_pause(self): if self.thread_list.pause: self.thread_list.pause = False @@ -95,6 +86,7 @@ class Core(object): self.config = self.xmlconfig.getConfig() self.do_kill = False + self.do_restart = False translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) translation.install(unicode=True) @@ -162,6 +154,9 @@ class Core(object): while True: sleep(2) + if self.do_restart: + self.logger.info("restarting pyLoad") + self.restart() if self.do_kill: self.shutdown() self.logger.info("pyLoad quits") @@ -274,7 +269,8 @@ class Core(object): exit() def restart(self): - pass + self.shutdown() + execv(executable, [executable, "pyLoadCore.py"]) #~ def update(self, file_update=None): #~ try: @@ -459,6 +455,9 @@ class ServerMethods(): def kill(self): self.core.do_kill = True return True + + def restart(self): + self.core.do_restart = True def get_queue(self): data = [] @@ -525,7 +524,7 @@ class ServerMethods(): def is_time_reconnect(self): start = self.core.config['reconnectTime']['start'].split(":") end = self.core.config['reconnectTime']['end'].split(":") - return self.compare_time(start, end) + return self.core.compare_time(start, end) if __name__ == "__main__": pyload_core = Core() -- cgit v1.2.3 From 8e87787753b2e049917a5491727d285b1c5a7095 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 00:20:21 +0100 Subject: closes #13 --- pyLoadCore.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 0ad952e7d..5890c6e9a 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -282,8 +282,12 @@ class Core(object): #~ except: #~ self.logger.info("Error on updating pyLoad") - def create_plugin_index(self): - for file_handler in glob(self.plugin_folder + sep + '*.py') + glob(self.plugin_folder + sep + 'DLC.pyc'): + def create_plugin_index(self): + plugins = glob(join(self.plugin_folder, "hoster", "*.py")) + plugins += glob(join(self.plugin_folder, "decrypter", "*.py")) + plugins += glob(join(self.plugin_folder, "container", "*.py")) + plugins += glob(join(self.plugin_folder, "container", "DLC.pyc")) + for file_handler in plugins: plugin_pattern = "" plugin_file = sub("(\.pyc|\.py)", "", basename(file_handler)) if plugin_file == "DLC": -- cgit v1.2.3 From 757f025247d77b085b6168d5f625d2bbfa7c4c0d Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 14:45:22 +0100 Subject: stop button works, closes #59 --- pyLoadCore.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 5890c6e9a..979abaf44 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -508,7 +508,20 @@ class ServerMethods(): pid = self.core.file_list.packager.addNewPackage(filename) cid = self.core.file_list.collector.addLink(path) self.move_file_2_package(cid, pid) - self.core.file_list.save() + self.core.file_list.save() + + def get_log(self, offset=0): + filename = self.core.config['log']['log_folder'] + sep + 'log.txt' + fh = open(filename, "r") + content = fh.read() + fh.close() + lines = content.splitlines() + if offset >= len(lines): + return None + return lines[offset:] + + def stop_downloads(self): + self.core.thread_list.stopAllDownloads() #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From ff7d4f1a13db0f4a9d6c427dcccbb0d1faf6c577 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 15:26:33 +0100 Subject: closes #51 --- pyLoadCore.py | 61 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 979abaf44..c062374bc 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -125,8 +125,10 @@ class Core(object): self.server_methods = ServerMethods(self) self.file_list = File_List(self) self.thread_list = Thread_List(self) - - self.server_methods.check_update() + + self.last_update_check = 0 + self.update_check_interval = 1800 + self.update_available = self.check_update() self.init_server() self.init_webserver() # start webinterface like cli, gui etc @@ -160,7 +162,9 @@ class Core(object): if self.do_kill: self.shutdown() self.logger.info("pyLoad quits") - exit() + exit() + if self.last_update_check + self.update_check_interval <= time.time(): + self.update_available = self.check_update() def init_server(self): try: @@ -323,41 +327,51 @@ class Core(object): thread.shutdown = True thread.join(15) self.file_list.save() - - #################################### - ########## XMLRPC Methods ########## - #################################### -class ServerMethods(): - def __init__(self, core): - self.core = core + def check_update(self): + try: + if self.config['updates']['search_updates']: + version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, False)) + if version_check == "": + self.logger.info("No Updates for pyLoad") + return False + else: + self.logger.info("New pyLoad Version %s available" % version_check) + return True + else: + return False + finally: + self.last_update_check = time.time() - def check_update(self): - """checks newst version""" - if self.core.config['updates']['search_updates']: + def install_update(self): + if self.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'])) if version_check == "": - self.core.logger.info("No Updates for pyLoad") return False else: - if self.core.config['updates']['install_updates']: + if self.config['updates']['install_updates']: try: tmp_zip_name = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name - tmp_zip = open(tmp_zip_name, 'w') + tmp_zip = open(tmp_zip_name, 'wb') tmp_zip.write(version_check) tmp_zip.close() __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip_name, "Test/") return True - except: - self.logger.core.info("Auto install Faild") + self.logger.info("Auto install Failed") return False - else: - self.core.logger.info("New pyLoad Version %s available" % version_check) - return True + return False else: return False + + #################################### + ########## XMLRPC Methods ########## + #################################### + +class ServerMethods(): + def __init__(self, core): + self.core = core def status_downloads(self): downloads = [] @@ -521,7 +535,10 @@ class ServerMethods(): return lines[offset:] def stop_downloads(self): - self.core.thread_list.stopAllDownloads() + self.core.thread_list.stopAllDownloads() + + def update_available(self): + return self.core.update_available #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From 090c9d2abdac07025fe6d7351e376e85aabc0891 Mon Sep 17 00:00:00 2001 From: mkaay Date: Sun, 27 Dec 2009 22:16:51 +0100 Subject: fixed uploaded.to and netload.in, gui clipboard check --- pyLoadCore.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index c062374bc..d0a6195d4 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -537,6 +537,14 @@ class ServerMethods(): def stop_downloads(self): self.core.thread_list.stopAllDownloads() + def stop_download(self, type, id): + if type == "pack": + ids = self.core.file_list.getPackageFiles(id) + for fid in ids: + self.core.file_list.packager.abortFile(fid) + else: + self.core.file_list.packager.abortFile(id) + def update_available(self): return self.core.update_available -- cgit v1.2.3 From 035fd57b56b33463c933db15f4ee8a149ddc060f Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 20:03:11 +0100 Subject: tried to satisfy RaNaN --- pyLoadCore.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index d0a6195d4..52cdf6720 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -152,7 +152,9 @@ class Core(object): pid = found lid = self.file_list.collector.addLink(linkFile) self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) - self.file_list.packager.pushPackage2Queue(pid) + self.file_list.packager.pushPackage2Queue(pid) + + self.file_list.continueAborted() while True: sleep(2) @@ -322,9 +324,10 @@ class Core(object): self.logger.info("shutting down...") self.webserver.quit() self.webserver.join() - self.thread_list.stopAllDownloads() for thread in self.thread_list.threads: thread.shutdown = True + self.thread_list.stopAllDownloads() + for thread in self.thread_list.threads: thread.join(15) self.file_list.save() -- cgit v1.2.3 From e78cbecc8405e225b6b22625e1854ba920d81062 Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 20:14:15 +0100 Subject: fixed webserver bug (thx nCID) --- pyLoadCore.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 52cdf6720..aaa965901 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -321,9 +321,10 @@ class Core(object): return self.downloadSpeedLimit def shutdown(self): - self.logger.info("shutting down...") - self.webserver.quit() - self.webserver.join() + self.logger.info("shutting down...") + if self.config['webinterface']['activated']: + self.webserver.quit() + self.webserver.join() for thread in self.thread_list.threads: thread.shutdown = True self.thread_list.stopAllDownloads() -- cgit v1.2.3 From 86949a6240bc6d5a5fd5e5677925e0d945686d3e Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 28 Dec 2009 22:21:35 +0100 Subject: package renaming in collector works --- pyLoadCore.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index aaa965901..8bd9a3995 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -550,7 +550,10 @@ class ServerMethods(): self.core.file_list.packager.abortFile(id) def update_available(self): - return self.core.update_available + return self.core.update_available + + def set_package_name(self, pid, name): + self.core.file_list.packager.setPackageData(pid, package_name=name) #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From fa9cce4987da585f5bf21274cfbe5f046f46f703 Mon Sep 17 00:00:00 2001 From: mkaay Date: Tue, 29 Dec 2009 16:50:13 +0100 Subject: : Bitte gib eine Versions-Meldung ein. Zeilen beginnend mit 'HG:' werden entfernt. --- pyLoadCore.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 8bd9a3995..6b38d425c 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -553,7 +553,10 @@ class ServerMethods(): return self.core.update_available def set_package_name(self, pid, name): - self.core.file_list.packager.setPackageData(pid, package_name=name) + self.core.file_list.packager.setPackageData(pid, package_name=name) + + def pull_out_package(self, pid): + self.core.file_list.packager.pullOutPackage(pid) #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From c1516088e4e7f76dddd68ef71f58c6413862e31c Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 30 Dec 2009 12:35:03 +0100 Subject: show captchas in gui, SerienjunkiesOrg plugin --- pyLoadCore.py | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 6b38d425c..4ca81efed 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -50,12 +50,16 @@ from time import sleep from shutil import copyfile from tempfile import NamedTemporaryFile -from module.file_list import File_List from module.network.Request import Request import module.remote.SecureXMLRPCServer as Server +from module.XMLConfigParser import XMLConfigParser + +from module.file_list import File_List from module.thread_list import Thread_List from module.web.ServerThread import WebServer -from module.XMLConfigParser import XMLConfigParser +from module.CaptchaManager import CaptchaManager + +from xmlrpclib import Binary class Core(object): """ pyLoad Core """ @@ -121,10 +125,13 @@ class Core(object): self.init_scripts() path.append(self.plugin_folder) self.create_plugin_index() - + + self.lastGuiConnected = 0 + self.server_methods = ServerMethods(self) self.file_list = File_List(self) - self.thread_list = Thread_List(self) + self.thread_list = Thread_List(self) + self.captchaManager = CaptchaManager(self) self.last_update_check = 0 self.update_check_interval = 1800 @@ -135,7 +142,7 @@ class Core(object): self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only - + #read url list @mkaay: pid, lid? # pid = package id # lid = link/file id @@ -273,7 +280,10 @@ class Core(object): print _("could not create %s: %s") % (description, tmp_name) if essential: exit() - + + def isGUIConnected(self): + return self.lastGuiConnected+10 > time.time() + def restart(self): self.shutdown() execv(executable, [executable, "pyLoadCore.py"]) @@ -556,7 +566,30 @@ class ServerMethods(): self.core.file_list.packager.setPackageData(pid, package_name=name) def pull_out_package(self, pid): - self.core.file_list.packager.pullOutPackage(pid) + self.core.file_list.packager.pullOutPackage(pid) + + def is_captcha_waiting(self): + self.core.lastGuiConnected = time.time() + task = self.core.captchaManager.getTask() + return not task == None + + def get_captcha_task(self): + task = self.core.captchaManager.getTask() + if task: + task.setWatingForUser() + c = task.getCaptcha() + return str(task.getID()), Binary(c[0]), str(c[1]) + else: + return None, None, None + + def set_captcha_result(self, tid, result): + task = self.core.captchaManager.getTaskFromID(tid) + if task: + task.setResult(result) + task.setDone() + return True + else: + return False #def move_urls_up(self, ids): # for id in ids: -- cgit v1.2.3 From 69746896671494ab0169ac74fc316b5fce02cd95 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 2 Jan 2010 12:42:53 +0100 Subject: new cli functions --- pyLoadCore.py | 246 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 123 insertions(+), 123 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 4ca81efed..bdf4e1e40 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -35,30 +35,30 @@ from os.path import basename from os.path import abspath from os.path import dirname from os.path import exists -from os.path import join +from os.path import join from os import execv from re import sub import subprocess from sys import argv from sys import exit from sys import path -from sys import stdout +from sys import stdout from sys import executable import thread import time -from time import sleep -from shutil import copyfile +from time import sleep +from shutil import copyfile from tempfile import NamedTemporaryFile from module.network.Request import Request import module.remote.SecureXMLRPCServer as Server -from module.XMLConfigParser import XMLConfigParser +from module.XMLConfigParser import XMLConfigParser from module.file_list import File_List from module.thread_list import Thread_List from module.web.ServerThread import WebServer -from module.CaptchaManager import CaptchaManager - +from module.CaptchaManager import CaptchaManager + from xmlrpclib import Binary class Core(object): @@ -113,8 +113,8 @@ class Core(object): if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) - self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) - + self.check_file(self.config['ssl']['key'], _("ssl key"), False, True) + self.downloadSpeedLimit = int(self.xmlconfig.get("general", "download_speed_limit", 0)) if self.config['general']['debug_mode']: @@ -125,15 +125,15 @@ class Core(object): self.init_scripts() path.append(self.plugin_folder) self.create_plugin_index() - - self.lastGuiConnected = 0 + + self.lastGuiConnected = 0 self.server_methods = ServerMethods(self) self.file_list = File_List(self) - self.thread_list = Thread_List(self) + self.thread_list = Thread_List(self) self.captchaManager = CaptchaManager(self) - - self.last_update_check = 0 + + self.last_update_check = 0 self.update_check_interval = 1800 self.update_available = self.check_update() @@ -159,19 +159,19 @@ class Core(object): pid = found lid = self.file_list.collector.addLink(linkFile) self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) - self.file_list.packager.pushPackage2Queue(pid) - + self.file_list.packager.pushPackage2Queue(pid) + self.file_list.continueAborted() while True: sleep(2) - if self.do_restart: - self.logger.info("restarting pyLoad") + if self.do_restart: + self.logger.info("restarting pyLoad") self.restart() - if self.do_kill: + if self.do_kill: self.shutdown() self.logger.info("pyLoad quits") - exit() + exit() if self.last_update_check + self.update_check_interval <= time.time(): self.update_available = self.check_update() @@ -196,10 +196,10 @@ class Core(object): traceback.print_exc() - def init_webserver(self): - pyloadDBFile = join(self.path, "module", "web", "pyload.db") - pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db") - if not exists(pyloadDBFile): + def init_webserver(self): + pyloadDBFile = join(self.path, "module", "web", "pyload.db") + pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db") + if not exists(pyloadDBFile): copyfile(pyloadDefaultDBFile, pyloadDBFile) if self.config['webinterface']['activated']: self.webserver = WebServer(self) @@ -280,12 +280,12 @@ class Core(object): print _("could not create %s: %s") % (description, tmp_name) if essential: exit() - - def isGUIConnected(self): - return self.lastGuiConnected+10 > time.time() + + def isGUIConnected(self): + return self.lastGuiConnected+10 > time.time() def restart(self): - self.shutdown() + self.shutdown() execv(executable, [executable, "pyLoadCore.py"]) #~ def update(self, file_update=None): @@ -298,10 +298,10 @@ class Core(object): #~ except: #~ self.logger.info("Error on updating pyLoad") - def create_plugin_index(self): - plugins = glob(join(self.plugin_folder, "hoster", "*.py")) - plugins += glob(join(self.plugin_folder, "decrypter", "*.py")) - plugins += glob(join(self.plugin_folder, "container", "*.py")) + def create_plugin_index(self): + plugins = glob(join(self.plugin_folder, "hoster", "*.py")) + plugins += glob(join(self.plugin_folder, "decrypter", "*.py")) + plugins += glob(join(self.plugin_folder, "container", "*.py")) plugins += glob(join(self.plugin_folder, "container", "DLC.pyc")) for file_handler in plugins: plugin_pattern = "" @@ -325,36 +325,36 @@ class Core(object): if start < now and end > now: return True elif start > end and (now > start or now < end): return True elif start < now and end < now and start > end: return True - else: return False - - def getMaxSpeed(self): - return self.downloadSpeedLimit - - def shutdown(self): + else: return False + + def getMaxSpeed(self): + return self.downloadSpeedLimit + + def shutdown(self): self.logger.info("shutting down...") - if self.config['webinterface']['activated']: + if self.config['webinterface']['activated']: self.webserver.quit() - self.webserver.join() - for thread in self.thread_list.threads: - thread.shutdown = True - self.thread_list.stopAllDownloads() - for thread in self.thread_list.threads: - thread.join(15) + self.webserver.join() + for thread in self.thread_list.threads: + thread.shutdown = True + self.thread_list.stopAllDownloads() + for thread in self.thread_list.threads: + thread.join(15) self.file_list.save() - def check_update(self): + def check_update(self): try: if self.config['updates']['search_updates']: version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, False)) if version_check == "": self.logger.info("No Updates for pyLoad") - return False + return False else: self.logger.info("New pyLoad Version %s available" % version_check) return True else: - return False - finally: + return False + finally: self.last_update_check = time.time() def install_update(self): @@ -420,7 +420,7 @@ class ServerMethods(): if self.core.thread_list.pause: self.core.thread_list.pause = False else: - self.core.thread_list.pause = True + self.core.thread_list.pause = True return self.core.thread_list.pause def status_server(self): @@ -443,8 +443,8 @@ class ServerMethods(): return CURRENT_VERSION def add_urls(self, links): - for link in links: - link = link.strip() + for link in links: + link = link.strip() if link.startswith("http") or exists(link): self.core.file_list.collector.addLink(link) self.core.file_list.save() @@ -519,77 +519,77 @@ class ServerMethods(): self.core.file_list.collector.removeFile(fid) def push_package_2_queue(self, id): - self.core.file_list.packager.pushPackage2Queue(id) - - def restart_package(self, packid): - for id in self.core.file_list.packager.getPackageFiles(packid): - self.core.file_list.packager.resetFileStatus(id) - - def restart_file(self, fileid): - self.core.file_list.packager.resetFileStatus(fileid) - - def upload_container(self, filename, type, content): - th = NamedTemporaryFile(mode="w", suffix="."+type, delete=False) - th.write(content) - path = th.name - th.close() - pid = self.core.file_list.packager.addNewPackage(filename) - cid = self.core.file_list.collector.addLink(path) + self.core.file_list.packager.pushPackage2Queue(id) + + def restart_package(self, packid): + for id in self.core.file_list.packager.getPackageFiles(packid): + self.core.file_list.packager.resetFileStatus(id) + + def restart_file(self, fileid): + self.core.file_list.packager.resetFileStatus(fileid) + + def upload_container(self, filename, type, content): + th = NamedTemporaryFile(mode="w", suffix="."+type, delete=False) + th.write(content) + path = th.name + th.close() + pid = self.core.file_list.packager.addNewPackage(filename) + cid = self.core.file_list.collector.addLink(path) self.move_file_2_package(cid, pid) - self.core.file_list.save() - - def get_log(self, offset=0): - filename = self.core.config['log']['log_folder'] + sep + 'log.txt' - fh = open(filename, "r") - content = fh.read() - fh.close() - lines = content.splitlines() - if offset >= len(lines): - return None - return lines[offset:] - - def stop_downloads(self): - self.core.thread_list.stopAllDownloads() - - def stop_download(self, type, id): - if type == "pack": - ids = self.core.file_list.getPackageFiles(id) - for fid in ids: - self.core.file_list.packager.abortFile(fid) - else: - self.core.file_list.packager.abortFile(id) - - def update_available(self): - return self.core.update_available - - def set_package_name(self, pid, name): - self.core.file_list.packager.setPackageData(pid, package_name=name) - - def pull_out_package(self, pid): - self.core.file_list.packager.pullOutPackage(pid) - - def is_captcha_waiting(self): - self.core.lastGuiConnected = time.time() - task = self.core.captchaManager.getTask() - return not task == None - - def get_captcha_task(self): - task = self.core.captchaManager.getTask() - if task: - task.setWatingForUser() - c = task.getCaptcha() - return str(task.getID()), Binary(c[0]), str(c[1]) - else: - return None, None, None - - def set_captcha_result(self, tid, result): - task = self.core.captchaManager.getTaskFromID(tid) - if task: - task.setResult(result) - task.setDone() - return True - else: - return False + self.core.file_list.save() + + def get_log(self, offset=0): + filename = self.core.config['log']['log_folder'] + sep + 'log.txt' + fh = open(filename, "r") + content = fh.read() + fh.close() + lines = content.splitlines() + if offset >= len(lines): + return None + return lines[offset:] + + def stop_downloads(self): + self.core.thread_list.stopAllDownloads() + + def stop_download(self, type, id): + if type == "pack": + ids = self.core.file_list.getPackageFiles(id) + for fid in ids: + self.core.file_list.packager.abortFile(fid) + else: + self.core.file_list.packager.abortFile(id) + + def update_available(self): + return self.core.update_available + + def set_package_name(self, pid, name): + self.core.file_list.packager.setPackageData(pid, package_name=name) + + def pull_out_package(self, pid): + self.core.file_list.packager.pullOutPackage(pid) + + def is_captcha_waiting(self): + self.core.lastGuiConnected = time.time() + task = self.core.captchaManager.getTask() + return not task == None + + def get_captcha_task(self): + task = self.core.captchaManager.getTask() + if task: + task.setWatingForUser() + c = task.getCaptcha() + return str(task.getID()), Binary(c[0]), str(c[1]) + else: + return None, None, None + + def set_captcha_result(self, tid, result): + task = self.core.captchaManager.getTaskFromID(tid) + if task: + task.setResult(result) + task.setDone() + return True + else: + return False #def move_urls_up(self, ids): # for id in ids: @@ -615,7 +615,7 @@ if __name__ == "__main__": pyload_core = Core() try: pyload_core.start() - except KeyboardInterrupt: + except KeyboardInterrupt: pyload_core.shutdown() pyload_core.logger.info("killed pyLoad from Terminal") exit() -- cgit v1.2.3 From 3e3ba5240d20a5eb8df669272cb0f3d838d8fcfa Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 3 Jan 2010 14:58:28 +0100 Subject: Full Config File --- pyLoadCore.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index bdf4e1e40..6eafee4ac 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -138,14 +138,11 @@ class Core(object): self.update_available = self.check_update() self.init_server() - self.init_webserver() # start webinterface like cli, gui etc + self.init_webserver() - self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) # debug only + self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) - #read url list @mkaay: pid, lid? - # pid = package id - # lid = link/file id linkFile = self.config['general']['link_file'] packs = self.server_methods.get_queue() found = False -- cgit v1.2.3 From e9dc8ea08452c1555e28f4ac1970b96315ec4376 Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 3 Jan 2010 21:12:02 +0100 Subject: Cleaned Reconnect XML Config --- pyLoadCore.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 6eafee4ac..e586ee080 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -201,7 +201,6 @@ class Core(object): if self.config['webinterface']['activated']: self.webserver = WebServer(self) self.webserver.start() - def init_logger(self, level): console = logging.StreamHandler(stdout) @@ -217,7 +216,6 @@ 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 @@ -604,8 +602,8 @@ class ServerMethods(): return self.core.compare_time(start, end) def is_time_reconnect(self): - start = self.core.config['reconnectTime']['start'].split(":") - end = self.core.config['reconnectTime']['end'].split(":") + start = self.core.config['reconnect']['startTime'].split(":") + end = self.core.config['reconnect']['endTime'].split(":") return self.core.compare_time(start, end) if __name__ == "__main__": -- cgit v1.2.3 From 89acc0ff595f73956572c8892ccb860c06fba33a Mon Sep 17 00:00:00 2001 From: mkaay Date: Mon, 4 Jan 2010 20:35:26 +0100 Subject: added hook system --- pyLoadCore.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index e586ee080..a5521cd70 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -57,7 +57,8 @@ from module.XMLConfigParser import XMLConfigParser from module.file_list import File_List from module.thread_list import Thread_List from module.web.ServerThread import WebServer -from module.CaptchaManager import CaptchaManager +from module.CaptchaManager import CaptchaManager +from module.HookManager import HookManager from xmlrpclib import Binary @@ -106,10 +107,6 @@ class Core(object): self.check_file(self.config['general']['link_file'], _("file for links")) self.check_file(self.config['general']['failed_file'], _("file for failed links")) - script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/reconnected/'] # @TODO: windows save? - - self.check_file(script_folders, _("folders for scripts"), True) - if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) @@ -122,7 +119,7 @@ class Core(object): else: self.init_logger(logging.INFO) # logging level - self.init_scripts() + self.init_hooks() path.append(self.plugin_folder) self.create_plugin_index() @@ -216,19 +213,8 @@ 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 = {} - #@TODO: windows save?! - 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'))) - - for script_type, script_name in self.scripts.iteritems(): - if script_name != []: - self.logger.info("Installed %s Scripts: %s" % (script_type, ", ".join(script_name))) + def init_hooks(self): + self.hookManager = HookManager(self) def check_install(self, check_name, legend, python=True, essential=False): """check wether needed tools are installed""" -- cgit v1.2.3 From d56dcab5d48c8c4ec05f200f92bd35a1f977cd4f Mon Sep 17 00:00:00 2001 From: RaNaN Date: Wed, 6 Jan 2010 17:38:53 +0100 Subject: cli fix, webinterface db check --- pyLoadCore.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index a5521cd70..c43fac3c8 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -30,13 +30,14 @@ import logging import logging.handlers from os import listdir from os import makedirs -from os import sep +from os import sep from os.path import basename from os.path import abspath from os.path import dirname from os.path import exists from os.path import join -from os import execv +from os import execv +from sys import stdin from re import sub import subprocess from sys import argv @@ -66,9 +67,11 @@ class Core(object): """ pyLoad Core """ def __init__(self): if len(argv) > 1: - if argv[1] == "-v": - print "pyLoad", CURRENT_VERSION - exit() + if argv[1] == "-v" or argv[1] == "--version": + print "pyLoad", CURRENT_VERSION + else: + print "Unknown Command" + exit() def toggle_pause(self): if self.thread_list.pause: @@ -133,12 +136,11 @@ class Core(object): self.last_update_check = 0 self.update_check_interval = 1800 self.update_available = self.check_update() + self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) self.init_server() self.init_webserver() - - self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) linkFile = self.config['general']['link_file'] packs = self.server_methods.get_queue() @@ -191,10 +193,10 @@ class Core(object): def init_webserver(self): - pyloadDBFile = join(self.path, "module", "web", "pyload.db") - pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db") - if not exists(pyloadDBFile): - copyfile(pyloadDefaultDBFile, pyloadDBFile) + #pyloadDBFile = join(self.path, "module", "web", "pyload.db") + #pyloadDefaultDBFile = join(self.path, "module", "web", "pyload_default.db") + #if not exists(pyloadDBFile): + # copyfile(pyloadDefaultDBFile, pyloadDBFile) if self.config['webinterface']['activated']: self.webserver = WebServer(self) self.webserver.start() -- cgit v1.2.3 From 205c200b94f3b4edf1220a9ffd5ebeab58aa098b Mon Sep 17 00:00:00 2001 From: spoob Date: Thu, 7 Jan 2010 19:05:42 +0100 Subject: Better ConfigParser --- pyLoadCore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index c43fac3c8..16c272d5e 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -90,7 +90,7 @@ class Core(object): self.plugin_folder = join("module", "plugins") - self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml"), join(self.path,"module","config","core_default.xml")) + self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) self.config = self.xmlconfig.getConfig() self.do_kill = False -- cgit v1.2.3 From 3d655ddbfbd96abecb9a9c9bebf6e43eb710ab12 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 10 Jan 2010 16:20:31 +0100 Subject: fixed manage.py, addBox working, some code formatted and cleaned --- pyLoadCore.py | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 16c272d5e..5ae81294d 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -28,49 +28,43 @@ from glob import glob from imp import find_module import logging import logging.handlers -from os import listdir +from os import execv from os import makedirs -from os import sep +from os import sep from os.path import basename -from os.path import abspath from os.path import dirname from os.path import exists from os.path import join -from os import execv -from sys import stdin from re import sub import subprocess from sys import argv +from sys import executable from sys import exit from sys import path from sys import stdout -from sys import executable +from tempfile import NamedTemporaryFile import thread import time from time import sleep -from shutil import copyfile -from tempfile import NamedTemporaryFile +from xmlrpclib import Binary -from module.network.Request import Request -import module.remote.SecureXMLRPCServer as Server +from module.CaptchaManager import CaptchaManager +from module.HookManager import HookManager from module.XMLConfigParser import XMLConfigParser - from module.file_list import File_List +from module.network.Request import Request +import module.remote.SecureXMLRPCServer as Server from module.thread_list import Thread_List from module.web.ServerThread import WebServer -from module.CaptchaManager import CaptchaManager -from module.HookManager import HookManager - -from xmlrpclib import Binary class Core(object): """ pyLoad Core """ def __init__(self): if len(argv) > 1: if argv[1] == "-v" or argv[1] == "--version": - print "pyLoad", CURRENT_VERSION - else: - print "Unknown Command" + print "pyLoad", CURRENT_VERSION + else: + print "Unknown Command" exit() def toggle_pause(self): @@ -90,7 +84,7 @@ class Core(object): self.plugin_folder = join("module", "plugins") - self.xmlconfig = XMLConfigParser(join(self.path,"module","config","core.xml")) + self.xmlconfig = XMLConfigParser(join(self.path, "module", "config", "core.xml")) self.config = self.xmlconfig.getConfig() self.do_kill = False @@ -136,7 +130,7 @@ class Core(object): self.last_update_check = 0 self.update_check_interval = 1800 self.update_available = self.check_update() - self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) + self.logger.info(_("Downloadtime: %s") % self.server_methods.is_time_download()) self.init_server() self.init_webserver() @@ -265,7 +259,7 @@ class Core(object): exit() def isGUIConnected(self): - return self.lastGuiConnected+10 > time.time() + return self.lastGuiConnected + 10 > time.time() def restart(self): self.shutdown() @@ -512,7 +506,7 @@ class ServerMethods(): self.core.file_list.packager.resetFileStatus(fileid) def upload_container(self, filename, type, content): - th = NamedTemporaryFile(mode="w", suffix="."+type, delete=False) + th = NamedTemporaryFile(mode="w", suffix="." + type, delete=False) th.write(content) path = th.name th.close() -- cgit v1.2.3 From 324ed3da96b07d42da753d1314495724ef4c2b7a Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 13 Jan 2010 11:18:03 +0100 Subject: removed Mp3Convert, just load plugin config once --- pyLoadCore.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 5ae81294d..b3f9b9186 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -86,6 +86,8 @@ class Core(object): self.xmlconfig = XMLConfigParser(join(self.path, "module", "config", "core.xml")) self.config = self.xmlconfig.getConfig() + self.parser_plugins = XMLConfigParser(join(self.path, "module", "config", "plugin.xml")) + #~ self.config_plugins = self.parser_plugins.getConfig() self.do_kill = False self.do_restart = False -- cgit v1.2.3 From b1637236297fc5c3278e4d358fa7ec990824db71 Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 13 Jan 2010 14:21:13 +0100 Subject: More YoutubeChannel Options --- pyLoadCore.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index b3f9b9186..0a7fef11a 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -590,6 +590,7 @@ class ServerMethods(): end = self.core.config['reconnect']['endTime'].split(":") return self.core.compare_time(start, end) +# And so it begins... if __name__ == "__main__": pyload_core = Core() try: -- cgit v1.2.3 From ea94eace93bae1f1f9a3fd27c498f1b5309de50b Mon Sep 17 00:00:00 2001 From: spoob Date: Wed, 13 Jan 2010 15:03:23 +0100 Subject: Fixed MyVideo.de (yuck) --- pyLoadCore.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 0a7fef11a..cd928315a 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -267,16 +267,6 @@ class Core(object): self.shutdown() execv(executable, [executable, "pyLoadCore.py"]) - #~ def update(self, file_update=None): - #~ try: - #~ if not file_update: - #~ tmp_zip = __import__("tempfile").NamedTemporaryFile(suffix=".zip").name - #~ file_update = Request().download("http://update.pyload.org/index.php?download=True", tmp_zip) - #~ __import__("module.Unzip", globals(), locals(), "Unzip", -1).Unzip().extract(tmp_zip,"Test/") - #~ self.logger.info(_("Updated pyLoad")) - #~ except: - #~ self.logger.info("Error on updating pyLoad") - def create_plugin_index(self): plugins = glob(join(self.plugin_folder, "hoster", "*.py")) plugins += glob(join(self.plugin_folder, "decrypter", "*.py")) -- cgit v1.2.3 From 2edf36eb45d427262e9f83af90b8b4fc2f69aab8 Mon Sep 17 00:00:00 2001 From: spoob Date: Fri, 15 Jan 2010 15:03:00 +0100 Subject: Better Argument Parsing in Core, littel fixes --- pyLoadCore.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index cd928315a..4b2e63a2c 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -31,6 +31,7 @@ import logging.handlers from os import execv from os import makedirs from os import sep +from os import remove from os.path import basename from os.path import dirname from os.path import exists @@ -47,6 +48,7 @@ import thread import time from time import sleep from xmlrpclib import Binary +from getopt import getopt from module.CaptchaManager import CaptchaManager from module.HookManager import HookManager @@ -60,12 +62,22 @@ from module.web.ServerThread import WebServer class Core(object): """ pyLoad Core """ def __init__(self): + self.arg_links = [] if len(argv) > 1: - if argv[1] == "-v" or argv[1] == "--version": - print "pyLoad", CURRENT_VERSION - else: - print "Unknown Command" - exit() + try: + options, arguments = getopt(argv[1:], 'vcl:') + for option, argument in options: + if option == "-v": + print "pyLoad", CURRENT_VERSION + exit() + elif option == "-c": + remove(join("module", "links.pkl")) + print "Removed Linkliste" + elif option == "-l": + self.arg_links.append(argument) + print "Added %s" % argument + except: + print 'Unknown Argument(s) "%s"' % " ".join(argv[1:]) def toggle_pause(self): if self.thread_list.pause: @@ -137,7 +149,6 @@ class Core(object): self.init_server() self.init_webserver() - linkFile = self.config['general']['link_file'] packs = self.server_methods.get_queue() found = False @@ -151,8 +162,12 @@ class Core(object): pid = found lid = self.file_list.collector.addLink(linkFile) self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) + if self.arg_links: + for link in self.arg_links: + lid = self.file_list.collector.addLink(link) + self.file_list.packager.addFileToPackage(pid, self.file_list.collector.popFile(lid)) + self.file_list.packager.pushPackage2Queue(pid) - self.file_list.continueAborted() while True: @@ -589,4 +604,3 @@ if __name__ == "__main__": pyload_core.shutdown() pyload_core.logger.info("killed pyLoad from Terminal") exit() - -- cgit v1.2.3 From 8d842efb12ee7db88505e3078b626855e55aa4bf Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 17 Jan 2010 18:31:52 +0100 Subject: some fixes, closed #62 ?? --- pyLoadCore.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 4b2e63a2c..96cd1b204 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -303,6 +303,11 @@ class Core(object): self.logger.info(_("created index of plugins")) def compare_time(self, start, end): + + toInt = lambda x: int(x) + start = map(toInt, start) + end = map(toInt, end) + if start == end: return True now = time.localtime()[3:5] -- cgit v1.2.3 From 4eb1404eca2b795d809ee626a057a543043060cb Mon Sep 17 00:00:00 2001 From: RaNaN Date: Thu, 21 Jan 2010 22:13:21 +0100 Subject: some optimizations --- pyLoadCore.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 96cd1b204..05a487cf8 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -23,15 +23,17 @@ """ CURRENT_VERSION = '0.3' +from getopt import getopt import gettext from glob import glob from imp import find_module import logging import logging.handlers +from operator import attrgetter from os import execv from os import makedirs -from os import sep from os import remove +from os import sep from os.path import basename from os.path import dirname from os.path import exists @@ -48,7 +50,6 @@ import thread import time from time import sleep from xmlrpclib import Binary -from getopt import getopt from module.CaptchaManager import CaptchaManager from module.HookManager import HookManager @@ -304,9 +305,8 @@ class Core(object): def compare_time(self, start, end): - toInt = lambda x: int(x) - start = map(toInt, start) - end = map(toInt, end) + start = map(int, start) + end = map(int, end) if start == end: return True @@ -469,8 +469,7 @@ class ServerMethods(): self.core.file_list.save() def del_packages(self, ids): - for id in ids: - self.core.file_list.packager.removePackage(id) + map(self.core.file_list.packager.removePackage, ids) self.core.file_list.save() def kill(self): @@ -481,22 +480,13 @@ class ServerMethods(): self.core.do_restart = True def get_queue(self): - data = [] - for q in self.core.file_list.data["queue"]: - data.append(q.data) - return data + return map(attrgetter("data"), self.core.file_list.data["queue"]) def get_collector_packages(self): - data = [] - for q in self.core.file_list.data["packages"]: - data.append(q.data) - return data + return map(attrgetter("data"), self.core.file_list.data["packages"]) def get_collector_files(self): - files = [] - for f in self.core.file_list.data["collector"]: - files.append(f.id) - return files + return map(attrgetter("id"), self.core.file_list.data["collector"]) def move_file_2_package(self, fid, pid): try: @@ -511,8 +501,7 @@ class ServerMethods(): self.core.file_list.packager.pushPackage2Queue(id) def restart_package(self, packid): - for id in self.core.file_list.packager.getPackageFiles(packid): - self.core.file_list.packager.resetFileStatus(id) + map(self.core.file_list.packager.resetFileStatus, self.core.file_list.packager.getPackageFiles(packid)) def restart_file(self, fileid): self.core.file_list.packager.resetFileStatus(fileid) -- cgit v1.2.3 From 1c6e23e5a0c6719cabac9c60e838a2c1dee17abc Mon Sep 17 00:00:00 2001 From: mkaay Date: Sat, 23 Jan 2010 18:56:41 +0100 Subject: new update url --- pyLoadCore.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 05a487cf8..9a9c0d6ff 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -334,7 +334,7 @@ class Core(object): def check_update(self): try: if self.config['updates']['search_updates']: - version_check = Request().load("http://update.pyload.org/index.php?do=dev%s&download=%s" % (CURRENT_VERSION, False)) + version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION, )) if version_check == "": self.logger.info("No Updates for pyLoad") return False @@ -347,8 +347,11 @@ class Core(object): self.last_update_check = time.time() def install_update(self): - if self.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'])) + if self.config['updates']['search_updates']: + if self.core.config['updates']['install_updates']: + version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION, )) + else: + version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION, )) if version_check == "": return False else: -- cgit v1.2.3 From 769f156ea822d4520620727dc1317224a02bdaaa Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 26 Jan 2010 21:23:16 +0100 Subject: extended script support --- pyLoadCore.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 9a9c0d6ff..7aa38b9b1 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -104,7 +104,7 @@ class Core(object): self.do_kill = False self.do_restart = False - translation = gettext.translation("pyLoad", "locale", languages=[self.config['general']['language']]) + translation = gettext.translation("pyLoad", join(self.path, "locale"), languages=[self.config['general']['language']]) translation.install(unicode=True) self.check_install("Crypto", "pycrypto to decode container files") @@ -347,10 +347,10 @@ class Core(object): self.last_update_check = time.time() def install_update(self): - if self.config['updates']['search_updates']: + if self.config['updates']['search_updates']: if self.core.config['updates']['install_updates']: - version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION, )) - else: + version_check = Request().load("http://get.pyload.org/get/update/%s/" % (CURRENT_VERSION, )) + else: version_check = Request().load("http://get.pyload.org/check/%s/" % (CURRENT_VERSION, )) if version_check == "": return False -- cgit v1.2.3 From 7223256dbcbcad79b5edf0f71f525264903607f9 Mon Sep 17 00:00:00 2001 From: spoob Date: Tue, 26 Jan 2010 22:10:09 +0100 Subject: Better Script Support --- pyLoadCore.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 7aa38b9b1..203639c63 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -119,6 +119,10 @@ class Core(object): self.check_file(self.config['general']['link_file'], _("file for links")) self.check_file(self.config['general']['failed_file'], _("file for failed links")) + + script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/before_reconnect/', 'scripts/after_reconnect/'] # @TODO: yes, replace / with sep + self.check_file(script_folders, _("folders for scripts"), True) + if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) -- cgit v1.2.3 From ce184310fd592047d47de24287b20fee00a587cd Mon Sep 17 00:00:00 2001 From: mkaay Date: Wed, 27 Jan 2010 14:52:42 +0100 Subject: moved script support to a new plugin --- pyLoadCore.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'pyLoadCore.py') diff --git a/pyLoadCore.py b/pyLoadCore.py index 203639c63..7aa38b9b1 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -119,10 +119,6 @@ class Core(object): self.check_file(self.config['general']['link_file'], _("file for links")) self.check_file(self.config['general']['failed_file'], _("file for failed links")) - - script_folders = ['scripts/download_preparing/', 'scripts/download_finished/', 'scripts/package_finished/', 'scripts/before_reconnect/', 'scripts/after_reconnect/'] # @TODO: yes, replace / with sep - self.check_file(script_folders, _("folders for scripts"), True) - if self.config['ssl']['activated']: self.check_install("OpenSSL", "OpenSSL for secure connection", True) self.check_file(self.config['ssl']['cert'], _("ssl certificate"), False, True) -- cgit v1.2.3