diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-08-02 12:26:11 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-08-02 12:26:11 +0200 |
commit | ae0a6546752e95735cb8d4086127540619f44419 (patch) | |
tree | 1cc0ada2fb6ae8a54c25d392528c809d62f04641 /module | |
parent | Rapidshare, Netload, Uploaded updated. (diff) | |
download | pyload-ae0a6546752e95735cb8d4086127540619f44419.tar.xz |
reconnect fix
Diffstat (limited to 'module')
-rw-r--r-- | module/AccountManager.py | 53 | ||||
-rw-r--r-- | module/ConfigParser.py | 2 | ||||
-rw-r--r-- | module/PluginManager.py | 19 | ||||
-rw-r--r-- | module/PluginThread.py | 3 | ||||
-rw-r--r-- | module/ThreadManager.py | 16 | ||||
-rw-r--r-- | module/plugins/Account.py | 31 | ||||
-rw-r--r-- | module/plugins/Plugin.py | 2 |
7 files changed, 87 insertions, 39 deletions
diff --git a/module/AccountManager.py b/module/AccountManager.py index 8c4213912..fd2d4c853 100644 --- a/module/AccountManager.py +++ b/module/AccountManager.py @@ -17,6 +17,8 @@ @author: RaNaN """ +from os.path import exists + ######################################################################## class AccountManager(): """manages all accounts""" @@ -28,24 +30,65 @@ class AccountManager(): self.core = core self.accounts = {} # key = ( plugin ) + self.plugins = {} + self.initAccountPlugins() self.loadAccounts() #---------------------------------------------------------------------- - def getAccount(self, plugin): + def getAccountPlugin(self, plugin): """get account instance for plugin or None if anonymous""" - #@TODO ... - return None + if self.accounts.has_key(plugin): + if not self.plugins.has_key(plugin): + self.plugins[plugin] = self.core.pluginManager.getAccountPlugin(plugin)(self, self.accounts[plugin]) + + return self.plugins[plugin] + else: + return None #---------------------------------------------------------------------- def loadAccounts(self): """loads all accounts available""" - pass + + if not exists("accounts.conf"): + f = open("accounts.conf", "wb") + f.close() + + f = open("accounts.conf", "rb") + content = f.readlines() + + plugin = "" + account = "" + + for line in content: + line = line.strip() + + if not line: continue + if line.startswith("#"): continue + + if line.endswith(":"): + plugin = line[:-1] + self.accounts[plugin] = {} + + elif line.startswith("@"): + option = line[1:].split() + self.accounts[plugin][name]["options"].append(tuple(option)) + + elif ":" in line: + name, pw = line.split(":")[:] + self.accounts[plugin][name] = {"pw": pw, "options": []} + + #---------------------------------------------------------------------- def saveAccounts(self): """save all account information""" pass -
\ No newline at end of file + #---------------------------------------------------------------------- + def initAccountPlugins(self): + """init names""" + for name in self.core.pluginManager.getAccountPlugins(): + self.accounts[name] = {} +
\ No newline at end of file diff --git a/module/ConfigParser.py b/module/ConfigParser.py index 3abc5a6ae..859136572 100644 --- a/module/ConfigParser.py +++ b/module/ConfigParser.py @@ -196,7 +196,7 @@ class ConfigParser: with open(filename, "wb") as f: for section in config.iterkeys(): - f.write('%s - "%s":\n' % (section, config[section]["desc"])) + f.write('\n%s - "%s":\n' % (section, config[section]["desc"])) for option, data in config[section].iteritems(): diff --git a/module/PluginManager.py b/module/PluginManager.py index db746975a..bace9807d 100644 --- a/module/PluginManager.py +++ b/module/PluginManager.py @@ -205,22 +205,25 @@ class PluginManager(): """return account class if existent""" if self.accountPlugins.has_key(name): plugin = self.accountPlugins[name] - if plugin.has_key("inst"): - return plugin["inst"] + if plugin.has_key("class"): + return plugin["class"] module = __import__(plugin["path"], globals(), locals(), [plugin["name"]] , -1) - pclass = getattr(module, plugin["name"]) - plugin["inst"] = pclass(self) - - - return plugin["inst"] + plugin["class"] = getattr(module, plugin["name"]) + + return plugin["class"] return None #---------------------------------------------------------------------- def getAccountPlugins(self): - """return list of account modules""" + """return list of account plugin names""" + res = [] + for name in self.accountPlugins.keys(): + res.append(name) + + return res #---------------------------------------------------------------------- def getHookPlugins(self): """return list of hook classes""" diff --git a/module/PluginThread.py b/module/PluginThread.py index a2ac6e027..1adf15172 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -84,7 +84,8 @@ class DownloadThread(PluginThread): except Reconnect: self.queue.put(pyfile) - pyfile.req.clearCookies() + #@TODO + #pyfile.req.clearCookies() while self.m.reconnecting.isSet(): sleep(0.5) diff --git a/module/ThreadManager.py b/module/ThreadManager.py index 6ab651cee..a49885297 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -21,6 +21,8 @@ from threading import Event import PluginThread +from time import sleep + ######################################################################## class ThreadManager: """manages the download threads, assign jobs, reconnect etc""" @@ -73,14 +75,26 @@ class ThreadManager: #---------------------------------------------------------------------- def checkReconnect(self): """checks if reconnect needed""" - active = [x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.threads if x.active] + if not (self.core.server_methods.is_time_reconnect() and self.core.config["reconnect"]["activated"] ): + return False + + active = [x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.threads if x.active] + print active if active.count(True) > 0 and len(active) == active.count(True): self.reconnecting.set() #Do reconnect self.log.info(_("Reconnecting")) + while [x.active.plugin.waiting for x in self.threads if x.active].count(True) != 0: + sleep(0.25) + + + print "wating finsihed" + + print "do reconnect" + self.reconnecting.clear() #---------------------------------------------------------------------- diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 7c8beec76..91636bc5d 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -17,7 +17,7 @@ @author: mkaay """ -from random import randrange +from random import choice import re class Account(): @@ -28,19 +28,19 @@ class Account(): __author_name__ = ("mkaay") __author_mail__ = ("mkaay@mkaay.de") - def __init__(self, manager): + def __init__(self, manager, accounts): self.manager = manager self.core = manager.core - self.configParser = self.core.parser_plugins + self.accounts = accounts - self.accounts = [] - self.register = {} - self.loadAccounts() - def login(self): pass - def getAccountInfo(self, name): + def setAccounts(self, accounts): + #@TODO improve + self.accounts = accounts + + def getAccountInfo(self, namepass): return { "validuntil": None, "login": name, @@ -49,26 +49,13 @@ class Account(): } def getAllAccounts(self): - return map(lambda t: self.getAccountInfo(t[0]), self.accounts) + pass def getAccountRequest(self, plugin): account = self.getAccountData(plugin) req = self.core.requestFactory.getRequest(self.__name__, account[0]) return req - - def loadAccounts(self): - usernames = self.configParser.get(self.__name__, "username") - passwords = self.configParser.get(self.__name__, "password") - - data = zip(usernames.split("\n"), passwords.split("\n")) - self.accounts = [] - for acc in data: - t = (acc[0].strip(), acc[1].strip()) - if t[0] and t[1]: - self.accounts.append(t) - self.login() - def getAccountData(self, plugin): if not len(self.accounts): return None diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index de29dfc4e..19b5983a6 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -78,7 +78,7 @@ class Plugin(object): self.premium = False self.ocr = None # captcha reader instance - self.account = pyfile.m.core.accountManager.getAccount(self.__name__) # account handler instance + self.account = pyfile.m.core.accountManager.getAccountPlugin(self.__name__) # account handler instance self.req = pyfile.m.core.requestFactory.getRequest(self.__name__, self.account) self.log = logging.getLogger("log") |