#!/usr/bin/env python

from optparse import OptionParser

from com.sixsq.slipstream.CommandBase import CommandBase
from com.sixsq.slipstream.Client import Client   
from com.sixsq.slipstream.ConfigHolder import ConfigHolder

class MainProgram(CommandBase):
    '''A command-line program to set directly the statecustom value, such that the dashboard can be made more dynamic.'''
    
    def __init__(self, argv=None):
        self.value = None
        super(MainProgram,self).__init__(argv)

    def parse(self):
        usage = '''%prog [options] <value>

<value>          Value to be set.'''

        self.addIgnoreAbortOption()

        self.options, self.args = self.parser.parse_args()

        if len(self.args) != 1:
                self.usageExit('Error, one argument must be specified')

        self.value = self.args[0]

    def doWork(self):
        configHolder = ConfigHolder(self.options)
        client = Client(configHolder)
        value = client.setRuntimeParameter('statecustom', self.value)

main = MainProgram

##############################################################################
# Executing this module from the command line
##############################################################################

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print '\n\nExecution interrupted by the user... goodbye!'
