Exemple #1
0
    def test_delta_patch(self):
        data = 'hello'

        with open('.tmp1', 'wb') as f:
            f.write(data)

        new = open('.tmp2', 'wb')
        new.close()

        d = delta('.tmp1', blockchecksums('.tmp2'))

        patchname = patch('.tmp2', d)

        self.assertTrue(filecmp.cmp('.tmp1', patchname))

        os.remove('.tmp1')
        os.remove('.tmp2')
        os.remove(patchname)
Exemple #2
0
    def test_delta_patch(self):
        data = 'hello'

        with open('.tmp1', 'wb') as f:
            f.write(data)

        new = open('.tmp2', 'wb')
        new.close()

        d = delta('.tmp1', blockchecksums('.tmp2'))

        patchname = patch('.tmp2', d)

        self.assertTrue(filecmp.cmp('.tmp1',patchname))

        os.remove('.tmp1')
        os.remove('.tmp2')
        os.remove(patchname)
Exemple #3
0
    def patch(self, path, patch):
        """
        Patch the given path with patch.

        @param path: path.
        @type path: str
        @param patch: patch data.
        @type patch: str (json list)
        @return: return code.
        @rtype: int
        """

        path = self._get_path(path)
        d = json.loads(patch)
        patched = patch(path, d)
        try:
            os.rename(patched, path)
            return paramiko.SFTP_OK
        except OSError as e:
            return paramiko.SFTPServer.convert_errno(e.errno)
Exemple #4
0
    def _process(self, t, request_number, msg):
        """
        Overwritten method for processing incoming requests to except
        and execute synchronization specific requests.

        This is a hook into the paramiko.SFTPServer implementation

        See L{paramiko.SFTPServer._process}
        """
        if t == CMD_BLOCKCHK:
            path = msg.get_string()
            bs = blockchecksums(self.server._get_path(path))
            j = json.dumps(bs)
            message = paramiko.Message()
            message.add_int(request_number)
            message.add_string(j)
            self._send_packet(t, str(message))
            return
        elif t == CMD_DELTA:
            path = msg.get_string()
            bs = json.loads(msg.get_string())
            d = delta(self.server._get_path(path), bs)
            j = json.dumps(d)
            message = paramiko.Message()
            message.add_int(request_number)
            message.add_string(j)
            self._send_packet(t, str(message))
        elif t == CMD_PATCH:
            path = msg.get_string()
            d = json.loads(msg.get_string())
            patched = patch(self.server._get_path(path), d)
            self._send_status(request_number, self.server.rename(patched, path))
        elif t == CMD_OTP:
            self._send_status(request_number, self.server.onetimepass()) 
        else:
            return paramiko.SFTPServer._process(self, t, request_number, msg)
Exemple #5
0
 def patch(self, path, delta):
     patched = patch(path, delta)
     self.instance.remove(path)
     return self.instance.rename(patched, path)
Exemple #6
0
 def patch(self, path, delta):
     patched = patch(path, delta)
     self.instance.remove(path)
     return self.instance.rename(patched, path)