示例#1
0
 def _verify_load(self, client, info_hash):
     ex = xmlrpc_client.Error()
     for _ in range(0, 5):
         try:
             return client.torrent(info_hash, fields=['hash'])
         except xmlrpc_client.Error as e:
             ex = e
             sleep(0.5)
     raise ex
示例#2
0
    def move(self, info_hash, dst_path):
        self.stop(info_hash)

        torrent = self.torrent(info_hash, fields=['base_path'])

        try:
            logger.verbose('Creating destination directory `{}`', dst_path)
            self._server.execute.throw('', 'mkdir', '-p', dst_path)
        except xmlrpc_client.Error:
            raise xmlrpc_client.Error("unable to create folder %s" % dst_path)

        self._server.execute.throw('', 'mv', '-u', torrent['base_path'], dst_path)
        self._server.d.set_directory(info_hash, dst_path)
        self.start(info_hash)
示例#3
0
    def load(self, raw_torrent, fields=None, start=False, mkdir=True):

        if fields is None:
            fields = {}
        # First param is empty 'target'
        params = ['', xmlrpc_client.Binary(raw_torrent)]

        # Additional fields to set
        for key, val in fields.items():
            # Values must be escaped if within params
            # TODO: What are the escaping requirements? re.escape works differently on python 3.7+
            params.append('d.%s.set=%s' % (key, re.escape(str(val))))

        if mkdir and 'directory' in fields:
            result = self._server.execute.throw('', 'mkdir', '-p',
                                                fields['directory'])
            if result != 0:
                raise xmlrpc_client.Error('Failed creating directory %s' %
                                          fields['directory'])

        # by default rtorrent won't allow calls over 512kb in size.
        xmlrpc_size = (len(xmlrpc_client.dumps(tuple(params), 'raw_start')) +
                       71680)  # Add 70kb for buffer
        if xmlrpc_size > 524288:
            prev_size = self._server.network.xmlrpc.size_limit()
            self._server.network.xmlrpc.size_limit.set('', xmlrpc_size)

        # Call load method and return the response
        if start:
            result = self._server.load.raw_start(*params)
        else:
            result = self._server.load.raw(*params)

        if xmlrpc_size > 524288:
            self._server.network.xmlrpc.size_limit.set('', prev_size)

        return result