Thursday, August 2, 2007
use * for string duplication
valueStr2 "( %s" + ",%s"*(len(dict)-1)+")"
rather than the following c-type implementation
tempL = []
for i in dict.keys():
tempL.append("%s")
valueStr2 = "(" + ",".join(tempL)+")"
Tuesday, July 24, 2007
restart python to get newly imported module
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 "
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
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
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
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
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
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
WAS CE installation
export WASCE_HOME=/opt/wasce
export GERONIMO_HOME=/opt/wasce
export GERONIMO_TMPDIR=/opt/wasce
export GERONIMO_BASE=/opt/wasce
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
DB V9 uninstall on AIX
db2 V9 installation does not show in AIX's lslpp.
root@hvw2 #
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
python 2.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
xen and xen0 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%]
VMware linux guest VM to see shared folder
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
-bash: /opt/ibm/java2-i386-50/bin:/wmj: No such file or directory
-bash: ls: command not found
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
XAMPP, easyElcipse, Ruby
Yum Package
the http://www.freevps.com/download/yum/RHEL4/ contains the necessary files, however, yum official website and redhat does not have rpms.
PyOpenSSL installation
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
running build
running build_py
running build_ext
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
Writing c:\python25\Lib\site-packages\pyOpenSSL-0.6-py2.5.egg-info
>>> import OpenSSL
>>>
python ValueError: universal newline mode 'U'
ValueError: universal newline mode can only be used with modes starting with 'r'
Monday, July 2, 2007
python tip
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.