[Zope] Python Extensions are easier than it seems

Philip Aylesworth phila@regalint.com
Tue, 23 Feb 1999 08:59:54 -0500


Hi,

Just wanted to let you know my experience with python extensions. I had
been avoiding them because I had my hands full with learning Zope and DTML
and SQL Methods. When I asked on the list about doing something that seemed
very difficult Paul replied that a 10 line Python extension would do it.

Well, yesterday I set out to do it. I have been reading about Python but
had not used it yet. I looked at an example which gave me lots of clues and
went at it.

Within half an hour I had it working! 9 lines! What it does is it looks to
see if a file exists (the name is stored in a database) in a given (NFS
mounted) directory (in this case the path is also based on the first four
characters of the filename). It returns an HTML link if the file exists or
just the file name if it doesn't.

Here is the code:

import os
def cadlink(file):
    server = 'http://netapp.regalint.com'
    url = '/web/so' + file[0:4] + '/' + file
    path = '/netapp/BBLM' + url
    if os.path.isfile(path):
        return '<A HREF=' + server + url + '>' + file + '</A>'
    else:
        return file


I just call it as a function in DTML with <!--#var "cadlink(file)"--> and
it works!

Very cool!

Phil.


-------------------------------------------------------------------
Philip Aylesworth                  Information Systems Manager
phila@regalint.com
PGP public key: http://www.regalint.com/PGPkeys/phila.html