# getVar.py
# 20080704
# copyright (c), 2008, by Arthur Kevin McGrath
# All rights reserved



# getVariablesInScope
# return a Dictionary with all the variables in a given scope
# parameters:
#       scope
#               String in the form of Node=xxx,Server=yyy
#       varName
#               String optional parameter
#                       if present, the name of the WAS variable
def getVariablesInScope( scope, varName = "@!~~$%^^" ):
  raw = ""
  result = {}
  if varName == "@!~~$%^^":
    try:
      raw = AdminTask.showVariables( "[ -scope " +  scope +  " ]"  )
    except:
      raw = ""
  else:
    try:
      raw = AdminTask.showVariables( "[ -scope " +  scope +  "  -variableName  " + varName +" ]"  )
    except:
      raw = ""
  # convert the string into a proper python List
  raw = raw.replace( "] [", "],[" )
  #strip off outtermost square brackets
  if  len(raw) > 4:
    raw = raw[2:-2]
  else:
    return result
  # convert each WAS variable into a List
  outterList = raw.split(",")
  for o in outterList:
    #make each variable into a key:value
    #strip off the square brackets that surround each key:value pair
    str = o[1:-1]
    #separate the key from the value
    lst = str.split( " ", 1)
    # and add it to our master List
    result[ lst[0] ]  =  lst[1]
  
  return result

 
