From cc5063734679e708b9937fca7e583d7702ffaffe Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Mon, 3 Mar 2014 16:23:41 -0600 Subject: [PATCH] Issue #2667 delta scripts for lightning source name change in xml files handles stored procedures/bundles in localization Former-commit-id: ddcb1011bb90a7088da079255e77fb63fd76cce0 [formerly 8e3e3be372d5db6dfc5897407074bc250fbef294] Former-commit-id: 0811b0580fc06d61ac6aa359b0f5f1f3808b9ef4 --- .../14.3.1/renameLightningSourceInBundles.sh | 9 +++ ...Source.sh => renameLightningSourceInDB.sh} | 0 .../renameLightningSourceInProcedures.sh | 9 +++ .../14.3.1/utility/replaceAttributeInXML.py | 32 ++++++++++ .../utility/updateLightningNameInXML.sh | 64 +++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100755 deltaScripts/14.3.1/renameLightningSourceInBundles.sh rename deltaScripts/14.3.1/{renameLightningSource.sh => renameLightningSourceInDB.sh} (100%) create mode 100755 deltaScripts/14.3.1/renameLightningSourceInProcedures.sh create mode 100755 deltaScripts/14.3.1/utility/replaceAttributeInXML.py create mode 100755 deltaScripts/14.3.1/utility/updateLightningNameInXML.sh diff --git a/deltaScripts/14.3.1/renameLightningSourceInBundles.sh b/deltaScripts/14.3.1/renameLightningSourceInBundles.sh new file mode 100755 index 0000000000..a7213f382e --- /dev/null +++ b/deltaScripts/14.3.1/renameLightningSourceInBundles.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# This script will rename the lightning source column in any D2D bundle files +# This update is only for edex servers which host the cave localization files + +MY_DIR=`dirname $0` +bash $MY_DIR/utility/updateLightningNameInXML.sh -b +exit 0 + diff --git a/deltaScripts/14.3.1/renameLightningSource.sh b/deltaScripts/14.3.1/renameLightningSourceInDB.sh similarity index 100% rename from deltaScripts/14.3.1/renameLightningSource.sh rename to deltaScripts/14.3.1/renameLightningSourceInDB.sh diff --git a/deltaScripts/14.3.1/renameLightningSourceInProcedures.sh b/deltaScripts/14.3.1/renameLightningSourceInProcedures.sh new file mode 100755 index 0000000000..e5291b28dc --- /dev/null +++ b/deltaScripts/14.3.1/renameLightningSourceInProcedures.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# This script will rename the lightning source column in any D2D procedure files +# This update is only for edex servers which host the cave localization files + +MY_DIR=`dirname $0` +bash $MY_DIR/utility/updateLightningNameInXML.sh -p +exit 0 + diff --git a/deltaScripts/14.3.1/utility/replaceAttributeInXML.py b/deltaScripts/14.3.1/utility/replaceAttributeInXML.py new file mode 100755 index 0000000000..a7eb953d24 --- /dev/null +++ b/deltaScripts/14.3.1/utility/replaceAttributeInXML.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# This script will replace attribute values for XML elements that match an xpath + +import sys +import xml.etree.ElementTree as ET + +if len(sys.argv) != 6: + print "Usage: %s [xml inputfile file] [output file name] [xpath] [attribute name] [replacement value]" % (sys.argv[0]) + sys.exit(1) + +print "Parsing XML file at " + sys.argv[1] +tree = ET.parse(sys.argv[1]) +root = tree.getroot() + +matches = root.findall(sys.argv[3]) + +if len(matches) < 1: + print "No matches found, exiting" + sys.exit(0) + +attribute = sys.argv[4] +replValue = sys.argv[5] + +for match in matches: + if attribute in match.attrib: + print "Replacing attribute '%s': old value '%s', new value '%s'" % \ + (attribute, match.attrib[attribute], replValue) + match.attrib[attribute] = replValue + +print "Writing results to file at " + sys.argv[2] +tree.write(sys.argv[2]) +print "Done" diff --git a/deltaScripts/14.3.1/utility/updateLightningNameInXML.sh b/deltaScripts/14.3.1/utility/updateLightningNameInXML.sh new file mode 100755 index 0000000000..4e20f21b25 --- /dev/null +++ b/deltaScripts/14.3.1/utility/updateLightningNameInXML.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# This script will rename the lightning source column in any D2D bundle/procedure files +# This update is only for edex servers which host the cave localization files + +function usage() +{ + echo "Usage: $0 [-p|-b]" + echo "Use '$0 -p to update procedure files" + echo "Use '$0 -b to update bundle files" +} + +if [[ $# < 1 ]] +then + usage + exit 1 +fi + +IFS=$'\n' +if [[ $1 == '-b' ]] +then + files=`find /awips2/edex/data/utility/cave_static/*/*/bundles/ -iname '*.xml'` +elif [[ $1 == '-p' ]] +then + files=`ls /awips2/edex/data/utility/cave_static/*/*/procedures/*.xml` +else + usage + exit 1 +fi + +if [ $? -ne 0 ]; then + echo "No files found." + exit 1 +fi + +echo "" +echo "Press Enter to perform the updates Ctrl-C to quit." +read done + +xpath=".//resourceData[@{http://www.w3.org/2001/XMLSchema-instance}type='lightningResourceData']//mapping[@key='lightSource']" +attributeName="key" +replValue="source" + +MY_DIR=`dirname $0` +for f in $files; do + python $MY_DIR/replaceAttributeInXML.py $f $f.tmp $xpath $attributeName $replValue + if [[ $? == 0 ]] + then + # if output file doesn't exist, xpath wasn't found + if [[ -e $f.tmp ]] + then + mv $f.tmp $f + fi + else + echo "ERROR: Problem updating file $f" + exit 1 + fi +done + + + +echo "INFO: The update finished successfully." +exit 0 +