Exemplo n.º 1
0
 def test_patch(self):
     s = librsync.signature(self.rand1)
     d = librsync.delta(self.rand2, s)
     self.rand1.seek(0)
     self.rand2.seek(0)
     o = librsync.patch(self.rand1, d)
     self.assertEqual(o.read(), self.rand2.read())
Exemplo n.º 2
0
 def test_patch(self):
     s = librsync.signature(self.rand1)
     d = librsync.delta(self.rand2, s)
     self.rand1.seek(0)
     self.rand2.seek(0)
     o = librsync.patch(self.rand1, d)
     self.assertEqual(o.read(), self.rand2.read())
Exemplo n.º 3
0
 def signature(self, uid, name):
     res = ''
     if RSYNC:
         temp = get_temp(self.get_path(uid, name))
         with open(temp, 'rb') as f:
             sigature = librsync.signature(f)
         res = b64encode(sigature.read())
     return res
    def add(self, path=None, fileobj=None):
        if path is not None:
            fileobj = bltn_open(os.path.join(self.base_path, path), 'rb')
        sig = librsync.signature(fileobj)
        # Copy the sig to a file in open mode
        with NamedTemporaryFile() as f:
            f.write(sig.read())
            f.seek(0)

            sig_size = os.fstat(sig.fileno()).st_size
            sig_info = tarfile.TarInfo(path)
            sig_info.size = sig_size
            self.tar.addfile(tarinfo=sig_info, fileobj=f)
Exemplo n.º 5
0
    def add(self, path=None, fileobj=None):
        if path is not None:
            fileobj = bltn_open(os.path.join(self.base_path, path), 'rb')
        sig = librsync.signature(fileobj)
        # Copy the sig to a file in open mode
        with NamedTemporaryFile() as f:
            f.write(sig.read())
            f.seek(0)

            sig_size = os.fstat(sig.fileno()).st_size
            sig_info = tarfile.TarInfo(path)
            sig_info.size = sig_size
            self.tar.addfile(tarinfo=sig_info, fileobj=f)
Exemplo n.º 6
0
    def CalculateDelta(self, directory, fileName):

        if os.path.exists(directory + "/" + ".Delta_" + fileName):
            os.remove(directory + "/" + ".Delta_" + fileName)

        # The destination file.
        src = file(self.directoryPath + fileName, 'rb')
        # The source file.
        dst = file(directory + "/" + "." + fileName, 'rb')
        # Step 1: prepare signature of the destination file
        signature = librsync.signature(dst)
        # Step 2: prepare a delta of the source file
        delta = librsync.delta(src, signature)
        #Save delta in a file
        dill.dump(delta, open(directory + "/" + ".Delta_" + fileName, "w"))
Exemplo n.º 7
0
def send_signature(file_name):

    # connect for sync
    client_sig_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    wait_net_service(client_sig_socket, SERVER_IP,
                     pm.SharedPort.server_sig_port)

    # calculate signature
    sig = sync.signature(open(file_name, "rb+"))

    # logging.info("sending signature of file : %s",file_name)

    l = sig.read(BUFFER_SIZE)
    while l:
        client_sig_socket.send(l)
        l = sig.read(BUFFER_SIZE)
    sig.close()
    client_sig_socket.close()

    logging.info("Signature Sent!")
Exemplo n.º 8
0
def send_signature(client_id, ip, file_name, db_conn, client):

    msg = pm.get_sensig_msg(client_id, file_name, db_conn)
    client.send(msg)

    # connect for sync
    server_sig_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    wait_net_service(server_sig_socket, ip, pm.SharedPort.client_sig_port)

    # calculate signature
    sig = sync.signature(open(file_name, "rb+"))

    # logging.info("sending signature of file : %s",file_name)

    l = sig.read(BUFFER_SIZE)
    while l:
        server_sig_socket.send(l)
        l = sig.read(BUFFER_SIZE)
    sig.close()
    server_sig_socket.close()

    logging.info("Signature Sent!")
Exemplo n.º 9
0
 def signature(self, block_size=None):
     "Calculates signature for local file."
     kwargs = {}
     if block_size:
         kwargs['block_size'] = block_size
     return librsync.signature(open(self.path, 'rb'), **kwargs)
Exemplo n.º 10
0
#!/usr/bin/python
import librsync
import tempfile

# get the file objects
dst = file('old.SLDPRT')
src = file('new.SLDPRT')
synced = tempfile.SpooledTemporaryFile(max_size=500000000,mode='w+b')

# do the librsync stuff
signature = librsync.signature(dst)
delta = librsync.delta(src, signature)
librsync.patch(dst,delta,synced)


# write the synced file
synced.seek(0)
syncedfile = open('synced.SLDPRT','wb')
buf = synced.read()
syncedfile.write(buf)
syncedfile.close()

# write the signature to file
signature.seek(0)
sigfile = open('prt.signature','wb')
buf = signature.read()
sigfile.write(buf)
sigfile.close()

# write the delta to file
delta.seek(0)
Exemplo n.º 11
0
 def test_signature(self):
     s = librsync.signature(self.rand1)
     d = librsync.delta(self.rand2, s)
Exemplo n.º 12
0
 def test_signature(self):
     s = librsync.signature(self.rand)
Exemplo n.º 13
0
#!/usr/bin/python
import librsync
import tempfile

# get the file objects
dst = file('old.SLDASM')
src = file('new.SLDASM')
synced = tempfile.SpooledTemporaryFile(max_size=500000000, mode='w+b')

# do the librsync stuff
signature = librsync.signature(dst)
delta = librsync.delta(src, signature)
librsync.patch(dst, delta, synced)

# write the synced file
synced.seek(0)
syncedfile = open('synced.SLDASM', 'wb')
buf = synced.read()
syncedfile.write(buf)
syncedfile.close()

# write the signature to file
signature.seek(0)
sigfile = open('asm.signature', 'wb')
buf = signature.read()
sigfile.write(buf)
sigfile.close()

# write the delta to file
delta.seek(0)
delfile = open('asm.delta', 'wb')
Exemplo n.º 14
0
    def test_string_patch(self):
        src_sig = librsync.signature(BytesIO(self.src))
        delta = librsync.delta(BytesIO(self.dst), src_sig).read()
        out = librsync.patch(BytesIO(self.src), BytesIO(delta))

        self.assertEqual(self.dst, out.read())
Exemplo n.º 15
0
 def test_signature(self):
     s = librsync.signature(self.rand1)
     d = librsync.delta(self.rand2, s)
Exemplo n.º 16
0
 def get_signature(filename):
     with open(filename, "r") as dst:
         return librsync.signature(dst)
Exemplo n.º 17
0
 def signature(self, block_size=None):
     "Calculates signature for local file."
     kwargs = {}
     if block_size:
         kwargs['block_size'] = block_size
     return librsync.signature(open(self.path, 'rb'), **kwargs)
Exemplo n.º 18
0
 def _sync(self, src, dst, dst_path):
     syn = open(dst_path, 'wb')
     signature = librsync.signature(dst)
     delta = librsync.delta(src, signature)
     librsync.patch(dst, delta, syn)
     return True
Exemplo n.º 19
0
    def test_string_patch(self):
        src_sig = librsync.signature(BytesIO(self.src))
        delta = librsync.delta(BytesIO(self.dst), src_sig).read()
        out = librsync.patch(BytesIO(self.src), BytesIO(delta))

        self.assertEqual(self.dst, out.read())
Exemplo n.º 20
0
 def test_signature(self):
     s = librsync.signature(self.rand)
Exemplo n.º 21
0
	def _sync(self,src,dst,dst_path):
		syn = open(dst_path,'wb')
		signature = librsync.signature(dst)
		delta = librsync.delta(src, signature)
		librsync.patch(dst,delta,syn)
		return True