Tuesday, July 24, 2007

restart python to get newly imported module

newly imported python module by using easy_install can not be imported instantly. you have to restart the python session to import the new module properly
C:\Documents and Settings\mwang>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
>>> import MySQLdb
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named MySQLdb
>>> quit
Use quit() or Ctrl-Z plus Return to exit
>>> quit()

C:\Documents and Settings\mwang>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

Friday, July 13, 2007

a quick/good example of using the python/twill

Today I have a issue on playing http request by using one of load stress testing tool/appliance, and I suspected that the cookie setting in that appliance is not working properly: 2 cookies were set during the requst, and I expected more cookie to be set. I may ask around the developer for cookie information, but it will take time to find the right resource. Fortunately, the following 9 lines code saves my time:

from twill import get_browser
from twill.commands import *
import sys


b = get_browser()
b.go("http://www.example.com/foo")
show()
print "======="
show_cookies()


the results surprisingly tells me that 8 cookies was set after the request. the next thing is to submit an service request to the vendor, provides my expectation with my findings, then expected solution soon.

Wednesday, July 11, 2007

iter() sample

the iter() is more like generator, it will return an item every time you call it. here is the different output by using list and iter()

it = range(10)
print it
b = zip(it, it)
print b

it = iter(range(10))
b = zip(it, it)
print b

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]

Monday, July 9, 2007

Twill Tips -Form

Although we may use Form#, for instance "2" in the fv to update item value, it will be unpredictable if the form order or the number the form is different based on dynamic content, it will be hard to select the right form# for fv function. the good news is that we can use form name rather than form # in fv to specify which form we want to update.

Form name=editPage (#2)
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 cancelURL hidden cancelURL /home/home.jsp
2 retURL hidden retURL /home/home.jsp

fv("editPage", "p19", "12")

checkbox value in Twill

in the twill, the value of the de-selected box of the item is [], while the value of selected box is ['1']

33 p23 checkbox p23 [] of ['1']
34 p22 checkbox p22 ['1'] of ['1']

the proper way to deselect the default checkbox, for instacne p22, is to
fv("3", "p22", "false").

if we use fv("3", "p22", "") to perform unselected checkbox, you may get the following error message:

File "c:\python25\lib\site-packages\twill-0.9b1-py2.5.egg\twill\utils.py", line 164, in make_boolean
raise Exception("unable to convert '%s' into true/false..." % (value,))
Exception: unable to convert '' into true/false...


You will know that you should use true or false to do select or deselect on the checkbox in twill.

Friday, July 6, 2007

Twill Tips - Links

Assumed that you have some links on html page, you may want to find and go to the url ended with "/items" by using twill in the python command line environment:

a=showlinks()
for i in a:
if i.url.find("/items") > 0 :
URL_items=i.absolute_url

print "=====", URL_items
b.go(URL_items)

a contains Link Object, which has url and absolute_url attribute. we use url attribute to search for "/items", then access the page by using absolute_url attribute

Tuesday, July 3, 2007

nice Python

after polishing my skill set related to c developement, I am comfortable about setup python environment, especially build from source code, in linux enviroment or in windows environment.
opensource gave us an opportunity to have a try, but it is not free. time is value. we can keep trying different opensource, but we may end up with having nothing. I think have 2 solutions to deal with opensource:
1. evaluate the necessary open source.
2. have a build script to speed up open source environment settting.
I likes python easy_install idea, which has similar idea as eclipse update.

WAS CE installation

http://publib.boulder.ibm.com/wasce/V1.1.0/en/Tasks/Install/Installing.html is a good reference was ce 1.1.0 installation. here is highlight steps
1. extract tar file
2. rpm -Uvh ibm-java2-i386-sdk-5.0-3.0.i386.rpm
3. add the java's installation path to PATH
/opt/ibm/java2-i386-50/bin
4.wasce_setup-1.1.0.1-unix.bin -console
5. update the following environment variable in /root/.bashrc:
export BASEDIR=/opt/wasce
export WASCE_HOME=/opt/wasce
export GERONIMO_HOME=/opt/wasce
export GERONIMO_TMPDIR=/opt/wasce
export GERONIMO_BASE=/opt/wasce
6. . /root/.bashrc to refresh the variables
7. [root@localhost bin]# ./startup.sh
Using GERONIMO_BASE: /opt/wasce
Using GERONIMO_HOME: /opt/wasce
Using GERONIMO_TMPDIR: /opt/wasce
Using JRE_HOME: /opt/ibm/java2-i386-50/jre
Using GERONIMO_OUT: /opt/wasce/var/log/geronimo.out
Geronimo started in background. PID: 11230
8. access to adminsonole: http://9.30.182.181:8080/ system/manager is default password

DB V9 uninstall on AIX

db2 V9 installation does not show in AIX's lslpp.

root@hvw2 # /V9.1/instance/dasdrop
SQL4410W The DB2 Administration Server is not active.
DBI1070I Program dasdrop completed successfully.


use the following way to remove it
db2stop in any db2instance
remove any db2 instance, otherwise de-installation will fail
/V9.1/install/db2_deinstall -a -l /tmp/db2V9_uninstall.log

python 2.5

Here is the key steps for Python 2.5 installation on RHEL 4.0 from the http://www.python.org/download/releases/2.5/
the installation location is /usr/local/bin/Python2.5

All others should download either python-2.5.tgz or python-2.5.tar.bz2, the source archive. The tar.bz2 is considerably smaller, so get that one if your system has the appropriate tools to deal with it. Unpack it with tar -zxvf Python-2.5.tgz (or bzcat Python-2.5.tar.bz2 | tar -xf -). Change to the Python-2.5 directory and run the "./configure", "make", "make install" commands to compile and install Python.

Since this is a new version of Python, you may want to use the "make altinstall" command instead of "make install" - this will install a "python2.5" binary without touching the existing "python" binariy

the cpp pacage is on RHEL CD2, glibc and gcc package is on RHEL CD3

RHEL 5.0 Beta XEN installation

using virt-install to install RHEL4.0 xen guest, the following error message was shown:

Starting install...

ERROR: Invalid NFS location given: [Errno 2] No such file or directory: '/var/lib/xen/xennfs.XfOkIq/images/xen/vmlinuz'

because there is no xen directories under images, since RHEL4.4 is not XEN ready...

according to http://people.redhat.com/riel/RHEL4-Xen-HOWTO , currently we can not use virt-install to install RHEL4.4 , the image should be installed in someway, the apply the virtualization kernel RPM which is available in http://people.redhat.com/~jbaron/rhel4/RPMS.kernel/ .

not sure whether http://people.redhat.com/~jbaron/rhel4/RPMS.kernel/ shows the RPM for RHEL 4.4 guest VM, or RHEL4.4 XEN host.

Convert Cert between PEM and keytool

I have been using CERT for a while. I mainly knew IBM keyman tool to do the cert related tasks. recently I exposed to opensource environment. I just realized the powerful openssl and the diference between cert format:
apache is using PEM based cert, while others may use java keytool ( for instance WebSphere Application Server Community edition), I was able to porting cert from keytool into apache by following a good web reference doc : http://mark.foster.cc/kb/openssl-keytool.html
1.1 keytool export cert
1.2 use exportPriv to export private key
1.3 use openssl verify command to verify my exported cert
1.4 use openssl s_server -cert server.crt -key private.key -www to test whether the cert and key works. the command will open port 4433 for https accessing

xen and xen0 rpm

if the kernel-xen version is higher, in order to acommadate lower version of xenU, we can install xen0 alternative.
[root@localhost boot]# rpm -Uvh /wmj/kernel-xen-2.6.19-1.2288.2.4.fc5.i686.rpm
Preparing... ########################################### [100%]
package kernel-xen-2.6.19-1.2911.fc6 (which is newer than kernel-xen-2.6 .19-1.2288.2.4.fc5) is already installed
package kernel-xen-2.6.19-1.2911.6.5.fc6 (which is newer than kernel-xen -2.6.19-1.2288.2.4.fc5) is already installed
[root@localhost boot]# rpm -Uvh /wmj/kernel-xen0-2.6.19-1.2288.2.4.fc5.i686.rpm
Preparing... ########################################### [100%]
1:kernel-xen0 ########################################### [100%]
vmlinuz-2.6.19-1.2288.2.4.fc5xen0

VMware linux guest VM to see shared folder

It is straightforward for VMware windows guest VM to use shared folder from host, however, it is not the case for the VMware linux guest. Although in VMware linux guest, /mnt/hgfs is default mount point for any shared folder, it was not created by default; the vmware-tools also not installed by default. without these 2 elements, we are not able to use shared folder feature in VMware linux guest, the VMware workstation user guide did not document it. here is my summary of action based on VMTN's discussion threads:
1. install VMware-tools
by attach linux.iso and click ' install vmware tools' in the VMWare menu/ VM tab. you will get VMware-tools icon on your Linux guest VM GUI. you will be able to install RPM.
2. mkdir /mount/hgfs
the default mount point for shared folder.
3. if you run /etc/init.d/vmware-tools restart, you may get warning on ' your VMware tools was not configured properly'
1. run /usr/bin/vmware-tools-configure.pl, please run it in local machine, rather remote session. the configure script will detect it for you.
2. after the configuration, you may use /usr/bin/vmware-toolbox to invoke VMware Toolbox for audio, shrink etc feature.
3. at this moment, the NIC eth0 is disconnected. in order to use vmxnet driver, run the following commands:
/etc/init.d/network stop
rmmod pcnet32
rmmod vmxnet
depmod -a
modprobe vmxnet
/etc/init.d/network start
4. the /mnt/hfgs got shared folder.

a unix shell test

if I have the following entries in the /root/.bashrc:
export PATH=/opt/ibm/java2-i386-50/bin;$PATH:/wmj
then run . /root/.bashrc
-bash: /opt/ibm/java2-i386-50/bin:/wmj: No such file or directory
why I will got the following error
[root@localhost bin]# ls -al /opt/IBM/WPS/profiles/ccmdb/bin
-bash: ls: command not found
Answer: the typerr ; before the $PATH should be changed to : under unix to delimiter each individual path. the typerr cause the system environment $PATH to be /opt/ibm/java2-i386-50/bin, since ls is not under /opt/ibm/java2-i386-50/bin, the error is raised.

ITSM/ISM 1.1.1 CTGWE6038E

When you attempt to create a RFC, you may have the following issue

CTGWE6038E
The error "com.ibm.tivoli.prism.rm.util.ex.ChangeException" with message "com.ibm.tivoli.prism.rm.util.ex.ChangeException: com.ibm.tivoli.prism.rm.util.ex.RMCMDBEJBException: CTGCM1002E An attempt was made to send a request to the CDB EAR application, but the attempt failed." was received unexpectedly.

the root cause is that CCMDB does not have SSL cert info of CMDB, copying the jssecacerts.cert to /cmdb_data/etc, and re-create RFC.

XAMPP, easyElcipse, Ruby

recently I found the convenience of XAMPP. especially in linux platform
1. un-tar XAMPP tarball in /opt/lampp
2. un-tar esyEclipse 1.2.1.1 for LAMPP
3. install ruby rail on XAMPP by using axlegrease 0.6.2
after the installation, you should be able to sess http://hostname/emaildir the ruby sample application.

Yum Package

in order to install YUM
rpm -Uvh yum-2.6.1-1.noarch.rpm python-elementtree-1.2.6-7.el4.rf.i386.rpm python-sqlite-1.0.1-1.2.el4.rf.i386.rpm python-urlgrabber-2.9.7-1.2.el4.rf.noarch.rpm sqlite-2.8.16-1.2.el4.rf.i386.rpm
the http://www.freevps.com/download/yum/RHEL4/ contains the necessary files, however, yum official website and redhat does not have rpms.

PyOpenSSL installation

although PyOpenSSL install file mentioned the windows modules installation, it assumed that Visual Studio 2003 has been installed. in reality, we do not have VS 2003 installed, sometime we also does not Cygwin installed, does it mean that we can not install pyOpenSSL? the answer is obvious No. It will take a while to find out the why, since there is not such answer on the web.
first step: get packages ( my python version is 2.5)
download pyOpenSSL-0.6
install windows OpenSSL, default folder is c:\OpenSSL
second step: build ( I found the following content is very useful for the issue (http://webcleaner.sourceforge.net/install.html)
Change to the directory where you installed the Win32OpenSSL software into (for example c:\OpenSSL). Now fix the library names for the mingw compiler: c:\OpenSSL> cd lib\MinGW && move ssleay32.a libssleay32.a && move ssleay32.def libssleay32.def
  • Extract pyOpenSSL-0.6.tar.gz and change into the generated directory (for example c:\pyOpenSSL-0.6). Open a text editor for setup.py and replace 'libeay32' with 'eay32'.

  • Then run: c:\pyOpenSSL-0.6> python setup.py build_ext -c mingw32 -I c:\OpenSSL\include -L c:\OpenSSL\lib\MinGW

  • last step: install ( if you do not skil-build, since -c mingw32 will not pass from install to build, the installation will failure regardless whether build success or not)
    C:\projects\Python\pyOpenSSL-0.6\pyOpenSSL-0.6>python setup.py build -c mingw32
    running build
    running build_py
    running build_ext
    C:\projects\Python\pyOpenSSL-0.6\pyOpenSSL-0.6>python setup.py install --skip-build
    running install
    running install_lib
    creating c:\python25\Lib\site-packages\OpenSSL
    copying build\lib.win32-2.5\OpenSSL\crypto.pyd -> c:\python25\Lib\site-packages\
    OpenSSL
    copying build\lib.win32-2.5\OpenSSL\rand.pyd -> c:\python25\Lib\site-packages\Op
    enSSL
    copying build\lib.win32-2.5\OpenSSL\SSL.pyd -> c:\python25\Lib\site-packages\Ope
    nSSL
    copying build\lib.win32-2.5\OpenSSL\tsafe.py -> c:\python25\Lib\site-packages\Op
    enSSL
    copying build\lib.win32-2.5\OpenSSL\version.py -> c:\python25\Lib\site-packages\
    OpenSSL
    copying build\lib.win32-2.5\OpenSSL\__init__.py -> c:\python25\Lib\site-packages
    \OpenSSL
    byte-compiling c:\python25\Lib\site-packages\OpenSSL\tsafe.py to tsafe.pyc
    byte-compiling c:\python25\Lib\site-packages\OpenSSL\version.py to version.pyc
    byte-compiling c:\python25\Lib\site-packages\OpenSSL\__init__.py to __init__.pyc
    running install_egg_info
    Writing c:\python25\Lib\site-packages\pyOpenSSL-0.6-py2.5.egg-info
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import OpenSSL
    >>>

    python ValueError: universal newline mode 'U'

    print open(featurefile, 'wU').writelines()
    ValueError: universal newline mode can only be used with modes starting with 'r'
    take out U will solve the issue.

    Monday, July 2, 2007

    python tip

    Assumed that a sample.txt file contains multiple headline, which are same as the line0. In order to keep line0 as the only head line, and delete the rest line in the middle of file, we have the following 2 implementation:

    Trivial:

    ls = open("sample.txt").readlines()
    k = ls[0]
    for l in ls[1:] :
    if l.find("File") < 0:
    k += l
    then k contains what I want

    Python way :

    from operator import add
    filter_line0 = lambda line0, lines: reduce ( add, filter ( lambda line : line.find(line0) < 0, lines ))
    k = ls[0]+filter_line0(ls[0], ls[1:])

    The trivial way is easy to understand, but hard to reuse. in order to reuse these code, we have to copy block of code or define these code as a function, However, the python way express intuitive way as one line function definition, then you can use it anywhere.