Exemplo n.º 1
0
    def load(self, raw_torrent, fields={}, start=False, mkdir=True):

        # First param is empty 'target'
        params = ['', xmlrpclib.Binary(raw_torrent)]

        # Additional fields to set
        for key, val in fields.iteritems():
            # Values must be escaped if within params
            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 xmlrpclib.Error('Failed creating directory %s' %
                                      fields['directory'])

        # by default rtorrent won't allow calls over 512kb in size.
        xmlrpc_size = len(xmlrpclib.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
Exemplo n.º 2
0
    def move(self, info_hash, dst_path):
        self.stop(info_hash)

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

        try:
            log.verbose('Creating destination directory `%s`' % dst_path)
            self._server.execute.throw('', 'mkdir', '-p', dst_path)
        except xmlrpclib.Error:
            raise xmlrpclib.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)
Exemplo n.º 3
0
    def load(self, raw_torrent, fields={}, start=False, mkdir=True):

        # First param is empty 'target'
        params = ['', xmlrpclib.Binary(raw_torrent)]

        # Additional fields to set
        for key, val in fields.iteritems():
            # Values must be escaped if within params
            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 xmlrpclib.Error('Failed creating directory %s' %
                                      fields['directory'])

        # Call load method and return the response
        if start:
            return self._server.load.raw_start(*params)
        else:
            return self._server.load.raw(*params)
Exemplo n.º 4
0
 def provoke_error(*args, **kw):
     raise xmlrpclib.Error()