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())
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)
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"))
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!")
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!")
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)
#!/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)
def test_signature(self): s = librsync.signature(self.rand1) d = librsync.delta(self.rand2, s)
def test_signature(self): s = librsync.signature(self.rand)
#!/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')
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())
def get_signature(filename): with open(filename, "r") as dst: return librsync.signature(dst)
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
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