diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/Api.py | 8 | ||||
-rw-r--r-- | module/PluginThread.py | 41 | ||||
-rw-r--r-- | module/ThreadManager.py | 8 |
3 files changed, 34 insertions, 23 deletions
diff --git a/module/Api.py b/module/Api.py index 0cc2dc1d4..e7638560e 100644 --- a/module/Api.py +++ b/module/Api.py @@ -282,7 +282,7 @@ class Api(Iface): return plugins - def checkOnlineStatus(self, urls, container=None): + def checkOnlineStatus(self, urls): """ initiates online status check :param urls: @@ -290,7 +290,7 @@ class Api(Iface): """ data = self.core.pluginManager.parseUrls(urls) - rid = self.core.threadManager.createResultThread(data, False, container) + rid = self.core.threadManager.createResultThread(data, False) tmp = [(url, (url, OnlineStatus(url, pluginname, "unknown", 3, 0))) for url, pluginname in data] data = parseNames(tmp) @@ -315,7 +315,7 @@ class Api(Iface): th.write(str(data)) th.close() - return self.checkOnlineStatus(urls, th.name) + return self.checkOnlineStatus(urls + [th.name]) def pollResults(self, rid): """ Polls the result available for ResultID @@ -323,8 +323,6 @@ class Api(Iface): :param rid: if -1 no more data is available :return: """ - self.core.threadManager.timestamp = time() + 5 * 60 - result = self.core.threadManager.getInfoResult(rid) if "ALL_INFO_FETCHED" in result: diff --git a/module/PluginThread.py b/module/PluginThread.py index b32361f4e..b415d7d60 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -407,7 +407,7 @@ class HookThread(PluginThread): class InfoThread(PluginThread): - def __init__(self, manager, data, pid=-1, rid=-1, add=False, container=None): + def __init__(self, manager, data, pid=-1, rid=-1, add=False): """Constructor""" PluginThread.__init__(self, manager) @@ -417,7 +417,6 @@ class InfoThread(PluginThread): self.rid = rid #result id self.add = add #add packages instead of return result - self.container = container #container file self.cache = [] #accumulated data @@ -427,6 +426,7 @@ class InfoThread(PluginThread): """run method""" plugins = {} + container = [] for url, plugin in self.data: if plugin in plugins: @@ -434,6 +434,14 @@ class InfoThread(PluginThread): else: plugins[plugin] = [url] + + # filter out container plugins + for name in self.m.core.pluginManager.containerPlugins: + if name in plugins: + container.extend([(name, url) for url in plugins[name]]) + + del plugins[name] + #directly write to database if self.pid > -1: for pluginname, urls in plugins.iteritems(): @@ -467,10 +475,10 @@ class InfoThread(PluginThread): else: #post the results - if self.container: + for name, url in container: #attach container content try: - data = self.decryptContainer() + data = self.decryptContainer(name, url) except: print_exc() self.m.log.error("Could not decrypt container.") @@ -570,17 +578,19 @@ class InfoThread(PluginThread): cb(pluginname, result) - def decryptContainer(self): - url, plugin = self.m.core.pluginManager.parseUrls([self.container])[0] - # decrypt only container - if plugin in self.m.core.pluginManager.containerPlugins: + def decryptContainer(self, plugin, url): + data = [] + # only works on container plugins + + self.m.log.debug("Pre decrypting %s with %s" % (url, plugin)) - # dummy pyfile - pyfile = PyFile(self.m.core.files, -1, url, url, 0, 0, "", plugin, -1, -1) + # dummy pyfile + pyfile = PyFile(self.m.core.files, -1, url, url, 0, 0, "", plugin, -1, -1) - pyfile.initPlugin() + pyfile.initPlugin() - # little plugin lifecycle + # little plugin lifecycle + try: pyfile.plugin.setup() pyfile.plugin.loadToDisk() pyfile.plugin.decrypt(pyfile) @@ -590,8 +600,9 @@ class InfoThread(PluginThread): pyfile.plugin.urls.extend(pack[1]) data = self.m.core.pluginManager.parseUrls(pyfile.plugin.urls) + except : + pass + finally: pyfile.release() - return data - - return [] + return data diff --git a/module/ThreadManager.py b/module/ThreadManager.py index 159b495cd..7b64a2f9a 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -88,14 +88,14 @@ class ThreadManager: PluginThread.InfoThread(self, data, pid) @lock - def createResultThread(self, data, add=False, container=None): + def createResultThread(self, data, add=False): """ creates a thread to fetch online status, returns result id """ self.timestamp = time() + 5 * 60 rid = self.resultIDs self.resultIDs += 1 - PluginThread.InfoThread(self, data, rid=rid, add=add, container=container) + PluginThread.InfoThread(self, data, rid=rid, add=add) return rid @@ -103,6 +103,8 @@ class ThreadManager: @lock def getInfoResult(self, rid): """returns result and clears it""" + self.timestamp = time() + 5 * 60 + if rid in self.infoResults: data = self.infoResults[rid] self.infoResults[rid] = {} @@ -148,9 +150,9 @@ class ThreadManager: #it may be failed non critical so we try it again if (self.infoCache or self.infoResults) and self.timestamp < time(): - self.log.debug("Cleared Result cache") self.infoCache.clear() self.infoResults.clear() + self.log.debug("Cleared Result cache") #---------------------------------------------------------------------- def tryReconnect(self): |