diff options
| author | 2010-08-12 11:47:23 +0200 | |
|---|---|---|
| committer | 2010-08-12 11:47:23 +0200 | |
| commit | 46bac1946a3d3f8346517e9a42da457646074c44 (patch) | |
| tree | 2b572a2af0852bbb03c2cd372457772d8ee5a3ae /module | |
| parent | renaming fix, get job by priority (diff) | |
| download | pyload-46bac1946a3d3f8346517e9a42da457646074c44.tar.xz | |
account fixes
Diffstat (limited to 'module')
| -rw-r--r-- | module/AccountManager.py | 27 | ||||
| -rw-r--r-- | module/PluginThread.py | 158 | ||||
| -rw-r--r-- | module/plugins/Account.py | 11 | ||||
| -rw-r--r-- | module/plugins/accounts/RapidshareCom.py | 5 | ||||
| -rw-r--r-- | module/plugins/accounts/UploadedTo.py | 7 | 
5 files changed, 124 insertions, 84 deletions
| diff --git a/module/AccountManager.py b/module/AccountManager.py index 5c3c99276..0122b0223 100644 --- a/module/AccountManager.py +++ b/module/AccountManager.py @@ -126,3 +126,30 @@ class AccountManager():  		for name in self.core.pluginManager.getAccountPlugins():  			self.accounts[name] = {} +	#---------------------------------------------------------------------- +	def updateAccount(self, plugin , user, password, options): +		"""add or update account""" +		 +		if self.accounts.has_key(plugin): +			p = self.getAccountPlugin(plugin) +			p.updateAccounts(user, password, options) +			 +			if self.accounts[plugin].has_key(user): +				self.accounts[plugin][user]["password"] = password +				self.accounts[plugin][user]["options"] = options +			else: +				self.accounts[plugin][user] = {"password": password, "options": options} +		 +			self.saveAccounts() +				 +	#---------------------------------------------------------------------- +	def removeAccount(self, plugin, user): +		"""remove account""" +		if self.accounts.has_key(plugin): +			p = self.getAccountPlugin(plugin) +			p.removeAccount(user) +			 +			if self.accounts.has_key(user): +				del self.accounts[user] +		 +			self.saveAccounts() diff --git a/module/PluginThread.py b/module/PluginThread.py index 2bd078e02..f6707a908 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -39,7 +39,7 @@ class PluginThread(Thread):          Thread.__init__(self)          self.setDaemon(True)          self.m = manager #thread manager -		 +  ########################################################################  class DownloadThread(PluginThread): @@ -49,61 +49,61 @@ class DownloadThread(PluginThread):      def __init__(self, manager):          """Constructor"""          PluginThread.__init__(self, manager) -		 +          self.queue = Queue() # job queue          self.active = False -		 +          self.start() -		 +      #----------------------------------------------------------------------      def run(self):          """run method""" -		 +          while True:              self.active = self.queue.get()              pyfile = self.active -			 +              if self.active == "quit":                  return True -			 +              self.m.log.info(_("Download starts: %s" % pyfile.name)) -			 +              try:                  pyfile.plugin.preprocessing(self) -				 +              except NotImplementedError: -				 +                  self.m.log.error(_("Plugin %s is missing a function.") % pyfile.pluginname)                  continue -			 +              except Abort:                  self.m.log.info(_("Download aborted: %s") % pyfile.name)                  pyfile.setStatus("aborted") -				 +                  self.active = False                  pyfile.release()                  continue -				 +              except Reconnect:                  self.queue.put(pyfile)                  #@TODO                  #pyfile.req.clearCookies() -				 +                  while self.m.reconnecting.isSet():                      sleep(0.5) -				 +                  continue -			 +              except Retry: -				 +                  self.m.log.info(_("Download restarted: %s") % pyfile.name)                  self.queue.put(pyfile)                  continue -			 +              except Fail, e: -				 +                  msg = e.args[0] -				 +                  if msg == "offline":                      pyfile.setStatus("offline")                      self.m.log.warning(_("Download is offline: %s") % pyfile.name) @@ -111,65 +111,65 @@ class DownloadThread(PluginThread):                      pyfile.setStatus("failed")                      self.m.log.warning(_("Download failed: %s | %s") % (pyfile.name, msg))                      pyfile.error = msg -				 +                  self.active = False                  pyfile.release()                  continue -						 +              except error, e:                  code, msg = e                  if self.m.core.debug:                      print "pycurl error", code, msg                      print_exc() -				 +                  if code == 7:                      self.m.log.warning(_("Couldn't connect to host waiting 1 minute and retry."))                      self.queue.put(pyfile)                      continue -					                   					 +                  self.active = False                  pyfile.release()                  continue -			 +              except Exception, e:                  pyfile.setStatus("failed")                  self.m.log.error(_("Download failed: %s | %s") % (pyfile.name, str(e)))                  pyfile.error = str(e) -				 +                  if self.m.core.debug:                      print_exc() -				 +                  self.active = False                  pyfile.release()                  continue -			 -			 + +              finally:                  self.m.core.files.save() -			 -			 + +              self.m.log.info(_("Download finished: %s") % pyfile.name) -			 +              self.m.core.hookManager.downloadFinished(pyfile) -			 +              self.m.core.files.checkPackageFinished(pyfile) -			 +              self.active = False              pyfile.finishIfDone()              self.m.core.files.save() -			 +      #----------------------------------------------------------------------      def put(self, job):          """assing job to thread"""          self.queue.put(job) -	 +      #----------------------------------------------------------------------      def stop(self):          """stops the thread"""          self.put("quit") -		 -		 -		 + + +  ########################################################################  class DecrypterThread(PluginThread):      """thread for decrypting""" @@ -178,33 +178,33 @@ class DecrypterThread(PluginThread):      def __init__(self, manager, pyfile):          """constructor"""          PluginThread.__init__(self, manager) -		 +          self.active = pyfile          manager.localThreads.append(self) -		 +          pyfile.setStatus("decrypting") -		 +          self.start() -		 +      #----------------------------------------------------------------------      def run(self):          """run method""" -		 +          pyfile = self.active -		 +          try:              self.m.log.info(_("Decrypting starts: %s") % self.active.name)              self.active.plugin.preprocessing(self) -				 +          except NotImplementedError: -			 +              self.m.log.error(_("Plugin %s is missing a function.") % self.active.pluginname)              return -		 +          except Fail, e: -			 +              msg = e.args[0] -			 +              if msg == "offline":                  self.active.setStatus("offline")                  self.m.log.warning(_("Download is offline: %s") % self.active.name) @@ -212,36 +212,36 @@ class DecrypterThread(PluginThread):                  self.active.setStatus("failed")                  self.m.log.warning(_("Decrypting failed: %s | %s") % (self.active.name, msg))                  self.active.error = msg -			 +              return -					 -		 + +          except Exception, e: -		 +              self.active.setStatus("failed")              self.m.log.error(_("Decrypting failed: %s | %s") % (self.active.name, str(e)))              self.active.error = str(e) -			 +              if self.m.core.debug:                  print_exc() -			 +              return -		 -		 + +          finally:              self.active.release()              self.active = False              self.m.core.files.save()              self.m.localThreads.remove(self) -	 -		 + +          #self.m.core.hookManager.downloadFinished(pyfile) -	 -		 + +          #self.m.localThreads.remove(self)          #self.active.finishIfDone()          pyfile.delete() -     +  ########################################################################  class HookThread(PluginThread):      """thread for hooks""" @@ -250,24 +250,24 @@ class HookThread(PluginThread):      def __init__(self, m, function, pyfile):          """Constructor"""          PluginThread.__init__(self, m) -		 +          self.f = function          self.active = pyfile -		 +          m.localThreads.append(self) -		 +          pyfile.setStatus("processing") -		 +          self.start() -		 +      def run(self):          self.f(self.active) -		 -		 + +          self.m.localThreads.remove(self)          self.active.finishIfDone() -		 -		 + +  ########################################################################  class InfoThread(PluginThread): @@ -275,18 +275,18 @@ class InfoThread(PluginThread):      def __init__(self, manager, data, pid):          """Constructor"""          PluginThread.__init__(self, manager) -		 +          self.data = data          self.pid = pid # package id          # [ .. (name, plugin) .. ]          self.start() -		 +      #----------------------------------------------------------------------      def run(self):          """run method""" -		 +          plugins = {} -		 +          for url, plugin in self.data:              if plugins.has_key(plugin):                  plugins[plugin].append(url) @@ -300,7 +300,7 @@ class InfoThread(PluginThread):                  for result in plugin.getInfo(urls):                      if not type(result) == list: result = [result]                      self.m.core.files.updateFileInfo(result, self.pid) -				 +                  self.m.core.log.debug("Finished Info Fetching for %s" % pluginname) -		 -		self.m.core.files.save()
\ No newline at end of file + +                self.m.core.files.save()
\ No newline at end of file diff --git a/module/plugins/Account.py b/module/plugins/Account.py index de5fb00d6..bdbbd4c1c 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -43,8 +43,13 @@ class Account():          for user, data in self.accounts:              self.login(user, data) -    def updateAccounts(self, user, password): -        self.accounts[user]["password"] if self.accounts.has_key(user) else self.accounts[user] = {"password":password} +    def updateAccounts(self, user, password, options): +        if self.accounts.has_key(user): +            self.accounts[user]["password"] = password +            self.accounts[user]["options"] = options +        else: +            self.accounts[user] = {"password" : password, "options": options} +                      self.login(user, self.accounts[user])      def removeAccount(self, user): @@ -54,6 +59,8 @@ class Account():          return {              "validuntil": None,              "login": name, +            "password": self.accounts[name]["password"], +            "options": self.accounts[name]["options"],              "trafficleft": None,              "type": self.__name__          } diff --git a/module/plugins/accounts/RapidshareCom.py b/module/plugins/accounts/RapidshareCom.py index 233cd9801..052470ada 100644 --- a/module/plugins/accounts/RapidshareCom.py +++ b/module/plugins/accounts/RapidshareCom.py @@ -47,7 +47,10 @@ class RapidshareCom(Account):                  continue              k, v = t.split("=")              info[k] = v -        out = {"validuntil":None, "login":str(info["accountid"]), "trafficleft":int(info["tskb"]), "type":self.__name__} +             +        out = Account.getAccountInfo(self, user) +        tmp = {"validuntil":None, "login":str(info["accountid"]), "trafficleft":int(info["tskb"]), "type":self.__name__} +        out.update(tmp)          return out diff --git a/module/plugins/accounts/UploadedTo.py b/module/plugins/accounts/UploadedTo.py index 242e6cd5e..d2aa22b22 100644 --- a/module/plugins/accounts/UploadedTo.py +++ b/module/plugins/accounts/UploadedTo.py @@ -42,8 +42,11 @@ class UploadedTo(Account):          raw_valid = re.search(r"Valid until: </span> <span class=.*?>(.*?)</span>", html).group(1)          traffic = int(self.parseTraffic(raw_traffic))          validuntil = int(mktime(strptime(raw_valid.strip(), "%d-%m-%Y %H:%M"))) -        return {"login":user, "validuntil":validuntil, "trafficleft":traffic, "type":self.__name__} -     +        out = Account.getAccountInfo(self, user) +        tmp =  {"login":user, "validuntil":validuntil, "trafficleft":traffic, "type":self.__name__} +        out.update(tmp) +        return out +              def login(self, user, data):          req = self.core.requestFactory.getRequest(self.__name__, user)          req.load("http://uploaded.to/login", None, { "email" : user, "password" : data["password"]}, cookies=True) | 
