diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-07-21 12:08:06 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-07-21 12:08:06 +0200 |
commit | 1fce480bc8ba6eeccae5036b6842c8f03c746e0c (patch) | |
tree | b2af1aefad8a866f1ac94ad4b66f4527e42344d6 | |
parent | online check for container (diff) | |
download | pyload-1fce480bc8ba6eeccae5036b6842c8f03c746e0c.tar.xz |
improved online check
-rw-r--r-- | module/Api.py | 8 | ||||
-rw-r--r-- | module/PluginThread.py | 41 | ||||
-rw-r--r-- | module/ThreadManager.py | 8 | ||||
-rwxr-xr-x | pyLoadCli.py | 15 |
4 files changed, 37 insertions, 35 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): diff --git a/pyLoadCli.py b/pyLoadCli.py index 9c456d422..a7750f784 100755 --- a/pyLoadCli.py +++ b/pyLoadCli.py @@ -316,18 +316,9 @@ class Cli: self.client.movePackage((pack.dest + 1) % 2, pack.pid) elif command == "check": - links = [] - for url in args: - if exists(join(OWD, url)): - f = open(join(OWD, url), "rb") - links.extend([x.strip() for x in f.readlines() if x.strip()]) - f.close() - else: - links.append(url) - - print _("Checking %d links:") % len(links) + print _("Checking %d links:") % len(args) print - rid = client.checkOnlineStatus(links).rid + rid = client.checkOnlineStatus(args).rid self.printOnlineCheck(client, rid) @@ -463,7 +454,7 @@ def print_commands(): ("move <pid> <pid2>...", _("Move Packages from Queue to Collector or vice versa")), ("restart_file <fid> <fid2>...", _("Restart files")), ("restart_package <pid> <pid2>...", _("Restart packages")), - ("check <linklist|url> ...", _("Check online status")), + ("check <container|url> ...", _("Check online status, works with local container")), ("check_container path", _("Checks online status of a container file")), ("pause", _("Pause the server")), ("unpause", _("continue downloads")), |