#!/usr/bin/env python2.7
'''
Script for configuring configure_cassandrajvmheap.xml
'''
import os
import argparse
from lib.scriptutil import *

def parseOptions() :
    global options

    parser = argparse.ArgumentParser()
    parser.add_argument("--cassandraDir", help="The location of the cassandra install dir")
    parser.add_argument("--maxHeap", default="1G")
    parser.add_argument("--heapNewSize", default="200M")
    (options, unknown) = parser.parse_known_args()

    if not options.cassandraDir :
        parser.error("No cassandra directory specified.")

    if not os.path.isdir(options.cassandraDir) :
        parser.error("Directory not found: %s" % options.cassandraDir)

def configureCassandraJvm() :
    cassandraEnv = os.path.join(options.cassandraDir, "conf/cassandra-env.sh")
    replaceAll(cassandraEnv, [
        (r'#MAX_HEAP_SIZE.*', 'MAX_HEAP_SIZE='"%s"'' %options.maxHeap),
        (r'#HEAP_NEWSIZE.*', 'HEAP_NEWSIZE='"%s"'' %options.heapNewSize)])

if __name__ == "__main__":
    parseOptions()
    configureCassandraJvm()

