Skip to content

Instantly share code, notes, and snippets.

@pobalopalous
Last active May 12, 2022 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pobalopalous/51d997339abb83ff41c52f6ced4760d7 to your computer and use it in GitHub Desktop.
Save pobalopalous/51d997339abb83ff41c52f6ced4760d7 to your computer and use it in GitHub Desktop.
ORDS Create Deploy WAR
#!/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