I need to logically and non-interactively undeploy an application from Oracle 10. The solution I came up with is to use WLST and write a python program to do the work for me. The problem I have is in manipulating sys.path
outside of the script.
I'm invoking my script using Weblogic's custom WLSTTask
Ant task and passing certain arguments into the script via the arguments
attribute. It looks like this:
<target name="undeploy-oldest">
<wlsttask
debug="true"
fileName="${basedir}/resources/script/py/undeployOldestApp.py"
arguments="dmi ${user} ${password} ${url} ${basedir}/resources/script/py/" />
</target>
And the script itself.
import sys
from apputil.applist import getAppList
from apputil.apputility import getOldestAppVersion
from wlstModule import connect, disconnect, undeploy
appName = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
url = sys.argv[4]
connect(username, password, url)
serverAppList = getAppList()
versionToUndeploy = getOldestAppVersion(appName, serverAppList)
if (versionToUndeploy != -1):
undeploy(versionToUndeploy)
print "Undeployed " + versionToUndeploy
else:
print "Nothing to undeploy"
disconnect()
The problem I'm having has to do with the last argument in the Ant task's arguments list. I was under the impression that Jython adds the current working directory to sys.path
automatically; though, while I see an entry for "." in sys.path
, the imports from my custom apputil
module do not work. I suspect this has to do with where Ant is actually running from and that "." doesn't represent the directory in which undeployOldestApp.py
exists. I tried adding the path to the Ant classpath with a classpath tag inside the WLSTTask
tag, but it didn't add that path to Jython's sys.path
list.
My only success so far has been in that last argument in the Ant task, where in between import sys
and from apputil.applist import getAppList
I call sys.path.append(sys.argv[5])
. My scripts are then referenced properly from the import and all is well. My preference would be that I eliminate this dependency and that the Ant task would handle injection of the desired path element. I have had no luck accomplishing this.
I hope I've been clear, and that the community will ahve some novel suggestions or at least explanations for why this doesn't seem to work. Thanks.