Skip to content

Commit

Permalink
Merge pull request #343 from ESMCI/wilke/scripts/xmlchange
Browse files Browse the repository at this point in the history
Wilke/scripts/xmlchange
  • Loading branch information
jgfouca authored Aug 7, 2016
2 parents e7b334e + d1df346 commit 252aea7
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions scripts/Tools/xmlchange
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ from CIME.case import Case

import argparse, doctest, shutil, glob, time

logger = logging.getLogger("xmlchange")

###############################################################################
def parse_command_line(args, description):
###############################################################################
Expand All @@ -39,7 +41,7 @@ formatter_class=argparse.ArgumentDefaultsHelpFormatter

CIME.utils.setup_standard_logging_options(parser)

parser.add_argument("listofsettings", nargs="*",
parser.add_argument("listofsettings", nargs="?", default='' ,
help="Comma seperated list of settings in the form: var1=value,var2=value,...")

parser.add_argument("--caseroot", default=os.getcwd(),
Expand Down Expand Up @@ -75,19 +77,33 @@ formatter_class=argparse.ArgumentDefaultsHelpFormatter
args = parser.parse_args(args[1:])

CIME.utils.handle_standard_logging_options(args)

listofsettings = []
if( len(args.listofsettings) == 1 ):
listofsettings = args.listofsettings[0].split(',')
if( len(args.listofsettings) ):
listofsettings = args.listofsettings.split(',')

return args.caseroot, listofsettings, args.file, args.id, args.val, args.subgroup, args.append, args.noecho, args.warn, args.force

def xmlchange(caseroot, listofsettings=None, xmlfile=None, xmlid=None, xmlval=None, subgroup=None,
append=None, noecho=False, warn=None, force=False):
with Case(caseroot, read_only=False) as case:
if listofsettings:
if len(listofsettings):
logger.warning("List of attributes to change: %s" , listofsettings)

# Error handling, exit with grace if xmlval or equal sign is missing. Check first all attributes before changing
for setting in listofsettings:
# Test for equal sign
pair = setting.split("=")
expect(len(pair) == 2 , "Wrong format for %s. Expecting a key value pair in form of key=value." % (setting) )
(xmlid, xmlval) = pair

# Change values
for setting in listofsettings:
(xmlid, xmlval) = setting.split('=', 1)

pair = setting.split("=")
expect(len(pair) == 2 , "Expecting a key value pair in the form of key=value.")
(xmlid, xmlval) = pair

type_str = case.get_type_info(xmlid)
if(append is True):
value = case.get_value(xmlid, resolved=False,
Expand Down

0 comments on commit 252aea7

Please sign in to comment.