#!/usr/bin/env python

import shutil
import paramiko
import os, re, sys

v = paramiko.__version__
v = "1.1.6.2"
if v.find("1.6.1") >= 0:
    src = "paramiko.transport.py"
elif v.find("1.6.2") >= 0:
    src = "paramiko.transport.py.1.6.2"


arch = os.uname()[4]
if re.search('64', arch):
    arch_libdir = 'lib64'
else:
    arch_libdir = 'lib'


dest = "/usr/"+ arch_libdir + "/python2.4/site-packages/paramiko/transport.py"

#try again with lib itself.
if not os.path.exists(dest):
    arch_libdir = "lib"
    dest = "/usr/"+ arch_libdir + \
           "/python2.4/site-packages/paramiko/transport.py"

temp = dest + ".orig"

if os.path.exists(temp):
    print temp, "exists. Patch may be already applied"
    sys.exit(0)

shutil.copyfile(dest, temp)
shutil.copyfile(src,dest)

print "Patch applied. Original file content in ", temp
