#!/usr/bin/python
#
# Script to add UseKernelCache=yes for Chameleon boot loaders
#
# Copyright (C) tonymacx86 LLC

import sys
import os

vol = str(sys.argv[1])
boot = "/Extra/org.chameleon.Boot.plist"
plist = vol + boot
infile = open(plist, "r")

UseKernelCache = False

body = ""

for line in infile:
    if "<key>UseKernelCache</key>" in line:
        UseKernelCache = True

    # if we finish the tags and haven't written UseKernelCache Yet
    if "</dict>" in line:
        line = ""
        if UseKernelCache == False:
            line += "        <key>UseKernelCache</key>\n"
            line += "        <string>Yes</string>\n"
            UseKernelCache = True
            
        line += "</dict>\n"
        
    body += line
    
infile.close()

outfile = open(plist, "w")
outfile.write(body)
outfile.close()
