-
-
Save pobalopalous/51d997339abb83ff41c52f6ced4760d7 to your computer and use it in GitHub Desktop.
ORDS Create Deploy WAR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Python code to create a new ords.war that can be deployed to a supported Apache Tomcat or WebLogic Server container. | |
# The created web archive is based on the ords.war distribution but has the following modification: | |
# - The META-INF files are not copied. | |
# - The web.xml has the configutation directory explicitly set. Setting the config.url environment variable is not required. | |
# | |
# Usage: create_deploy_war <source ords.war> <destination war filename> <configuration directory> | |
# | |
import zipfile | |
import sys | |
import os | |
import xml.etree.ElementTree as ET | |
# Update the web.xml context-param for configuration directory | |
def setConfigDir(data, configdir): | |
newEntry = '<context-param><param-name>config.url</param-name><param-value>' + configdir + '</param-value></context-param></web-app>'; | |
webXML = data.decode().replace('</web-app>', newEntry); | |
return webXML; | |
# Read the input war and write the output war. Do not write certain files and modify the web.xml. | |
def repackage(source, destination, configdir): | |
with zipfile.ZipFile(source, 'r') as zipread: | |
with zipfile.ZipFile(destination, 'w') as zipwrite: | |
for item in zipread.infolist(): | |
# The META-INF files will be ignored | |
if not item.filename.startswith('META-INF/'): | |
data = zipread.read(item.filename); | |
# The web.xml should be modified | |
if item.filename == 'WEB-INF/web.xml': | |
data = setConfigDir(data, configdir); | |
zipwrite.writestr(item, data); | |
print('Done.'); | |
# Simple arguments validation | |
def validateArgs(): | |
if len(sys.argv) != 4: | |
sys.exit('Syntax: create_deploy_war <source ords.war filename> <destination war filename> <configuration directory>'); | |
if not zipfile.is_zipfile(sys.argv[1]): | |
sys.exit('Source ords.war is not valid'); | |
if not os.path.isdir(sys.argv[3]): | |
sys.exit('Configuration directory does not exist'); | |
# main | |
validateArgs(); | |
repackage(sys.argv[1], sys.argv[2], sys.argv[3]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment