Custom URLParser for Webware

Yes it works !!
While looking for a way to have some better URL in Webware, than the defaut http://host/Servlet?arg0=..&arg1=, Ian tell me to look at WebKit.URLParser. After a little time looking at the source i managed to do this without too much pain. As i can’t find example on the web, I put this here, if Ian is ok, i will perhaps post this on the wiki.

# put this in your context __init__.py file

class CustomParser(URLParser.URLParser):
"""
Class to do the dispatch of Request it should return a servlet instance
if we return nothing the default Webware behaviour is used
"""

def parse(self,trans,requestPath):
values=string.split(requestPath,'/')

if values[-2] == 'Article':
restPart = '/'
name = 'blog/Article.py'

req = trans.request()
req.setField('id',values[-1])

req._extraURLPath = restPart
req._serverSidePath = name
return URLParser.ServletFactoryManager.servletForFile(trans, name)

# we use the default url handling
return None

urlParser=CustomParser()

So now url like http://alias.larsen-b.com/Article/1 will map to the servlet Article.py and argument id=1 (http://alias.larsen-b.com/Article?id=1).
Of course this is a really simple example, but you can do things really more funny.

DNS and Localisation w/ Python

This post load testing BIND using dnspython and queryperf is a nice post about the use of dnspython module. There is a bunch of dns module right now adns and other.. but this one looks kool since it can read zone file directly .. the best thing would be to do the reverse .. building db file w hand is painfull you know .. what do you use to do this ?

Another pretty kool stuff is ip2cc, which do some dns query to find in which country the ip come from. Not really usefull but really funny :)

Building mpeg/avi/divx with a webcam

This is a small tips to build a avi/divx/mpeg/what you want, with webcam as input in realtime. Simply use mencoder (the encoder build by the mplayer team)

mencoder tv:// -tv driver=v4l:width=160:height=120  -ovc divx4 -o test.avi

Take care, that you should respect the width/height of the current webcam settings.

Howto install Alsa on Debian (kernel 2.4)

Installing Alsa (as a lot of linux kernel module) on Debian (w/ debian package) can be a real pain. But this one is really simple:
- apt-get install alsa-base
- apt-get install alsa-source

Take care that alsa-base ask you which sound card you have. This is needed for building the init-script.

Next:

cd /usr/src/
tar xvfj  alsa-driver.tar.bz2
cd modules/alsa-driver
./configure
make
make install
/etc/init.d/alsa start

Take care that by default all mixer are off !!

– Enjoy using gnomemeeting

Aspect programming

This isn’t really new, but i need to look at closer the aspect programming. Logilab aspects module seems to provide a great way to solve this kind of trouble.

This kind of programming need a total ‘twist’ of mind to do a total switch. Despite this seems to be used in many Java project, i haven’t see a really app that use this in Python. Do i miss something ?

SQLObject and ZPT

After looking at several way to build custom webapps in python, i tested several things :

  • Zope alone
  • Zope + CMF
  • Plone
  • Webware + Cheetah or PSP
  • Webware + Modeling + ZPT ..

And my conclusions right now is: SQLObject is really a kool SQL Api since you can use it very easily. For the template i really think that ZPT is the best one. Despite XML parsing is really slow, and ZPT performance isn’t really good, you can edit the template without too much pain.

Another great thing, is that i can use this tools in Webware (of course) but in a simple python (mod_python for example) CGI. And SQLObject really feat nicely w/ webware, because it’s thread safe. (I discover severals troubles in Modeling w/ thread)

The next step is to find a good way to build ‘slots’, to have a cross site layout. ZPTPage doesn’t support all METAL tags (macros..) so this isn’t done by default .. and calling a lot of ‘structure’ include is a bad way because this will call the ‘slot’ rendering too much times.

The main key is : Keep it simple.

ISpeel support for konqueror

Since month I used Mozilla-firebird instead of Konqueror because, Konqueror have some trouble with some website ( like the mldonkey web-interface ) .. Tonight after a little fight with XFree from the experimental, i decided to go deeply in my debian mess, and switched to lastest KDE cvs build ( deb http://www.cs.uni-magdeburg.de/~aschultz/debian/ unstable/ ), i discover two three good things:

  • Konqui now run fast and quite well (even some bad CSS)
  • KDE now have a centralized password manager (really usefull..)
  • and Konqui support ISpeel hightlight

Enjoy the screen-shot ( in French )

http://jkx.larsen-b.com/photos/blog/konqui.jpg