diff options
-rw-r--r-- | config | 2 | ||||
-rw-r--r-- | module/Unzip.py | 50 | ||||
-rwxr-xr-x | module/network/Request.py | 9 | ||||
-rwxr-xr-x | pyLoadCore.py | 42 | ||||
-rwxr-xr-x | pyLoadUpdater.py | 106 |
5 files changed, 84 insertions, 125 deletions
@@ -29,7 +29,7 @@ use_reconnect = False link_file = links.txt failed_file = failed_links.txt reconnect_method = reconnect_method -debug_mode = False +debug_mode = True #hours max_download_time = 5 diff --git a/module/Unzip.py b/module/Unzip.py new file mode 100644 index 000000000..f56fbe751 --- /dev/null +++ b/module/Unzip.py @@ -0,0 +1,50 @@ +import zipfile +import os + +class Unzip: + def __init__(self): + pass + + def extract(self, file, dir): + if not dir.endswith(':') and not os.path.exists(dir): + os.mkdir(dir) + + zf = zipfile.ZipFile(file) + + # create directory structure to house files + self._createstructure(file, dir) + + # extract files to directory structure + for i, name in enumerate(zf.namelist()): + + if not name.endswith('/') and not name.endswith("config"): + print "extracting", name.replace("pyload/","") + outfile = open(os.path.join(dir, name.replace("pyload/","")), 'wb') + outfile.write(zf.read(name)) + outfile.flush() + outfile.close() + + def _createstructure(self, file, dir): + self._makedirs(self._listdirs(file), dir) + + def _makedirs(self, directories, basedir): + """ Create any directories that don't currently exist """ + for dir in directories: + curdir = os.path.join(basedir, dir) + if not os.path.exists(curdir): + os.mkdir(curdir) + + def _listdirs(self, file): + """ Grabs all the directories in the zip structure + This is necessary to create the structure before trying + to extract the file to it. """ + zf = zipfile.ZipFile(file) + + dirs = [] + + for name in zf.namelist(): + if name.endswith('/'): + dirs.append(name.replace("pyload/","")) + + dirs.sort() + return dirs diff --git a/module/network/Request.py b/module/network/Request.py index b80ea44da..cda8e50f1 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -110,7 +110,7 @@ class Request: "Connection: keep-alive", "Keep-Alive: 300"]) - def load(self, url, get={}, post={}, ref=True, cookies=False): + def load(self, url, get={}, post={}, ref=True, cookies=False, just_header=False): if post: post = urllib.urlencode(post) @@ -136,6 +136,13 @@ class Request: if ref and self.lastURL is not None: self.pycurl.setopt(pycurl.REFERER, self.lastURL) + if just_header: + self.pycurl.setopt(pycurl.NOPROGRESS, 1) + self.pycurl.setopt(pycurl.NOBODY, 1) + self.pycurl.perform() + self.pycurl.setopt(pycurl.NOPROGRESS, 0) + self.pycurl.setopt(pycurl.NOBODY, 0) + return self.header self.pycurl.perform() 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 = "" diff --git a/pyLoadUpdater.py b/pyLoadUpdater.py deleted file mode 100755 index e6395a080..000000000 --- a/pyLoadUpdater.py +++ /dev/null @@ -1,106 +0,0 @@ -import urllib -import urllib2 -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -#Copyright (C) 2009 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 <http://www.gnu.org/licenses/>. -# -### - -## read version from core -import re -import zipfile -import os - -class Unzip: - def __init__(self): - pass - - def extract(self, file, dir): - if not dir.endswith(':') and not os.path.exists(dir): - os.mkdir(dir) - - zf = zipfile.ZipFile(file) - - # create directory structure to house files - self._createstructure(file, dir) - - # extract files to directory structure - for i, name in enumerate(zf.namelist()): - - if not name.endswith('/') and not name.endswith("config"): - print "extracting", name.replace("pyload/","") - outfile = open(os.path.join(dir, name.replace("pyload/","")), 'wb') - outfile.write(zf.read(name)) - outfile.flush() - outfile.close() - - def _createstructure(self, file, dir): - self._makedirs(self._listdirs(file), dir) - - def _makedirs(self, directories, basedir): - """ Create any directories that don't currently exist """ - for dir in directories: - curdir = os.path.join(basedir, dir) - if not os.path.exists(curdir): - os.mkdir(curdir) - - def _listdirs(self, file): - """ Grabs all the directories in the zip structure - This is necessary to create the structure before trying - to extract the file to it. """ - zf = zipfile.ZipFile(file) - - dirs = [] - - for name in zf.namelist(): - if name.endswith('/'): - dirs.append(name.replace("pyload/","")) - - dirs.sort() - return dirs - -def main(): - print "Updating pyLoad" - - try: - f = open("pyLoadCore.py", "rb") - version = re.search(r"CURRENT_VERSION = '([0-9.]+)'",f.read()).group(1) - f.close() - except: - version = "0.0.0" - - print "Your version:", version - - req = urllib2.urlopen("http://update.pyload.org/index.php?do="+version) - result = req.readline() - - if result == "False": - print "pyLoad is up-to-date, nothing to do." - return False - - req = urllib2.urlopen("http://update.pyload.org/index.php") - result = req.readline() - print "Newest Version:", result - print "Download new Version" - - urllib.urlretrieve("http://update.pyload.org/index.php?do=download", "lastest_version.zip") - - u = Unzip() - u.extract("lastest_version.zip",".") - -if __name__ == "__main__": - main() |