2

I am trying to call one wlst script from another wlst script, by importing the other one. I tried the following:

domain.py

import final

final.foo()

final.py

def foo():
cd('/')

when domain.py calls foo, it fails to recognize CD('/') command as its a wlst specific. i tried importing wlst into final.py but still it didn't work

Jinu Mohan
  • 136
  • 12

2 Answers2

4

Finally, i could figure out. In the final.py we need to import wlstModule and pass wls context to function from domain.py. Also in domain.py changed the way foo is imported. Note the way WLS(case important) is used in domain.py

final.py

from wlstModule import *
def foo(wls):
  wls.cd('/')

domain.py

import java.lang.String as jstring
import java.lang.System as jsystem
from final import foo

foo(WLS)
Jinu Mohan
  • 136
  • 12
  • This seems very helpful for what I am doing, but it doesn't seem to work for me. I am using online WLST, and edit() works in either python file, but startEdit() only works in domain.py. cmo and wls.cmo is a nonetype for me. my results: – Karl Henselin Sep 15 '15 at 20:56
  • print("1") print(cmo) print("2") print(wls) print("3") print(wls.cmo) print("4") wls.cd('/JMSSystemResources/' + ModuleName + '/JMSResource/' + ModuleName) print("5") print(cmo) print("6") print(wls.cmo) 1 None 2 com.oracle.cie.domain.script.jython.WLScriptContext@47487fd9 3 None 4 Error: No domain or domain template has been read. 5 None 6 None – Karl Henselin Sep 15 '15 at 21:00
  • I worked around that, by putting startEdit() in the parent file, and then in the child file using ref = mbean(path I needed) instead of cd, and then using ref.operation instead of cmo.operation – Karl Henselin Sep 15 '15 at 21:05
0

I found another solution to this problem which didn't have the problems the other solution had, but some might say has it's own issues.

I used execfile(final.py) instead of importing the child file. That allowed me to use some of WLST commands such as startEdit(), cmo(), etc. in the child file, since it is actually run in the parent WLST file something like domain.py at runtime. For me, this is what I am going to do as the child scripts already exist and editing them is not ideal way to fix.

PavanDevarakonda
  • 625
  • 5
  • 27
Karl Henselin
  • 1,015
  • 12
  • 17