cgimodel: CGI Programming Made Easy with Python

Always look on the bright side of life and at a method for debugging CGI programs on the command line.
Adding Existing Modules to CGI

Assume you already have this module:

#!/usr/bin/env python
#  testmethod.py
def  Method1(name1,name2,name3):
        print name1,name2,name3
if __name__ == '__main__':
     Method1('one','two','three')

Edit the cgidisp.py module, inserting the following method under the class Dispatcher:

def cmd_TestMeth(self,parDict):
   import testmethod
   name1 = parDict['name1']
   name2 = parDict['name2']
   name3 = parDict['name3']
   testmethod.Method1(name1,name2,name3)
Now it is ready! You can call this on the command line by typing on one line:
cgimodel.py -fun TestMeth -name1 one -name2 two -name3 three
or by URL (all on one line):
cgimodel.py?-fun=TestMeth&name1=one&name2=two&name3=three
or by FORMS:
<FORM METHOD="post" ACTION="/cgi-bin/cgimodel.py">
<INPUT TYPE=hidden name=fun value=TestMeth>
<INPUT TYPE=hidden name=name1 value=one>
<INPUT TYPE=hidden name=name2 value=two>
<INPUT TYPE=hidden name=name3 value=three>
<INPUT TYPE=SUBMIT VALUE="Run">
</FORM>
It would be much better if you could separate HTML text from CGI modules, so that CGI looks thinner and more readable. You can use the template modules (see Resources) to do this. The template module keeps the text away from the CGI and has a page-paragraph structure. Each CGI call can be associated with a page, and each paragraph can be used to set up the view of your HTML page.

cgimodel can host any number of applications. The redundancy of writing a CGI front end is no longer necessary. Since many applications can be run by a single cgimodel, logging information particular to each application can be done for later analysis to improve server performance, stability of each application, better service, etc. Currently, this can be done with the log information generated by the web server.

With cgimodel.py, cgidisp.py and possibly the template.py modules, you should find writing and testing CGI programs easier.

Resources

Chenna Ramu (ramu.chenna@embl-heidelberg.de) holds a postgraduate degree in mathematics. He currently works for European Molecular Biological Laboratory in Heidelberg, Germany, in the area of biocomputing. Interests are theoretical study about DNA/protein sequences, database development, parsing, compilers, system administration and web technology. He came across Python recently (thanks to Gert Vriend) and found it quite nice for programming.

Christine Gemuend has a degree in computer science. She is interested in parallel computers and database systems, and is working in the area of informatics.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Citation!

Anonymous's picture
Phospho.ELM: a database of phosphorylation sites—update 2008
Francesca Diella, Cathryn M. Gould, Claudia Chica, Allegra Via, and  Toby J. Gibson
Nucleic Acids Res. . 2008 January; 36(Database issue): D240–D244. Published online 2008 January. doi: 10.1093/nar/gkm772.
PMCID: PMC2238828

 Phospho.ELM: A database of experimentally verified phosphorylation sites in eukaryotic proteins
Francesca Diella, Scott Cameron, Christine Gemünd, Rune Linding, Allegra Via, Bernhard Kuster, Thomas Sicheritz-Pontén, Nikolaj Blom, and  Toby J Gibson
BMC Bioinformatics. . 2004; 5: 79. Published online 2004 June 22. doi: 10.1186/1471-2105-5-79.
PMCID: PMC449700


 SIRW: a web server for the Simple Indexing and Retrieval System that combines sequence motif searches with keyword searches
Chenna Ramu
Nucleic Acids Res. . 2003 July 1; 31(13): 3771–3774. 
PMCID: PMC168953

 ELM server: a new resource for investigating short functional sites in modular eukaryotic proteins
Pål Puntervoll, Rune Linding, et.al.,
Nucleic Acids Res. . 2003 July 1; 31(13): 3625–3630. 
PMCID: PMC168952


Gene2EST: a BLAST2 server for searching expressed sequence tag (EST) databases with eukaryotic gene-sized queries
Christine Gemünd, Chenna Ramu, Brigitte Altenberg-Greulich, and  Toby
 J. Gibson
Nucleic Acids Res. . 2001 March 15; 29(6): 1272–1277. 
PMCID: PMC29756

The points is it solves the

Anonymous's picture

The points is it solves the problem of debugging cgi's,
since you can do it on the command line. But isn't
that unix/linux specific ? Will it work for windows?

jens

Re: cgimodel: CGI Programming Made Easy with Python

Anonymous's picture

The author has done a very good job of designing a fantastic framework for cgi's. I am now writing cgi's with python!

peter

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState