#!/usr/bin/python """ copy the uncopied portion of a file Copyright (C) 2008 James Cameron (quozl@us.netrek.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import os, sys, time r = open(sys.argv[1], 'r') # input file a = open(sys.argv[2], 'a') # output file, may already exist # seek input to end to determine current size r.seek(0, os.SEEK_END) rs = r.tell() print rs, "size of input." # seek output to end a.seek(0, os.SEEK_END) # get output file length as = a.tell() uncopied = rs - as print as, "size of output,", uncopied, "to be moved." # position input to current output position r.seek(as, os.SEEK_SET) start = time.time() copied = 0 size = max(uncopied/10, 8192*1024) # loop reading and writing until end of file on input chunk = r.read(size) while chunk != '': a.write(chunk) copied += len(chunk) print r.tell(), "moved", len(chunk), "chunk", copied, "copied" chunk = r.read(size) # generate summary elapsed = time.time() - start bps = int(copied / elapsed) print r.tell(), "eof", copied, "copied", bps, "bytes per second"