Exemple #1
0
    def decrypt(self, plugin_map, password=None, err=False):
        result = []

        self.progress = ProgressInfo("BasePlugin", "", _("decrypting"), 0, 0,
                                     len(self.data), self.owner,
                                     ProgressType.Decrypting)
        # TODO QUEUE_DECRYPT
        for name, urls in plugin_map.iteritems():
            klass = self.core.pluginManager.loadClass("crypter", name)
            plugin = None
            plugin_result = []

            # updating progress
            self.progress.plugin = name
            self.progress.name = _("Decrypting %s links") % len(urls) if len(
                urls) > 1 else urls[0]

            #TODO: dependency check, there is a new error code for this
            # TODO: decrypting with result yielding
            if not klass:
                self.error = True
                if err:
                    plugin_result.extend(
                        LinkStatus(url, url, -1, DS.NotPossible, name)
                        for url in urls)
                self.log.debug("Plugin '%s' for decrypting was not loaded" %
                               name)
            else:
                try:
                    plugin = klass(self.core, password)

                    try:
                        plugin_result = plugin._decrypt(urls)
                    except Retry:
                        sleep(1)
                        plugin_result = plugin._decrypt(urls)

                    plugin.logDebug("Decrypted", plugin_result)

                except Abort:
                    plugin.logInfo(_("Decrypting aborted"))
                except Exception, e:
                    plugin.logError(_("Decrypting failed"), e)

                    self.error = True
                    # generate error linkStatus
                    if err:
                        plugin_result.extend(
                            LinkStatus(url, url, -1, DS.Failed, name)
                            for url in urls)

                    # no debug for intentional errors
                    if self.core.debug and not isinstance(e, Fail):
                        self.core.print_exc()
                        self.writeDebugReport(plugin.__name__, plugin=plugin)
                finally:
                    if plugin:
Exemple #2
0
    def fetchForPlugin(self, plugin, urls, cb):
        """executes info fetching for given plugin and urls"""
        # also works on module names
        pluginname = plugin.__name__.split(".")[-1]
        try:
            cached = []  #results loaded from cache
            process = []  #urls to process
            for url in urls:
                if url in self.m.infoCache:
                    cached.append(self.m.infoCache[url])
                else:
                    process.append(url)

            if cached:
                self.m.log.debug("Fetched %d links from cache for %s" %
                                 (len(cached), pluginname))
                cb(cached)

            if process:
                self.m.log.debug("Run Info Fetching for %s" % pluginname)
                for result in plugin.getInfo(process):
                    #result = [ .. (name, size, status, url) .. ]
                    if not type(result) == list: result = [result]

                    links = []
                    # Convert results to link statuses
                    for res in result:
                        if isinstance(res, LinkStatus):
                            links.append(res)
                        elif type(res) == tuple and len(res) == 4:
                            links.append(
                                LinkStatus(res[3], res[0], int(res[1]), res[2],
                                           pluginname))
                        elif type(res) == tuple and len(res) == 5:
                            links.append(
                                LinkStatus(res[3], res[0], int(res[1]), res[2],
                                           pluginname, res[4]))
                        else:
                            self.m.log.debug("Invalid getInfo result: " +
                                             result)

                    # put them on the cache
                    for link in links:
                        self.m.infoCache[link.url] = link

                    cb(links)

            self.m.log.debug("Finished Info Fetching for %s" % pluginname)
        except Exception, e:
            self.m.log.warning(
                _("Info Fetching for %(name)s failed | %(err)s") % {
                    "name": pluginname,
                    "err": str(e)
                })
            self.core.print_exc()
Exemple #3
0
    def decrypt(self, plugin_map, password=None, err=None):
        result = []

        # TODO QUEUE_DECRYPT

        for name, urls in plugin_map.iteritems():
            klass = self.m.core.pluginManager.loadClass("crypter", name)
            plugin = klass(self.m.core, password)
            plugin_result = []

            try:
                try:
                    plugin_result = plugin._decrypt(urls)
                except Retry:
                    sleep(1)
                    plugin_result = plugin._decrypt(urls)
            except Abort:
                plugin.logInfo(_("Decrypting aborted"))
            except Exception, e:
                plugin.logError(_("Decrypting failed"), e)

                # generate error linkStatus
                if err:
                    plugin_result.extend(
                        LinkStatus(url, url, -1, DS.Failed, name)
                        for url in urls)

                if self.core.debug:
                    self.core.print_exc()
                    self.writeDebugReport(plugin.__name__, plugin=plugin)
            finally:
Exemple #4
0
    def updateResult(self, plugin, result, force=False):
        #parse package name and generate result
        #accumulate results

        self.cache.extend(result)

        if len(self.cache) >= 20 or force:
            #used for package generating
            tmp = [(name, LinkStatus(url, name, plugin, int(size), status))
                   for name, size, status, url in self.cache]

            data = parseNames(tmp)
            self.m.setInfoResults(self.rid, data)

            self.cache = []
    def checkLinks(self, links):
        """ initiates online status check, will also decrypt files.

        :param urls:
        :return: initial set of data as :class:`OnlineCheck` instance containing the result id
        """
        hoster, crypter = self.core.pluginManager.parseUrls(links)

        #: TODO: withhold crypter, derypt or add later
        # initial result does not contain the crypter links
        tmp = [(url, LinkStatus(url, url, pluginname, -1, DS.Queued))
               for url, pluginname in hoster + crypter]
        data = parseNames(tmp)
        rid = self.core.threadManager.createResultThread(data)

        return OnlineCheck(rid, data)
Exemple #6
0
    def checkOnlineStatus(self, urls):
        """ initiates online status check, will also decrypt files.

        :param urls:
        :return: initial set of data as :class:`OnlineCheck` instance containing the result id
        """
        data, crypter = self.core.pluginManager.parseUrls(urls)

        # initial result does not contain the crypter links
        tmp = [(url, (url, LinkStatus(url, pluginname, "unknown", 3, 0)))
               for url, pluginname in data]
        data = parseNames(tmp)
        result = {}

        for k, v in data.iteritems():
            for url, status in v:
                status.packagename = k
                result[url] = status

        data.update(crypter)  # hoster and crypter will be processed
        rid = self.core.threadManager.createResultThread(data, False)

        return OnlineCheck(rid, result)
Exemple #7
0
    def updateResult(self, plugin, result, force=False):
        #parse package name and generate result
        #accumulate results

        self.cache.extend(result)

        if len(self.cache) >= 20 or force:
            #used for package generating
            tmp = [(name, (url,
                           LinkStatus(name, plugin, "unknown", status,
                                      int(size))))
                   for name, size, status, url in self.cache]

            data = parseNames(tmp)
            result = {}
            for k, v in data.iteritems():
                for url, status in v:
                    status.packagename = k
                    result[url] = status

            self.m.setInfoResults(self.rid, result)

            self.cache = []
Exemple #8
0
def to_link_list(links, status=DS.Queued):
    return [
        LinkStatus(link, link, -1, status)
        if isinstance(link, basestring) else link for link in links
    ]
Exemple #9
0
 def getInfo(cls, urls):
     for url in urls:
         yield LinkStatus(url, url + " - checked", randint(1024, 2048),
                          DS.Online)
         sleep(1)