#!/usr/bin/python2.6
#
# @package      hubzero-cli
# @file         hzcomponentparameter
# @author       David Benham <dbenham@purdue.edu>
# @copyright    Copyright (c) 2013 HUBzero Foundation, LLC.
# @license      http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
#
# Copyright (c) 2013 HUBzero Foundation, LLC.
#
# This file is part of: The HUBzero(R) Platform for Scientific Collaboration
#
# The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
# software: you can redistribute it and/or modify it under the terms of
# the GNU Lesser General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# HUBzero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# HUBzero is a registered trademark of HUBzero Foundation, LLC.
#

import argparse
import hubzero.config.webconfig
import re
import traceback


def getConfigValue(args):
	v = hubzero.config.webconfig.getComponentParam(args.component, 
	                                               args.name)
	print v


def setConfigValue(args):
	hubzero.config.webconfig.addComponentParam(args.component, 
	                                           args.name, 
	                                           args.value)


def delConfigValue(args):
	hubzero.config.webconfig.delComponentParam(args.component,
	                                           args.name)


# ####################
# main

# parse the command line
# main parser
parser = argparse.ArgumentParser(prog="hzcomponentparameter")
subparsers = parser.add_subparsers()

# get subcommand
parser_getConfigValue = subparsers.add_parser('get', help='get config value for a component')
parser_getConfigValue.add_argument('component', help='the option value of the component')
parser_getConfigValue.add_argument('name', help='name of value')
parser_getConfigValue.set_defaults(func=getConfigValue)

# set subcommand
parser_setConfigValue = subparsers.add_parser('set', help='set config value for a component')
parser_setConfigValue.add_argument('component', help='the option value of the component')
parser_setConfigValue.add_argument('name', help='name of value')
parser_setConfigValue.add_argument('value', help='actual value')
parser_setConfigValue.set_defaults(func=setConfigValue)

# delete subcommand
parser_delConfigValue = subparsers.add_parser('delete', help='delete config value for a component')
parser_delConfigValue.add_argument('component', help='the option value of the component')
parser_delConfigValue.add_argument('name', help='name of value')
parser_delConfigValue.set_defaults(func=delConfigValue)

args = parser.parse_args()
args.func(args)

exit(0)
