A .split() method typically requires to proceed a list[index] wsadmin command

Many WebSphere® Administrative (wsadmin) commands written in the Jacl scripting language return results in a list followed by the use of lindex or foreach command. Whereas, the same wsadmin commands written in the Jython scripting language returns multiple items as a single string which your scripts must separate out using the .split() method into a functional list.
Most wsadmin methods that return multiple items, such as the result from AdminApp.list or AdminConfig.listTemplates methods require:
  • This graphic is a Linux icon. On Linux: .split("\n")
  • This graphic is a Windows icon. On Windows:.split("\r\n")
Selecting the new line split characters (NewLine object), such as "\n" versus "\r\n", depends on the operating system the WebSphere Application Server is running and not the operating system where the client script is running.

The results of some commands, such as the AdminConfig.showAttribute method, requires you to remove the first open square brace ("[") and last close square brace ("]") and then use the .split(" ") method to obtain a functional list.

The Jacl2Jython program flags any use of list[index] statements or any use of for...in statements as a potential problem. The problem message indicates a .split() method might be missing:
apps = AdminApp.list()[0]  #?PROBLEM? (jacl 123) previous LINDEX \
                            may need variable.split("xx")
serverID = AdminConfig.getid("/Node/myNode/Server:myServer/")
services = AdminConfig.showAttribute(serverID,"services")
for service in services:  #?PROBLEM? (jacl 123) previous \
                           FOR ITEM IN LIST may need variable.split("xx")
To simplify the conversion of Jacl wsadmin scripts, the Jacl2Jython program inserts the following utility method into all converted Jython scripts:
def wsadminToList(inStr):
    outList=[]
    if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
        inStr = inStr[1:-1]
        tmpList = inStr.split(" ")
    else:
        tmpList = inStr.split("\n") #splits for Windows or Linux
    for item in tmpList:
        item = item.rstrip();       #removes any Windows "\r"
        if (len(item)>0):
           outList.append(item)
    return outList
#endDef
The following are examples of modifying the preliminary Jython script file. In addition, provides the optional script choices:
apps = AdminApp.list()

#Option 1: Choose this option if you want to use the wsadminToList() utility method.
#          This option is platform-independant 
appsList = wsadminToList(apps)

#Option 2: Choose this option if the application server is on Linux.
appsList = apps.split("\n")

#Option 3: Choose this option if the application server is on Windows.
appsList = apps.split("\r\n")

# Option 4: Choose this option if the client's and server's JVM are on the same operating system.
appsList = apps.split(java.lang.System.getProperty("line.separator")

app = appsList[0]
serverID = AdminConfig.getid("/Node/myNode/Server:myServer/")
services = AdminConfig.showAttribute(serverID,"services")

#Option 1: Choose this option if you want to use the wsadminToList() utility method.
servicesList = wsadminToList(services)

#Option 2: Choose this option if you do not want to use the wsadminToList() utility method.
servicesList = services[1:-1].split(" ")
for service in servicesList:
Tip: You are not required to use the wsadminToList() utility method. You can edit your Jython scripts to perform the required and appropriate splits, assuming you know the operating system your application server is running for theNewLine object splits. However, using the utility method might be helpful in the beginning to get your converted Jython scripts running, and in addition defines a server platform portability solution.

Feedback