Exemple #1
0
    def get_torrents(self, view="main"):
        """Get list of all torrents in specified view

        @return: list of L{Torrent} instances

        @rtype: list

        @todo: add validity check for specified view
        """
        self.torrents = []
        methods = torrent.methods
        retriever_methods = [
            m for m in methods if m.is_retriever() and m.is_available(self)
        ]

        m = rpc.Multicall(self)
        m.add("d.multicall", view, "d.get_hash=",
              *[method.rpc_call + "=" for method in retriever_methods])

        results = m.call()[0]  # only sent one call, only need first result

        for result in results:
            results_dict = {}
            # build results_dict
            for m, r in zip(retriever_methods,
                            result[1:]):  # result[0] is the info_hash
                results_dict[m.varname] = rpc.process_result(m, r)

            self.torrents.append(
                Torrent(self, info_hash=result[0], **results_dict))

        self._manage_torrent_cache()
        return (self.torrents)
Exemple #2
0
    def get_torrents(self, view='main'):
        """Get list of all torrents in specified view

        @return: list of L{Torrent} instances

        @rtype: list

        @todo: add validity check for specified view
        """
        self.torrents = []
        retriever_methods = filter(lambda m: m.is_retriever() and m.is_available(self), torrent_methods)
        mc = rpc.Multicall(self)

        if self.method_exists('d.multicall2'):
            mc.add('d.multicall2', '', view, 'd.hash=',
                   *map(lambda m2: ((getattr(m2, 'aliases') or [''])[-1] or m2.rpc_call) + '=', retriever_methods))
        else:
            mc.add('d.multicall', view, 'd.get_hash=',
                   *map(lambda m1: m1.rpc_call + '=', retriever_methods))

        results = mc.call()[0]  # only sent one call, only need first result

        for result in results:
            self.torrents.append(
                Torrent(self, info_hash=result[0],
                        **dict((mc.varname, rpc.process_result(mc, r))
                               for (mc, r) in list(zip(retriever_methods, result[1:])))))  # result[0]=info_hash

        self._manage_torrent_cache()
        return self.torrents
Exemple #3
0
    def get_trackers(self):
        """Get list of Tracker instances for given torrent.

        @return: L{Tracker} instances
        @rtype: list

        @note: also assigns return value to self.trackers
        """
        self.trackers = []
        retriever_methods = [m for m in tracker.methods
                             if m.is_retriever() and m.is_available(self._rt_obj)]

        # need to leave 2nd arg empty (dunno why)
        m = rpc.Multicall(self)
        m.add("t.multicall", self.info_hash, "",
              *[method.rpc_call + "=" for method in retriever_methods])

        results = m.call()[0]  # only sent one call, only need first result

        for result in results:
            results_dict = {}
            # build results_dict
            for m, r in zip(retriever_methods, result):
                results_dict[m.varname] = rpc.process_result(m, r)

            self.trackers.append(Tracker(
                self._rt_obj, self.info_hash, **results_dict))

        return(self.trackers)
Exemple #4
0
    def get_trackers(self):
        """Get list of Tracker instances for given torrent.

        @return: L{Tracker} instances
        @rtype: list

        @note: also assigns return value to self.trackers
        """
        self.trackers = []
        retriever_methods = filter(lambda m: m.is_retriever() and m.is_available(self._rt_obj), tracker_methods)
        mc = rpc.Multicall(self)

        # need to leave 2nd arg empty (dunno why)
        mc.add('t.multicall', self.info_hash, '', *[method.rpc_call + '=' for method in retriever_methods])

        results = mc.call()[0]  # only sent one call, only need first result

        for result in results:
            results_dict = {}
            # build results_dict
            for mc, r in zip(retriever_methods, result):
                results_dict[mc.varname] = rpc.process_result(mc, r)

            self.trackers.append(Tracker(self._rt_obj, self.info_hash, **results_dict))

        return self.trackers
Exemple #5
0
    def get_trackers(self):
        """Get list of Tracker instances for given torrent.

        @return: L{Tracker} instances
        @rtype: list

        @note: also assigns return value to self.trackers
        """
        self.trackers = []
        retriever_methods = [
            m for m in tracker.methods
            if m.is_retriever() and m.is_available(self._rt_obj)
        ]

        # need to leave 2nd arg empty (dunno why)
        m = rpc.Multicall(self)
        m.add("t.multicall", self.info_hash, "",
              *[method.rpc_call + "=" for method in retriever_methods])

        results = m.call()[0]  # only sent one call, only need first result

        for result in results:
            results_dict = {}
            # build results_dict
            for m, r in zip(retriever_methods, result):
                results_dict[m.varname] = rpc.process_result(m, r)

            self.trackers.append(
                Tracker(self._rt_obj, self.info_hash, **results_dict))

        return (self.trackers)
Exemple #6
0
    def get_torrents(self, view="main"):
        """Get list of all torrents in specified view

        @return: list of L{Torrent} instances

        @rtype: list

        @todo: add validity check for specified view
        """
        self.torrents = []
        methods = torrent.methods
        retriever_methods = [m for m in methods
                             if m.is_retriever() and m.is_available(self)]

        m = rpc.Multicall(self)
        m.add("d.multicall", view, "d.get_hash=",
              *[method.rpc_call + "=" for method in retriever_methods])

        results = m.call()[0]  # only sent one call, only need first result

        for result in results:
            results_dict = {}
            # build results_dict
            for m, r in zip(retriever_methods, result[1:]):  # result[0] is the info_hash
                results_dict[m.varname] = rpc.process_result(m, r)

            self.torrents.append(
                Torrent(self, info_hash=result[0], **results_dict)
            )

        self._manage_torrent_cache()
        return(self.torrents)
Exemple #7
0
    def get_files(self):
        """Get list of File instances for given torrent.

        @return: L{File} instances
        @rtype: list

        @note: also assigns return value to self.files
        """

        self.files = []
        retriever_methods = [
            m for m in file.methods
            if m.is_retriever() and m.is_available(self._rt_obj)
        ]
        # 2nd arg can be anything, but it'll return all files in torrent
        # regardless
        m = rpc.Multicall(self)
        m.add("f.multicall", self.info_hash, "",
              *[method.rpc_call + "=" for method in retriever_methods])

        results = m.call()[0]  # only sent one call, only need first result

        offset_method_index = retriever_methods.index(
            rpc.find_method("f.get_offset"))

        # make a list of the offsets of all the files, sort appropriately
        offset_list = sorted([r[offset_method_index] for r in results])

        for result in results:
            results_dict = {}
            # build results_dict
            for m, r in zip(retriever_methods, result):
                results_dict[m.varname] = rpc.process_result(m, r)

            # get proper index positions for each file (based on the file
            # offset)
            f_index = offset_list.index(results_dict["offset"])

            self.files.append(
                File(self._rt_obj, self.info_hash, f_index, **results_dict))

        return (self.files)
Exemple #8
0
    def get_files(self):
        """Get list of File instances for given torrent.

        @return: L{File} instances
        @rtype: list

        @note: also assigns return value to self.files
        """

        self.files = []
        retriever_methods = filter(
            lambda m: m.is_retriever() and m.is_available(self._rt_obj),
            file_methods)
        mc = rpc.Multicall(self)

        # 2nd arg can be anything, but it'll return all files in torrent
        mc.add('f.multicall', self.info_hash, '',
               *[method.rpc_call + '=' for method in retriever_methods])

        results = mc.call()[0]  # only sent one call, only need first result

        offset_method_index = retriever_methods.index(
            rpc.find_method('f.get_offset'))

        # make a list of the offsets of all the files, sort appropriately
        offset_list = sorted([r[offset_method_index] for r in results])

        for result in results:
            results_dict = {}
            # build results_dict
            for mc, r in zip(retriever_methods, result):
                results_dict[mc.varname] = rpc.process_result(mc, r)

            # get proper index positions for each file (based on the file
            # offset)
            f_index = offset_list.index(results_dict['offset'])

            self.files.append(
                File(self._rt_obj, self.info_hash, f_index, **results_dict))

        return self.files
Exemple #9
0
    def get_files(self):
        """Get list of File instances for given torrent.

        @return: L{File} instances
        @rtype: list

        @note: also assigns return value to self.files
        """

        self.files = []
        retriever_methods = [m for m in file.methods
                             if m.is_retriever() and m.is_available(self._rt_obj)]
        # 2nd arg can be anything, but it'll return all files in torrent
        # regardless
        m = rpc.Multicall(self)
        m.add("f.multicall", self.info_hash, "",
              *[method.rpc_call + "=" for method in retriever_methods])

        results = m.call()[0]  # only sent one call, only need first result

        offset_method_index = retriever_methods.index(
            rpc.find_method("f.get_offset"))

        # make a list of the offsets of all the files, sort appropriately
        offset_list = sorted([r[offset_method_index] for r in results])

        for result in results:
            results_dict = {}
            # build results_dict
            for m, r in zip(retriever_methods, result):
                results_dict[m.varname] = rpc.process_result(m, r)

            # get proper index positions for each file (based on the file
            # offset)
            f_index = offset_list.index(results_dict["offset"])

            self.files.append(File(self._rt_obj, self.info_hash,
                                   f_index, **results_dict))

        return(self.files)