Exemple #1
0
    def _send_hash(self, h):
        """ Sends over the transport streamer the hash h.
        """

        # Sets the future proxy_socket response dict.
        payload = {
            'sid': self.sid,
            'rid': self.rid,
            'node': self.project,
            'hashes': [h],
        }

        # Gets the proxy_socket associated to the SID and send the payload.
        proxy_sock = transport.streamer.get_socket(self.sid)
        proxy_sock.sendall(proxy_socket.pack(payload))

        # Wait until the rsync is finished.
        # TODO: It takes sometimes more than 240 sec (i.e. git pack files)
        self.rsync_finished.wait(240)

        if not self.rsync_finished.is_set():
            self.logger.error('Timeout on rsync detected !')

        # Reset the rsync_finished Event.
        self.rsync_finished.clear()
Exemple #2
0
    def _send_hash(self, h):
        """ Sends over the transport streamer the hash h.
        """

        # Sets the future proxy_socket response dict.
        payload = {
            'sid': self.sid,
            'rid': self.rid,
            'node': self.project,
            'hashes': [h],
        }

        # Gets the proxy_socket associated to the SID and send the payload.
        proxy_sock = transport.streamer.get_socket(self.sid)
        proxy_sock.sendall(proxy_socket.pack(payload))

        # Wait until the rsync is finished.
        # TODO: It takes sometimes more than 240 sec (i.e. git pack files)
        self.rsync_finished.wait(240)

        if not self.rsync_finished.is_set():
            self.logger.error('Timeout on rsync detected !')

        # Reset the rsync_finished Event.
        self.rsync_finished.clear()
Exemple #3
0
    def _on_socks5_data(self, sid, data, **kwargs):
        """ Called when receiving data over the socks5 proxy_socket (xep
        0065).
        """

        deltas = []  # The list of delta.

        # Sets the future proxy_socket response dict.
        ret = {'from': self.boundjid.bare}

        # Gets the current project.
        ret['node'] = data['node']

        # Gets the RID.
        ret['rid'] = data['rid']

        # Gets the list of hashes.
        all_hashes = data['hashes']

        for elem in all_hashes:
            # 'elem' is a tuple. The first element is the relative
            # path to the current file. The second is the server-side
            # hashes associated to this path.
            relpath = elem[0]
            hashes = elem[1]

            # TODO: Handle the possible AttributeError.
            project_path = config['projects'][data['node']]['path']
            project_path = os.path.expanduser(project_path)

            fullpath = os.path.join(project_path, relpath)
            if os.path.exists(fullpath) and os.path.isfile(fullpath):
                # Computes the local delta of the current file.
                patchedfile = open(fullpath, 'rb')
                delta = pyrsync.rsyncdelta(patchedfile, hashes,
                                           blocksize=8192)
                delta = (relpath, delta)

                # Appends the result to the list of delta.
                deltas.append(delta)
            else:
                # TODO: Handle this error ?
                pass

        # Adds the list of deltas in the response dict.
        ret['delta'] = deltas

        # Sends the result over the proxy_socket.
        self.streamer.send(sid, proxy_socket.pack(ret))
Exemple #4
0
    def _on_socks5_data(self, sid, data, **kwargs):
        """ Called when receiving data over the socks5 proxy_socket (xep
        0065).
        """

        deltas = []  # The list of delta.

        # Sets the future proxy_socket response dict.
        ret = {'from': self.boundjid.bare}

        # Gets the current project.
        ret['node'] = data['node']

        # Gets the RID.
        ret['rid'] = data['rid']

        # Gets the list of hashes.
        all_hashes = data['hashes']

        for elem in all_hashes:
            # 'elem' is a tuple. The first element is the relative
            # path to the current file. The second is the server-side
            # hashes associated to this path.
            relpath = elem[0]
            hashes = elem[1]

            # TODO: Handle the possible AttributeError.
            project_path = config['projects'][data['node']]['path']
            project_path = os.path.expanduser(project_path)

            fullpath = os.path.join(project_path, relpath)
            if os.path.exists(fullpath) and os.path.isfile(fullpath):
                # Computes the local delta of the current file.
                patchedfile = open(fullpath, 'rb')
                delta = pyrsync.rsyncdelta(patchedfile, hashes, blocksize=8192)
                delta = (relpath, delta)

                # Appends the result to the list of delta.
                deltas.append(delta)
            else:
                # TODO: Handle this error ?
                pass

        # Adds the list of deltas in the response dict.
        ret['delta'] = deltas

        # Sends the result over the proxy_socket.
        self.streamer.send(sid, proxy_socket.pack(ret))