From 4efde0d3d3570120bb51e1d9a659a9dc84d1e1e6 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sat, 30 Jan 2010 14:15:03 +0100 Subject: [PATCH] Make it possible to use the cgi script without installing a web server. * wrap/python/cgi-bin/ltl2tgba.in: Starts a web server if the script is not called as a CGI. Arrange to load libraries from the build directory. Create the spotimg/ if needed when run as a web server. * wrap/python/cgi-bin/Makefile.am: Adjust build rule and clean the spotimg directory. * wrap/python/cgi-bin/README, NEWS: Update. --- ChangeLog | 13 ++++++++++ NEWS | 2 ++ wrap/python/cgi-bin/Makefile.am | 7 +++++- wrap/python/cgi-bin/README | 32 ++++++++++++++++++------ wrap/python/cgi-bin/ltl2tgba.in | 43 ++++++++++++++++++++++++++++++--- 5 files changed, 85 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 888c65e5d..e67be07c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-01-30 Alexandre Duret-Lutz + + Make it possible to use the cgi script without installing a web + server. + + * wrap/python/cgi-bin/ltl2tgba.in: Starts a web server if the + script is not called as a CGI. Arrange to load libraries from + the build directory. Create the spotimg/ if needed when run as + a web server. + * wrap/python/cgi-bin/Makefile.am: Adjust build rule and clean + the spotimg directory. + * wrap/python/cgi-bin/README, NEWS: Update. + 2010-01-30 Alexandre Duret-Lutz More * -> & replacements. diff --git a/NEWS b/NEWS index 72f6ba00a..8e97ab153 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,8 @@ New in spot 0.5 (2010-01-31): * ltl2tgba has gained several options and the help text has been reorganized. Please run src/tgbatest/ltl2tgba without arguments for details. Couvreur/FM is now the default translation. + * The ltl2tgba.py CGI script can now run standalone. It also offers + the Tauriainen/TAA translation. * Automata using BDD-encoded transitions relation can now be pruned for useless states symbolically using the delete_unaccepting_scc() function. This is ltl2tgba's -R3b option. diff --git a/wrap/python/cgi-bin/Makefile.am b/wrap/python/cgi-bin/Makefile.am index 4c1a2066c..9866ec836 100644 --- a/wrap/python/cgi-bin/Makefile.am +++ b/wrap/python/cgi-bin/Makefile.am @@ -1,4 +1,4 @@ -## Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), +## Copyright (C) 2003, 2010 Laboratoire d'Informatique de Paris 6 (LIP6), ## département Systèmes Répartis Coopératifs (SRC), Université Pierre ## et Marie Curie. ## @@ -26,7 +26,12 @@ CLEANFILES = $(nodist_noinst_SCRIPTS) ltl2tgba.py: $(srcdir)/ltl2tgba.in Makefile sed -e 's|[@]PYTHON[@]|@PYTHON@|g' \ -e 's|[@]pythondir[@]|@pythondir@|g' \ + -e 's|[@]srcdir[@]|@srcdir@|g' \ + -e 's|[@]top_builddir[@]|@top_builddir@|g' \ -e 's|[@]PACKAGE_VERSION[@]|@PACKAGE_VERSION@|g' \ <$(srcdir)/ltl2tgba.in >ltl2tgba.tmp chmod +x ltl2tgba.tmp mv -f ltl2tgba.tmp $@ + +clean-local: + rm -rf spotimg diff --git a/wrap/python/cgi-bin/README b/wrap/python/cgi-bin/README index 4a5772b8d..838924632 100644 --- a/wrap/python/cgi-bin/README +++ b/wrap/python/cgi-bin/README @@ -1,21 +1,41 @@ ltl2tgba.py is a CGI script that translate user-supplied LTL formulae to Transition-based Generalized Büchi Automata. -You have to install the script yourself if you want to test it. +There are two ways to use the script: using a web server such as +Apache, or standalone. + +In both cases you should ensure that the command `dot', from the +GraphViz package, is in the PATH. + + + +Standalone usage +================ + +Simply run the script from this directory. This will create a +directory called spotimg/ in the current directory (this will hold the +generated pictures) and start an HTTP server on port 8000. Point your +browser to http://localhost:8000/ltl2tgba.py and you should be OK. + +After you have killed the server process (e.g. with Control-C), +you may want to erase the spotimg/ directory. + +Installing on a real web server +=============================== 1) Install Spot first (run `make install' from the top-level). The CGI scripts uses the Python bindings and assume they have been installed. Near the top of the script, you should see a call to sys.path.insert(), with the expected - location og the Python bindings for spot. This path was + location of the Python bindings for spot. This path was configured from ./configure's arguments and you should not have to fiddle with it. I'm mentionning it just in case. 2) Copy ltl2tgba.py to some place were CGI execution is allowed. Depending on your HTTP server's configuration, you may have to rename the script as ltl2tgba.cgi or something else, so - that the server accept to run it. + that the server accepts to run it. Apache users in trouble should look at the following options before digging the Apache manual deeper. These can go @@ -37,9 +57,5 @@ You have to install the script yourself if you want to test it. will run the script when the HTTP server processes the request. - ltl2tgba purges old files (>10min) from this directory + ltl2tgba purges old files (>15min) from this directory each time it runs. - -4) `dot', from the GraphViz package, should be in the PATH. - -5) Apache should have its unique_id module loaded. diff --git a/wrap/python/cgi-bin/ltl2tgba.in b/wrap/python/cgi-bin/ltl2tgba.in index 4575e8893..40f9bfc0c 100755 --- a/wrap/python/cgi-bin/ltl2tgba.in +++ b/wrap/python/cgi-bin/ltl2tgba.in @@ -23,8 +23,31 @@ # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. -import sys import os + +# Directory for temporary files (images and other auxiliary files). +imgdir = 'spotimg' + +from CGIHTTPServer import CGIHTTPRequestHandler +class MyHandler(CGIHTTPRequestHandler): + def is_cgi(self): + if self.path == '/ltl2tgba.py': + self.cgi_info = '', 'ltl2tgba.py' + return True + return False + +if not os.environ.has_key('SCRIPT_NAME'): + # If this is not run as a cgi script, let's start an HTTP server. + from BaseHTTPServer import HTTPServer + server_address=('',8000) + if not os.access(imgdir, os.F_OK): + os.mkdir(imgdir, 0755) + print "Directory spotimg/ created." + httpd = HTTPServer(server_address, MyHandler) + print "Point your browser to http://localhost:8000/ltl2tgba.py" + httpd.serve_forever() + +import sys import cgi import cgitb; cgitb.enable() import signal @@ -37,9 +60,23 @@ print os.close(sys.stderr.fileno()) os.dup2(sys.stdout.fileno(), sys.stderr.fileno()) +# Assume Spot is installed sys.path.insert(0, '@pythondir@') -# Directory for temporary files (images and other auxiliary files). -imgdir = 'spotimg' + +if (os.environ.has_key('SERVER_SOFTWARE') and + os.environ['SERVER_SOFTWARE'].startswith(MyHandler.server_version)): + # We might be running from the build tree (but it's not sure). + # Add the build and source directories first in the search path. + # If we are not in the right place, python will find the installed + # libraries later. + sys.path.insert(0, '@srcdir@/..') + sys.path.insert(0, '..') + # Darwin needs some help in figuring out where non-installed libtool + # libraries are (on this platform libtool encodes the expected final + # path of dependent libraries in each library). + m = '../.libs:@top_builddir@/src/.libs:@top_builddir@/buddy/src/.libs' + os.environ['DYLD_LIBRARY_PATH'] = m + import ltihooks # Extra HTML headers. extra_header = ''