summaryrefslogtreecommitdiffstats
path: root/module/PluginThread.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/PluginThread.py')
-rw-r--r--module/PluginThread.py374
1 files changed, 188 insertions, 186 deletions
diff --git a/module/PluginThread.py b/module/PluginThread.py
index 2a4312ecd..2bd078e02 100644
--- a/module/PluginThread.py
+++ b/module/PluginThread.py
@@ -18,287 +18,289 @@
@author: RaNaN
"""
-from threading import Thread
from Queue import Queue
-
+from threading import Thread
from time import sleep
from traceback import print_exc
+from module.plugins.Plugin import Abort
+from module.plugins.Plugin import Fail
+from module.plugins.Plugin import Reconnect
+from module.plugins.Plugin import Retry
from pycurl import error
-from module.plugins.Plugin import Abort, Reconnect, Retry, Fail
########################################################################
class PluginThread(Thread):
- """abstract base class for thread types"""
+ """abstract base class for thread types"""
- #----------------------------------------------------------------------
- def __init__(self, manager):
- """Constructor"""
- Thread.__init__(self)
- self.setDaemon(True)
- self.m = manager #thread manager
+ #----------------------------------------------------------------------
+ def __init__(self, manager):
+ """Constructor"""
+ Thread.__init__(self)
+ self.setDaemon(True)
+ self.m = manager #thread manager
########################################################################
class DownloadThread(PluginThread):
- """thread for downloading files from 'real' hoster plugins"""
+ """thread for downloading files from 'real' hoster plugins"""
- #----------------------------------------------------------------------
- def __init__(self, manager):
- """Constructor"""
- PluginThread.__init__(self, manager)
+ #----------------------------------------------------------------------
+ def __init__(self, manager):
+ """Constructor"""
+ PluginThread.__init__(self, manager)
- self.queue = Queue() # job queue
- self.active = False
+ self.queue = Queue() # job queue
+ self.active = False
- self.start()
+ self.start()
- #----------------------------------------------------------------------
- def run(self):
- """run method"""
+ #----------------------------------------------------------------------
+ def run(self):
+ """run method"""
- while True:
- self.active = self.queue.get()
- pyfile = self.active
+ while True:
+ self.active = self.queue.get()
+ pyfile = self.active
- if self.active == "quit":
- return True
+ if self.active == "quit":
+ return True
- self.m.log.info(_("Download starts: %s" % pyfile.name))
+ self.m.log.info(_("Download starts: %s" % pyfile.name))
- try:
- pyfile.plugin.preprocessing(self)
+ try:
+ pyfile.plugin.preprocessing(self)
- except NotImplementedError:
+ except NotImplementedError:
- self.m.log.error(_("Plugin %s is missing a function.") % pyfile.pluginname)
- continue
+ 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")
+ except Abort:
+ self.m.log.info(_("Download aborted: %s") % pyfile.name)
+ pyfile.setStatus("aborted")
- self.active = False
- pyfile.release()
- continue
+ self.active = False
+ pyfile.release()
+ continue
- except Reconnect:
- self.queue.put(pyfile)
- #@TODO
- #pyfile.req.clearCookies()
+ except Reconnect:
+ self.queue.put(pyfile)
+ #@TODO
+ #pyfile.req.clearCookies()
- while self.m.reconnecting.isSet():
- sleep(0.5)
+ while self.m.reconnecting.isSet():
+ sleep(0.5)
- continue
+ continue
- except Retry:
+ except Retry:
- self.m.log.info(_("Download restarted: %s") % pyfile.name)
- self.queue.put(pyfile)
- continue
+ self.m.log.info(_("Download restarted: %s") % pyfile.name)
+ self.queue.put(pyfile)
+ continue
- except Fail,e :
+ except Fail, e:
- msg = e.args[0]
+ msg = e.args[0]
- if msg == "offline":
- pyfile.setStatus("offline")
- self.m.log.warning(_("Download is offline: %s") % pyfile.name)
- else:
- pyfile.setStatus("failed")
- self.m.log.warning(_("Download failed: %s | %s") % (pyfile.name, msg))
- pyfile.error = msg
+ if msg == "offline":
+ pyfile.setStatus("offline")
+ self.m.log.warning(_("Download is offline: %s") % pyfile.name)
+ else:
+ pyfile.setStatus("failed")
+ self.m.log.warning(_("Download failed: %s | %s") % (pyfile.name, msg))
+ pyfile.error = msg
- self.active = False
- pyfile.release()
- continue
+ self.active = False
+ pyfile.release()
+ continue
- except error, e:
- code, msg = e
- if self.m.core.debug:
- print "pycurl error", code, msg
- print_exc()
+ 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
+ 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
+ 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)
+ 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()
+ if self.m.core.debug:
+ print_exc()
- self.active = False
- pyfile.release()
- continue
+ self.active = False
+ pyfile.release()
+ continue
- finally:
- self.m.core.files.save()
+ finally:
+ self.m.core.files.save()
- self.m.log.info(_("Download finished: %s") % pyfile.name)
+ self.m.log.info(_("Download finished: %s") % pyfile.name)
- self.m.core.hookManager.downloadFinished(pyfile)
+ self.m.core.hookManager.downloadFinished(pyfile)
- self.m.core.files.checkPackageFinished(pyfile)
+ self.m.core.files.checkPackageFinished(pyfile)
- self.active = False
- pyfile.finishIfDone()
- self.m.core.files.save()
+ self.active = False
+ pyfile.finishIfDone()
+ self.m.core.files.save()
- #----------------------------------------------------------------------
- def put(self, job):
- """assing job to thread"""
- self.queue.put(job)
+ #----------------------------------------------------------------------
+ def put(self, job):
+ """assing job to thread"""
+ self.queue.put(job)
- #----------------------------------------------------------------------
- def stop(self):
- """stops the thread"""
- self.put("quit")
+ #----------------------------------------------------------------------
+ def stop(self):
+ """stops the thread"""
+ self.put("quit")
########################################################################
class DecrypterThread(PluginThread):
- """thread for decrypting"""
+ """thread for decrypting"""
- #----------------------------------------------------------------------
- def __init__(self, manager, pyfile):
- """constructor"""
- PluginThread.__init__(self, manager)
+ #----------------------------------------------------------------------
+ def __init__(self, manager, pyfile):
+ """constructor"""
+ PluginThread.__init__(self, manager)
- self.active = pyfile
- manager.localThreads.append(self)
+ self.active = pyfile
+ manager.localThreads.append(self)
- pyfile.setStatus("decrypting")
+ pyfile.setStatus("decrypting")
- self.start()
+ self.start()
- #----------------------------------------------------------------------
- def run(self):
- """run method"""
+ #----------------------------------------------------------------------
+ def run(self):
+ """run method"""
- pyfile = self.active
+ pyfile = self.active
- try:
- self.m.log.info(_("Decrypting starts: %s") % self.active.name)
- self.active.plugin.preprocessing(self)
+ try:
+ self.m.log.info(_("Decrypting starts: %s") % self.active.name)
+ self.active.plugin.preprocessing(self)
- except NotImplementedError:
+ except NotImplementedError:
- self.m.log.error(_("Plugin %s is missing a function.") % self.active.pluginname)
- return
+ self.m.log.error(_("Plugin %s is missing a function.") % self.active.pluginname)
+ return
- except Fail,e :
+ except Fail, e:
- msg = e.args[0]
+ msg = e.args[0]
- if msg == "offline":
- self.active.setStatus("offline")
- self.m.log.warning(_("Download is offline: %s") % self.active.name)
- else:
- self.active.setStatus("failed")
- self.m.log.warning(_("Decrypting failed: %s | %s") % (self.active.name, msg))
- self.active.error = msg
+ if msg == "offline":
+ self.active.setStatus("offline")
+ self.m.log.warning(_("Download is offline: %s") % self.active.name)
+ else:
+ self.active.setStatus("failed")
+ self.m.log.warning(_("Decrypting failed: %s | %s") % (self.active.name, msg))
+ self.active.error = msg
- return
+ return
- except Exception, e:
+ 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)
+ 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()
+ if self.m.core.debug:
+ print_exc()
- return
+ return
- finally:
- self.active.release()
- self.active = False
- self.m.core.files.save()
- self.m.localThreads.remove(self)
+ 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.core.hookManager.downloadFinished(pyfile)
- #self.m.localThreads.remove(self)
- #self.active.finishIfDone()
- pyfile.delete()
+ #self.m.localThreads.remove(self)
+ #self.active.finishIfDone()
+ pyfile.delete()
########################################################################
class HookThread(PluginThread):
- """thread for hooks"""
+ """thread for hooks"""
- #----------------------------------------------------------------------
- def __init__(self, m, function, pyfile):
- """Constructor"""
- PluginThread.__init__(self, m)
+ #----------------------------------------------------------------------
+ def __init__(self, m, function, pyfile):
+ """Constructor"""
+ PluginThread.__init__(self, m)
- self.f = function
- self.active = pyfile
+ self.f = function
+ self.active = pyfile
- m.localThreads.append(self)
+ m.localThreads.append(self)
- pyfile.setStatus("processing")
+ pyfile.setStatus("processing")
- self.start()
+ self.start()
- def run(self):
- self.f(self.active)
+ def run(self):
+ self.f(self.active)
- self.m.localThreads.remove(self)
- self.active.finishIfDone()
+ self.m.localThreads.remove(self)
+ self.active.finishIfDone()
########################################################################
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)
- else:
- plugins[plugin] = [url]
+ #----------------------------------------------------------------------
+ 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)
+ else:
+ plugins[plugin] = [url]
- for pluginname, urls in plugins.iteritems():
- plugin = self.m.core.pluginManager.getPlugin(pluginname)
- if hasattr(plugin, "getInfo"):
- self.m.core.log.debug("Run Info Fetching for %s" % pluginname)
- for result in plugin.getInfo(urls):
- if not type(result) == list: result = [result]
- self.m.core.files.updateFileInfo(result, self.pid)
+ for pluginname, urls in plugins.iteritems():
+ plugin = self.m.core.pluginManager.getPlugin(pluginname)
+ if hasattr(plugin, "getInfo"):
+ self.m.core.log.debug("Run Info Fetching for %s" % pluginname)
+ 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.log.debug("Finished Info Fetching for %s" % pluginname)
self.m.core.files.save() \ No newline at end of file