如何使用 Weblogic 脚本工具附加到 sys.path?
我需要以逻辑方式和非交互方式从 Oracle 10 中取消部署应用程序。我想出的解决方案是使用 WLST 并编写一个 python 程序来为我完成这项工作。我遇到的问题是在脚本之外操作 sys.path 。
我使用 Weblogic 的自定义 WLSTTask
Ant 任务调用我的脚本,并通过 arguments
属性将某些参数传递到脚本中。它看起来像这样:
<target name="undeploy-oldest">
<wlsttask
debug="true"
fileName="${basedir}/resources/script/py/undeployOldestApp.py"
arguments="dmi ${user} ${password} ${url} ${basedir}/resources/script/py/" />
</target>
以及脚本本身。
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()
我遇到的问题与 Ant 任务参数列表中的最后一个参数有关。我的印象是 Jython 自动将当前工作目录添加到 sys.path 中;不过,虽然我看到了“.”的条目。在 sys.path
中,从我的自定义 apputil
模块导入不起作用。我怀疑这与 Ant 实际运行的位置以及“.”有关。不代表 undeployOldestApp.py
所在的目录。我尝试使用 WLSTTask
标记内的类路径标记添加 Ant 类路径的路径,但它没有将该路径添加到 Jython 的 sys.path
列表中。
到目前为止,我唯一的成功是 Ant 任务中的最后一个参数,在 import sys 和 from apputil.applist import getAppList 之间,我调用 sys.path .append(sys.argv[5])。然后从导入中正确引用我的脚本,一切都很好。我的偏好是消除这种依赖性,并且 Ant 任务将处理所需路径元素的注入。我没有运气完成这个任务。
我希望我已经说清楚了,并且社区将会有一些新颖的建议,或者至少解释为什么这似乎不起作用。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以使用executeScriptBeforeFile =“true”参数,
或者,您可以尝试从java运行任务:
这可能会让您访问wlsttask上不可用的java任务的一些参数。
Maybe you could use the executeScriptBeforeFile="true" parameter and
Alternatively, you might try to run the task from java:
This might give you access to some parameters of the java task that are not available on the wlsttask one.