Jython on Documentum part 3

March 12, 2009 at 5:44 pm | Posted in Continous Integration, Jython | Leave a comment
Tags: , ,

It’s been a while since I’ve blogged and even longer since I blogged about Jython on Documentum. Sadly excessive work schedules have prevented me from blogging as much as I would like and it’s unlikely to change for the forseeable future. Anyway I’m waiting for a build to run so I’ve got 5 minutes for a coffee and a swift blog.

Since my last Jython on Documentum post I’ve been using jython in a real-live project as part of a build system. The next couple of posts will record some things that I found out.

First up is organising script files. In my previous posts I had just been using jython by changing to the installation directory, saving a .py file and running it from the installation directory. This is not really a great way to organise your script files. I’ve found the following organisation to work well though no doubt there are other ways to do the same thing.

First I have my jython installation in say c:\jython2.2.1. So anytime I want to kick off a jython script I do the following:

  • Start a cmd prompt
  • set path=%path%;c:\jython2.2.1
  • jython

Next I organise my jython scripts in the source code repository in their own folder structure. Something like /scripts/jython/dctm or something similar. The scripts can then be included in builds or deployments as necessary.

A useful object to know about is the sys.path object. This is represents the classpath that jython uses to pickup python libraries, this includes libraries you write yourself (just standard jython code files). You can easily import an external library using the following code snippet (which I have seared into my brain!):

import sys
import dctm

sys is a standard python library that contains a lot of useful system functions/features. One of them is the aforementioned sys.path. The append method allows you to add extra paths that jython can use to look for libraries. In this case the relative path script/jython/dctm is where I keep my standard dctm.py library. After these lines I can use the dctm object to access any of the methods in dctm.py.

So my standard dctm.py is stored scripts/jython/dctm, my project specific jython file (e.g. myfile.py) is also stored in this folder structure. By navigating to the top-level folder (the one containing the scripts folder) I can run jython like this:

jython myfile.py

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: