diff options
author | mkaay <mkaay@mkaay.de> | 2010-04-29 20:26:18 +0200 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-04-29 20:26:18 +0200 |
commit | 632fb7eb860675a0375b8e3a8669335ec97f6d81 (patch) | |
tree | 8b0cb62f009727b91923946e4e713017b739cea5 | |
parent | Some design modifications (diff) | |
download | pyload-632fb7eb860675a0375b8e3a8669335ec97f6d81.tar.xz |
fixed updater, moved config files, folder for each package now optional
-rw-r--r-- | module/Plugin.py | 6 | ||||
-rw-r--r-- | module/XMLConfigParser.py | 9 | ||||
-rw-r--r-- | module/config/core_default.xml | 1 | ||||
-rw-r--r-- | module/file_list.py | 8 | ||||
-rwxr-xr-x | module/network/Request.py | 6 | ||||
-rw-r--r-- | module/plugins/hoster/HotfileCom.py | 5 | ||||
-rwxr-xr-x | pyLoadCore.py | 42 |
7 files changed, 45 insertions, 32 deletions
diff --git a/module/Plugin.py b/module/Plugin.py index 83610866d..59aa9c1d1 100644 --- a/module/Plugin.py +++ b/module/Plugin.py @@ -24,7 +24,6 @@ from os.path import join from time import sleep import sys -from os.path import exists from module.network.Request import Request from os import makedirs @@ -173,12 +172,13 @@ class Plugin(): def download(self, url, file_name, get={}, post={}, ref=True, cookies=True): download_folder = self.parent.core.config['general']['download_folder'] - if self.pyfile.package.data["package_name"] != (self.parent.core.config['general']['link_file']): + if self.pyfile.package.data["package_name"] != (self.parent.core.config['general']['link_file']) and self.parent.core.xmlconfig.get("general", "folder_per_package", False): self.pyfile.folder = self.pyfile.package.data["package_name"] location = join(download_folder, self.pyfile.folder.decode(sys.getfilesystemencoding())) - if not exists(location): makedirs(location) + makedirs(location) file_path = join(location.decode(sys.getfilesystemencoding()), self.pyfile.status.filename.decode(sys.getfilesystemencoding())) else: file_path = join(download_folder, self.pyfile.status.filename.decode(sys.getfilesystemencoding())) + file_path = join(download_folder, self.pyfile.status.filename.decode(sys.getfilesystemencoding())) self.pyfile.status.filename = self.req.download(url, file_path, get, post, ref, cookies) diff --git a/module/XMLConfigParser.py b/module/XMLConfigParser.py index 50214c49a..575dbd219 100644 --- a/module/XMLConfigParser.py +++ b/module/XMLConfigParser.py @@ -24,11 +24,14 @@ import re from shutil import copy class XMLConfigParser(): - def __init__(self, data, forceDefault=False): + def __init__(self, data, forceDefault=False, defaultFile=None): self.xml = None self.version = "0.1" self.file = data - self.file_default = self.file.replace(".xml", "_default.xml") + if defaultFile: + self.file_default = defaultFile + else: + self.file_default = self.file.replace(".xml", "_default.xml") self.forceDefault = forceDefault self.config = {} self.data = {} @@ -36,7 +39,7 @@ class XMLConfigParser(): self.loadData() self.root = self.xml.documentElement if not forceDefault: - self.defaultParser = XMLConfigParser(data, True) + self.defaultParser = XMLConfigParser(data, True, defaultFile=defaultFile) def loadData(self): file = self.file diff --git a/module/config/core_default.xml b/module/config/core_default.xml index ab247be08..e80892d46 100644 --- a/module/config/core_default.xml +++ b/module/config/core_default.xml @@ -35,6 +35,7 @@ <download_speed_limit type="int" name="Download Speed Limit">0</download_speed_limit> <checksum type="bool" name="Use Checksum">True</checksum> <min_free_space type="int" name="Min Free Space (MB)">200</min_free_space> + <folder_per_package type="bool" name="Create folder for each package">False</folder_per_package> </general> <updates name="Updates"> <search_updates type="bool" name="Search">True</search_updates> diff --git a/module/file_list.py b/module/file_list.py index 01a5924b3..eff96fa9e 100644 --- a/module/file_list.py +++ b/module/file_list.py @@ -44,7 +44,7 @@ class File_List(object): def __init__(self, core): self.core = core self.lock = RLock() - self.download_folder = self.core.config['general']['download_folder'] + self.download_folder = self.core.config["general"]["download_folder"] self.collector = self.pyLoadCollector(self) self.packager = self.pyLoadPackager(self) @@ -59,11 +59,11 @@ class File_List(object): def load(self): self.lock.acquire() try: - pkl_file = open(join(self.core.path, 'module', 'links.pkl'), 'rb') + pkl_file = open(join(self.core.configdir, "links.pkl"), "rb") obj = cPickle.load(pkl_file) except: obj = False - if obj != False and obj['version'] == LIST_VERSION: + if obj != False and obj["version"] == LIST_VERSION: packages = [] queue = [] collector = [] @@ -106,7 +106,7 @@ class File_List(object): pdata["queue"] = [PyLoadPackageData().set(x) for x in self.data["queue"]] pdata["collector"] = [PyLoadFileData().set(x) for x in self.data["collector"]] - output = open(join(self.core.path, 'module', 'links.pkl'), 'wb') + output = open(join(self.core.configdir, "links.pkl"), "wb") cPickle.dump(pdata, output, -1) self.lock.release() diff --git a/module/network/Request.py b/module/network/Request.py index 76f94ae41..d035048ff 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -343,11 +343,7 @@ def getURL(url): """ req = Request() c = req.load(url) - if req.curl: - try: - req.pycurl.close() - except: - pass + req.pycurl.close() return c if __name__ == "__main__": diff --git a/module/plugins/hoster/HotfileCom.py b/module/plugins/hoster/HotfileCom.py index d412ddd23..2a1117fc5 100644 --- a/module/plugins/hoster/HotfileCom.py +++ b/module/plugins/hoster/HotfileCom.py @@ -59,9 +59,8 @@ class HotfileCom(Plugin): def download_html(self): if self.config['premium']: self.req.add_auth(self.config['username'], self.config['password']) - self.url = self.parent.url + "?lang=en" - print self.url - self.html[0] = self.load(self.url, cookies=True) + self.url = self.parent.url + self.html[0] = self.load(self.url, get={"lang":"en"}, cookies=True) def get_file_url(self): if self.config['premium']: diff --git a/pyLoadCore.py b/pyLoadCore.py index ac4d387c5..0dd8ba28f 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -45,6 +45,7 @@ from os.path import dirname from os.path import exists from os.path import isabs from os.path import join +from os.path import expanduser from re import sub import signal import subprocess @@ -79,25 +80,31 @@ class Core(object): self.arg_links = [] self.path = abspath(dirname(__file__)) chdir(self.path) + self.homedir = self.getHomeDir() + if platform == "posix": + self.configdir = self.make_path(self.homedir, ".config", "pyload") + else: + self.configdir = self.make_path(self.homedir, "pyload") + self.check_file(self.configdir, "folder for config files", True, quiet=True) #check if no config exists, assume its first run - if not exists(join(self.path, "module", "config", "core.xml")): + if not exists(join(self.configdir, "core.xml")): print "No configuration file found." print "Startig Configuration Assistent" print "" from module.setup import Setup - self.xmlconfig = XMLConfigParser(self.make_path("module", "config", "core.xml")) + self.xmlconfig = XMLConfigParser(self.make_path(self.configdir, "core.xml"), defaultFile=join(self.path, "module", "config", "core_default.xml")) self.config = self.xmlconfig.getConfig() s = Setup(self.path, self.config) try: result = s.start() if not result: - remove(join(self.path, "module", "config", "core.xml")) + remove(join(self.configdir, "core.xml")) except Exception, e: print e - remove(join(self.path, "module", "config", "core.xml")) + remove(join(self.configdir, "core.xml")) exit() @@ -124,14 +131,14 @@ class Core(object): self.doDebug = True elif option in ("-u", "--user"): from module.setup import Setup - self.xmlconfig = XMLConfigParser(self.make_path("module", "config", "core.xml")) + self.xmlconfig = XMLConfigParser(self.make_path(self.configdir, "core.xml"), defaultFile=join(self.path, "module", "config", "core_default.xml")) self.config = self.xmlconfig.getConfig() s = Setup(self.path, self.config) s.set_user() exit() elif option in ("-s", "--setup"): from module.setup import Setup - self.xmlconfig = XMLConfigParser(self.make_path("module", "config", "core.xml")) + self.xmlconfig = XMLConfigParser(self.make_path(self.configdir, "core.xml"), defaultFile=join(self.path, "module", "config", "core_default.xml")) self.config = self.xmlconfig.getConfig() s = Setup(self.path, self.config) s.start() @@ -182,11 +189,11 @@ class Core(object): self.plugin_folder = self.make_path("module", "plugins") - self.xmlconfig = XMLConfigParser(self.make_path("module", "config", "core.xml")) + self.xmlconfig = XMLConfigParser(self.make_path(self.configdir, "core.xml"), defaultFile=self.make_path(self.path, "module", "config", "core_default.xml")) self.config = self.xmlconfig.getConfig() if self.doDebug == True: self.config['general']['debug_mode'] = True - self.parser_plugins = XMLConfigParser(self.make_path("module", "config", "plugin.xml")) + self.parser_plugins = XMLConfigParser(self.make_path(self.configdir, "plugin.xml"), defaultFile=self.make_path(self.path, "module", "config", "plugin_default.xml")) self.config['ssl']['cert'] = self.make_path(self.config['ssl']['cert']) self.config['ssl']['key'] = self.make_path(self.config['ssl']['key']) @@ -339,7 +346,7 @@ class Core(object): print _("Install %s") % legend if essential: exit() - def check_file(self, check_names, description="", folder=False, empty=True, essential=False): + def check_file(self, check_names, description="", folder=False, empty=True, essential=False, quiet=False): """check wether needed files exists""" tmp_names = [] if not type(check_names) == list: @@ -362,7 +369,7 @@ class Core(object): file_created = False else: file_created = False - if not file_exists: + if not file_exists and not quiet: if file_created: print _("%s created") % description else: @@ -433,7 +440,7 @@ class Core(object): thread.join(10) self.file_list.save() except: - self.logger.info(_("error when shutting down")) + self.logger.info(_("error while shutting down")) def check_update(self): try: @@ -480,11 +487,11 @@ class Core(object): finally: return False - def make_path(self, * args): + def make_path(self, *args): if isabs(args[0]): - return args[0] + return join(*args) else: - return join(self.path, * args) + return join(self.path, *args) def freeSpace(self): folder = self.make_path(self.config['general']['download_folder']) @@ -495,6 +502,13 @@ class Core(object): else: s = statvfs(folder) return s.f_bsize * s.f_bavail / 1024 / 1024 #megabyte + + def getHomeDir(self): + try: + from win32com.shell import shellcon, shell + return shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) + except ImportError: # quick semi-nasty fallback for non-windows/win32com case + return expanduser("~") #################################### ########## XMLRPC Methods ########## |