#!/bin/python
import sys
import os
import stat
src_file = sys.argv[1]
dst_file = sys.argv[2]
bs = 1024 * 1024
if not os.path.isfile(src_file) :
print "file not found :" , src_file
sys.exit()
if not os.path.isfile(dst_file) :
f2=open(dst_file, 'w')
f2.close()
src_size = os.path.getsize(src_file)
src_stat = os.stat(src_file)
src_time = (src_stat[stat.ST_MTIME], src_stat[stat.ST_MTIME])
dst_size = os.path.getsize(dst_file)
dst_stat = os.stat(dst_file)
dst_time = (dst_stat[stat.ST_MTIME], dst_stat[stat.ST_MTIME])
print "src : time",src_time , "size=",src_size , " " , src_file
print "dst : time",dst_time , "size=",dst_size , " " , dst_file
print "blocksize : ", bs , "bytes"
if src_time == dst_time :
if src_size == dst_size :
print "skip"
sys.exit()
f1 = open(src_file, 'r')
f2 = open(dst_file, 'w')
zero = chr(0x00)
zero_block = zero * bs
while 1:
s = f1.read(bs)
print f1.tell(),"/",src_size,"\r",
if not s:
break
if s == zero_block :
f2.seek( f1.tell() )
else:
f2.write(s)
f2.write( "a" )
f2.truncate( f1.tell() )
f1.close()
f2.close()
os.utime(dst_file, src_time)
print ""
print "done."