#!/usr/bin/python

# reverse_file.py
#       --copyright--                   Copyright 2007 (C) Tranzoa, Co. All rights reserved.    Warranty: You're free and on your own here. This code is not necessarily up-to-date or of public quality.
#       --url--                         http://www.tranzoa.net/tzpython/
#       --email--                       pycode is the name to send to. tranzoa.com is the place to send to.
#       --bodstamps--
#       November 15, 2005       bar
#       November 18, 2007       bar     turn on doxygen
#       November 27, 2007       bar     insert boilerplate copyright
#       May 17, 2008            bar     email adr
#       May 27, 2012            bar     doxygen namespace
#       --eodstamps--
##      \file
#       \namespace              tzpython.reverse_file
#
#
#       Reverse the data in a file to another file.
#
#

import  array


def reverse_string(s) :
    a = array.array('c', s)
    a.reverse()
    return(a.tostring())



#
#
#       Reverse a file.
#
#
if __name__ == '__main__' :
    import  sys

    import  replace_file

    if  len(sys.argv) != 3 :
        print "Tell me an input and output file!"
        sys.exit(254)

    fi  = open(sys.argv[1], "rb")
    d   = fi.read()
    fi.close()

    r   = reverse_string(d)

    ofn = sys.argv[2]
    tfn = ofn + ".tmp"

    fo  = open(tfn, "wb")
    fo.write(r)
    fo.close()

    replace_file.replace_file(ofn, tfn, ofn + ".bak")


#
#
#
# eof
