#!/usr/local/bin/python

import sys ,re

try:
    appDir = sys.argv[1]
    inName = sys.argv[2]
    outName = sys.argv[3]
except IndexError, e:
    print "Usage: python.exe replace-projecthome.py <appdir> <file from> <file to>"
    sys.exit(1)

reg = re.compile("\\\\")
appDir = reg.sub("\\\\\\\\",appDir)
inFile = open(inName, "r")
outFile = open(outName, "w")
regexp1 = re.compile("%%TL_PROJECT_HOME%%")
regexp2 = re.compile("#!/usr/bin/python");
pythonExec = "#!" + appDir + "\python\python.exe"

buf = inFile.readline()
while buf !="":
    buf = regexp1.sub(appDir, buf)
    buf = regexp2.sub(pythonExec, buf)
    outFile.write(buf)
    buf = inFile.readline()

