Trying to call wsadmin objects from a method that is defined in another file gives a NameError

StackOverflow https://stackoverflow.com/questions/16239647

  •  13-04-2022
  •  | 
  •  

Question

I have a script named test.py which is the main script that imports all definitions from def.py.

def.py

def test():
  print AdminApp.list() #Prints the applications installed
#EndDef

and the test.py

import sys
from def import *
test()

This throws a NameError stating that the AdminApp object cannot be identified as a valid function, keyword or variable.

WASX7093I: Issuing message: "WASX7017E: Exception received while running file "test.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<string>", line 10, in ?
  File "/opt/home/echkaay/wsadmin/test.py", line 3, in ?
NameError: AdminApp 

Any direction?

Was it helpful?

Solution 2

As I have globalised the Admin Objects in my definitions.py script, for them to be available throughout, rather then importing them using from definitions import *, I used the execfile.

execfile(scriptPath + "/jython/definitions.py")

That did it.

OTHER TIPS

Is this stanza from wsadminlib.py on developerworks helpful?

# Provide access to wsadminlib methods when accessed as an import.
# This is benign if wsadminlib is opened with execfile().
# Supports both connected and disconnected operations.
# (ie, works when wsadmin is connected to a running server,
# and works when wsadmin is not connected to a server.)
try:
    AdminConfig = sys._getframe(1).f_locals['AdminConfig']
    AdminApp = sys._getframe(1).f_locals['AdminApp']
    AdminControl = sys._getframe(1).f_locals['AdminControl']
    AdminTask = sys._getframe(1).f_locals['AdminTask']
except:
    print "Warning: Caught exception accessing Admin objects. Continuing."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top