Archive for the ‘jython’ Category

Old WLST tools

Wednesday, December 2nd, 2009

As you might know after the acquisition of BEA Systems by Oracle, Dev2Dev site has been discontinued. Unfortunately I don’t see a replacement for that, not only we lost some rich information, but a number of good tools. (more…)

Interview with Jython Lead

Wednesday, October 21st, 2009

Just came across this excellent interview with Frank Wierzbicki, who now leads the Jython Development.

Interview can be found here

No WLST cachedir with python.cachedir.skip

Friday, September 11th, 2009

In one of my previous post I have talked about python.cachedir and how it may cause some errors during WLST/Jython initialization.
With WebLogic 11g Oracle has upgraded the Jython Version from 2.1 to 2.2 (see my post here), which opens up yet another way of getting rid of these errors. In fact you can get rid of the cachedir entirely by starting WLST with -Dpython.cachedir.skip=true, this will instruct Jython not to create the CacheDir.
I haven’t done extensive testing with this option but so far I haven’t seen any issues by not creating this cachedir.

Jython 2.2 in WebLogic 11g

Friday, August 21st, 2009

I just started playing around with WebLogic Server 11g and realised that Oracle has upgraded Jython from 2.1 to 2.2, very nice!

(more…)

How are python.cachedir and the error "*sys-package-mgr*: can't create package cache dir" are related

Tuesday, August 4th, 2009

While starting WLST or for that matter Jython, you might have seen this annoying error message,

*sys-package-mgr*: can’t create package cache dir, ‘/tmp/cachedir/packages’
Traceback (innermost last):
File “<iostream>”, line 12, in ?
ImportError: no module named java

(more…)

Default protocol in WebLogic and why is it important

Sunday, July 26th, 2009

If your WebLogic Server makes outbound connections to other systems it is wise to know what a DefaultProtocol is. Generally, when you create a WebLogic domain and haven’t configured SSL you will not have to do anything. (more…)

IDE for WLST

Wednesday, October 22nd, 2008

I have been asked this question many times and recently here, “What IDE should I use for writing WLST/Jython Scripts?” Initially I used PyWin, it was great! After I started using Eclipse as my Java IDE I moved to JyDT. JyDT has all the features I needed, integrates nicely with Eclipse, provides Syntax higlighting and much more. I recommend JyDT if you are just starting of with Jython.

Jython 2.2 is finally here!

Thursday, August 23rd, 2007

The first major production release of Jython after almost 6 years is finally here. Jython 2.2 implements Python 2.2 and also includes a number of features from Python 2.3. Few major features that I like include:

  • New-style classes and their instances are Java serializable
  • Java collections integration
  • New and Improved socket module
  • Support for JDK1.5 and 1.6
  • telnetlib from CPython
  • Lots of bug fixes

The complete changelog is posted at http://www.jython.org/NEWS.
I hope BEA will consider bundling Jython 2.2 in its next major release.

_uacct = “UA-2684269-2″;
urchinTracker();

Jython is just too useful

Wednesday, February 15th, 2006

Recently I had to do this repeatedly while working on a project.
1) Revert files with extension .foo that are checked out from source control under a base directory structure.
2) Sync to the latest copy of these files.
3) Make a copy of these files with extension .foo in a directory that are in different directories underneath this base directory to files with different extension .bar.
4) Delete the original file from source control.
5) Add the copied file to the source control.
This could have been achieved manually or using a shell/perl script. Manually it would have taken me a long time, since I am not very comfortable with a shell or a perl script, thought I would write this in jython. It took me 10 minutes to come up with this script, and while doing so I found an extremely useful module, shutil. The script can be massaged a bit to make it more efficient.
Here’s the script that I wrote.

import os
import shutil
# define the source control commands here
delete = “p4 delete “
add = “p4 add “
forceSync = “p4 sync -f “
revert = “p4 revert “

def dirwalk(dir):
···”’walk a directory tree”’
···for f in os.listdir(dir):
······fullpath = os.path.join(dir, f)
······print “Looking at “+fullpath
······if os.path.isdir(fullpath) and not os.path.islink(fullpath):
·········dirwalk(fullpath)
·········if os.path.isfile(fullpath):
············s = String(fullpath)
············work(s, fullpath)

def work(myStr, thePath):
···if myStr.endsWith(sys.argv[2]):
······# first revert
······theStr = String(revert)
······cStr = theStr.concat(myStr)
······Runtime.getRuntime().exec(cStr)
······# now force sync the file
······theStr = String(forceSync)
······cStr = theStr.concat(myStr)
······Runtime.getRuntime().exec(cStr)
······# now copy the file to a different extension
······_myStr = myStr.replaceAll(sys.argv[2],sys.argv[3])
······# copy the file to the new extension
······shutil.copy(myStr, _myStr)
······# now delete the file from source control
······theStr = String(delete)
······cStr = theStr.concat(myStr)
······Runtime.getRuntime().exec(cStr)
······# now add the new file
······theStr = String(add)
······cStr = theStr.concat(_myStr)
······Runtime.getRuntime().exec(cStr)

“”"
Usage:
java weblogic.WLST c:/scripts/p4files.py d:/myfiles .foo .bar
This will revert all files under myfiles directory from source control, force sync’s the files,
copy the file to the given extension, deletes the file from source control and add the new file
to source control
“”"
dirwalk(sys.argv[1])

As you can see Jython is not only useful to call into Java objects you can also use it to call into operating system for file manipulation and also use most of the python modules with utmost ease.
This is one of the many many uses of Jython.

_uacct = “UA-2684269-2″;
urchinTracker();

WLST as a Jython Module

Friday, January 6th, 2006

Few questions that I answered about WLST as a module via various email queries recently.

What is a Jython Module?
In simple words, a jython Module is more or less like a Java class/object that you can import into other Modules. Lets say, you wrote a script/module ‘A.py’ and you defined a function ‘myFunction’. Now you can import this A.py into a different script, say B.py’ and call the function ‘myFunction’. Here’s how you do it.

A.py
——-
def myFunction():
··print “Hello There!”

def printFirstName(myName):
··print “Hello “+myName

B.py
——
import A
A.myFunction()
A.printFirstName(“satya”)

WLST provides a convienient way for you to import it as a module into your scripts and use all the WLST commands that are supported. The advantage of doing this is you can write Jython Modules without any WebLogic dependency and import WLST module into these modules. For example, now you can have another module C.py where you will import wlstModule.py and A.py.

C.py
——
import A
import wlstModule.py as myWLST
# connect to the server
myWLST.connect(‘weblogic’,'weblogic’,'t3://sghattu:7001′)
# call a function from module A
A.printFirstName(“satya”)
#start and edit session and create a server
myWLST.edit()
myWLST.startEdit()
newSvr = myWLST.cmo.createServer(‘ms1′)
newSvr.setListenPort(8001)
myWLST.activate()
myWLST.disconnect()


What is the difference between WLST as a Module and invoking WLST?
If you invoke WLST via ‘java weblogic.WLST‘, WLST instantiates a Jython Interpreter, creates a WLST Namespace and installs all the WLST functions in it. You can import other modules, but you will not have access to WLST functions from these external modules because when you import other modules they will be imported into the Jython’s Default NameSpace not the WLST NameSpace. To use your modules in WLST namespace you will have to execute the module in wlst NameSpace using execfile(externalModule.py).

Where can I find WLST Module and are there any recommendations
WLST Module is under {WL_HOME}/common/wlst/modules/wlstModule.py. You can also generate one using the writeIniFile command.
If you are using WLST as a module, you should use java org.python.util.jython to invoke your scripts. Do not use java weblogic.WLST and import WLST as a module. This will import WLST Module into WLST NameSpace and if you mix the module calls with straight WLST calls, you will see some weird interactions. This is not recommended. Please use straight Jython if you are using WLST as a Module.

_uacct = “UA-2684269-2″;
urchinTracker();