#!/awips2/python/bin/python3 # # This script must be run on the host where edex_rcm is installed. # import copy import glob import logging import os import re import shutil import sys from xml.etree.ElementTree import ParseError from xml.parsers.expat import ErrorString from xml.parsers.expat import errors import xml.dom.minidom as minidom import xml.etree.ElementTree as ET DR_NUMBER = "8364_8469" CONFIG_PATHS = ["/awips2/rcm/data/config/persist/config.xml" ] logging.basicConfig(format='%(asctime)-15s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO) log = logging.getLogger("updateRCMConfig.py") class CommentedTreeBuilder(ET.TreeBuilder): def __init__(self, *args, **kwargs): super(CommentedTreeBuilder, self).__init__(*args, **kwargs) def comment(self, data): self.start(ET.Comment, {}) self.data(data) self.end(ET.Comment) def processDir(directory): status = 0 log.info("Processing directory: %s", directory) for root, directories, files in os.walk(directory, topdown=False): for filePath in files: if str(filePath).endswith(".xml"): fullPath = os.path.join(root, filePath) status |= updateFile(fullPath) return status def readHeaderComments(path, rootTag): with open(path, 'r') as inFile: orig = inFile.read() pos = orig.find(rootTag) start = orig.find("", start + 4) if end < 0: # unclosed comment raise Exception("File contains unclosed comment") if end > pos: pos = orig.find(rootTag, end + 3) start = orig.find("