#!/usr/bin/python
#
# Script to add Graphics Mode 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")
# check if Graphics Mode has been written or not
GraphicsModeCheck = False

body = ""

for line in infile:
    # if Graphics Mode is there, advance the next line to
    # read past it, and then change the lines to read
    # "<key>Graphics Mode<\key>" and "<string>1920x1080x32</string>"
    if "<key>Graphics Mode</key>" in line:
        line = infile.next()
        line = "        <key>Graphics Mode</key>\n"
        line += "        <string>\"1920x1080x32\"</string>\n"
        GraphicsModeCheck = True
        
    # if we finish the tags and haven't written Graphics Mode yet
    if "</dict>" in line and GraphicsModeCheck == False:
        line = "        <key>Graphics Mode</key>\n"
        line += "        <string>\"1920x1080x32\"</string>\n"
        line += "</dict>\n"
        GraphicsModeCheck = True
        
    body += line
    
infile.close()

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



