From 430b00511f6d52da60cacc099b0eac1947aaf4ff Mon Sep 17 00:00:00 2001 From: "Rici.Yu" Date: Fri, 24 Apr 2015 15:35:56 -0400 Subject: [PATCH] ASM #17194 - add delta script to create/delete non-base files Change-Id: Ic3dabdf70715b1b385b4cbc31aad805b937a4ba6 Former-commit-id: 309b751381da57008f49e07277446d60e75f275c [formerly d3394c40ad25019aa4c0beaeccc600002c08e3fa [formerly 620d6d007fb70570504495c48caed8a14f79fbdd] [formerly 309b751381da57008f49e07277446d60e75f275c [formerly ea060273f714503a80f43ad2310a6b882cb8ab11]]] Former-commit-id: d3394c40ad25019aa4c0beaeccc600002c08e3fa [formerly 620d6d007fb70570504495c48caed8a14f79fbdd] Former-commit-id: d3394c40ad25019aa4c0beaeccc600002c08e3fa Former-commit-id: 419e672b6dfdfafa94e64631a82b8c2b1b2f4a52 --- .../DR17194/convertSerpConfigToUtility.py | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 deltaScripts/14.3.3/DR17194/convertSerpConfigToUtility.py diff --git a/deltaScripts/14.3.3/DR17194/convertSerpConfigToUtility.py b/deltaScripts/14.3.3/DR17194/convertSerpConfigToUtility.py new file mode 100755 index 0000000000..65436f6c7d --- /dev/null +++ b/deltaScripts/14.3.3/DR17194/convertSerpConfigToUtility.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python + + +import sys, os, glob, shutil, pwd + + +def main(): + + REMOVE = """#============================================================================== +# +# The following empty code is here to fool the ifpServer into +# thinking it's a tool. This is so that the configuration will +# appear right next to the primary tool. +# +# DO NOT CHANGE THE LINES BELOW +# +ToolType = "numeric" +WeatherElementEdited = "None" +from numpy import * +HideTool = 1 + +import SmartScript + +class Tool (SmartScript.SmartScript): + def __init__(self, dbss): + SmartScript.SmartScript.__init__(self, dbss) + def execute(self): + return +""" + + dryrun = 0 + if len(sys.argv) > 1 and sys.argv[1] == "-dry": + dryrun = 1 + + print "running %s with dryrun = %d\n\n" % (sys.argv[0], dryrun) + + pws = pwd.getpwnam("awips") + + + cavestatic = '/awips2/edex/data/utility/cave_static' + tool_subpaths = 'gfe/userPython/smartTools' + util_subpaths = 'gfe/userPython/utilities' + tool_list = glob.glob(cavestatic + "/*/*/" + tool_subpaths + "/SerpConfig*.py") + util_list = glob.glob(cavestatic + "/*/*/" + util_subpaths + "/SerpConfig*.py") + print "current tool files:" + print tool_list + print "\ncurrent utilities:" + print util_list + + for f in tool_list: + print "\nworking from %s" % f + dirn, filen = os.path.split(f) + utildir = dirn.replace("smartTools", "utilities") + newfile = os.path.join(utildir, "SerpConfig.py") + if os.path.exists(newfile): + print "%s already exists. No need to create." % newfile + else: + content = open(f).read() + replaced = content.replace(REMOVE, "") + if not dryrun: + if not os.path.exists(utildir): + os.makedirs(utildir) + open(newfile, 'w+').write(replaced) + print "create new file %s" % newfile + + if not dryrun: + if not os.path.exists(newfile): + print "Error: file %s is not created." % newfile + else: + os.chown(newfile, pws.pw_uid, pws.pw_gid) + os.chmod(newfile, 644) + + if filen == "SerpConfig.py": + print "removing override %s" % f + if not dryrun: + os.remove(f) + + print "" + for f in util_list: + dirn, filen = os.path.split(f) + utildir = dirn + newfile = os.path.join(utildir, "SerpConfig.py") + if not os.path.exists(newfile): + if not dryrun: + shutil.copy(f, newfile) + print "create new file %s from %s" % (newfile, filen) + if not dryrun: + if not os.path.exists(newfile): + print "Error: file %s is not created." % newfile + else: + os.chown(newfile, pws.pw_uid, pws.pw_gid) + pass + + +if __name__ == "__main__": + main()