#!/bin/python3

from glob import glob
from sys import stdout
from os import getcwd

def fixHeader(fil, fixln):
    stor = []
    with open(fil,'r') as info:
        for line in info:
            stor.append(line)
    
    if len(stor) >= 1:
        if len(stor[0]) >= 2:
            if stor[0][:2] == "#!":
                print("Fixing " + fil)
                with open(fil, 'w') as outgoing:
                    outgoing.write(fixln + '\n')
                    for line in stor[1:]:
                        outgoing.write(line)

                

def main():
    lst = glob('mgltools_x86_64Linux2_1.5.6/MGLToolsPckgs/AutoDockTools/Utilities24/*.py')
    fixln = "#!" + getcwd() + '/mgltools_x86_64Linux2_1.5.6/bin/pythonsh'
    print(fixln)
    for fil in lst:
        fixHeader(fil, fixln)

if __name__ == '__main__':
    main()
