Beispiel #1
0
 def has_local_id(self, info_hash):
     method = rpc.find_method('d.get_local_id')
     result = True
     try:
         func = filter(lambda m: self.method_exists(m), (method.rpc_call,) + method.aliases)[0]
         getattr(self.get_connection(), func)(info_hash)
     except(xmlrpclib.Fault, BaseException):
         result = False
     return result
Beispiel #2
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)
Beispiel #3
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
Beispiel #4
0
    def execute_func(self, func_name, param=None, extra=None):
        
        param = ([param], param)[isinstance(param, list)]
        for x in (extra or []):
            try:
                call, arg = x.split('=')
                method = rpc.find_method(call)
                method_name = filter(lambda m: self.method_exists(m), (method.rpc_call,) + method.aliases)[0]
                param += ['%s=%s' % (method_name, arg)]
            except(Exception, BaseException):
                pass

        method = getattr(self.get_connection(), func_name)

        if not self.use_target:
            try:
                method(*param)
            except(Exception, BaseException):
                self.use_target = True
        if self.use_target:
            method('', *param)
Beispiel #5
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)