#!@PYTHON@ # -*- mode: python; coding: iso-8859-1 -*- # Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), # département Systèmes Répartis Coopératifs (SRC), Université Pierre # et Marie Curie. # # This file is part of Spot, a model checking library. # # Spot is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Spot is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU General Public License # along with Spot; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. import sys import os import cgi import cgitb; cgitb.enable() import signal print "Content-Type: text/html" print # Redirect stderr to stdout. os.close(sys.stderr.fileno()) os.dup2(sys.stdout.fileno(), sys.stderr.fileno()) sys.path.insert(0, '@pythondir@') # Directory for temporary files (images and other auxiliary files). imgdir = 'spotimg' import spot import buddy def print_footer(): print '
The script was aborted because it has been running for too long. Please try a shorter formula, or different options (not drawing automata usually helps). If you want to benchmark big formulae it is better to install Spot on your own computer.
""" print_footer() sys.stdout.flush() os.kill(0, signal.SIGTERM) def reset_alarm(): signal.alarm(30) spot.unblock_signal(signal.SIGALRM) spot.unblock_signal(signal.SIGTERM) os.setpgrp() signal.signal(signal.SIGALRM, alarm_handler) reset_alarm() # Cleanup stale files from our image directory. os.system('find ' + imgdir + ' -type f -amin +10 -print | xargs rm -f') myself = os.environ['SCRIPT_NAME']; form = cgi.FieldStorage() filled = form.has_key('formula') # FIXME: This assumes Apache. uid = os.environ['UNIQUE_ID']; imgprefix = imgdir + '/' + uid def escaped_print_dot(dict, what): print ''; sys.stdout.flush()
s = spot.ostringstream()
spot.bdd_print_dot(s, dict, what)
print cgi.escape(s.str())
del s
print ''; sys.stdout.flush()
def escaped_print_set(dict, what):
print ''; sys.stdout.flush()
s = spot.ostringstream()
spot.bdd_print_set(s, dict, what)
print cgi.escape(s.str())
del s
print ''; sys.stdout.flush()
def print_stats(automaton):
stats = spot.stats_reachable(automaton)
print "", stats.states, if stats.states <= 1: print " state,", else: print " states,", print stats.transitions, if stats.transitions <= 1: print " transition,", else: print " transitions,", # compute the number of acceptance conditions acc = all = automaton.all_acceptance_conditions() count = 0 while all != buddy.bddfalse: all -= buddy.bdd_satone(all) count += 1 if count > 0: print count, if count <= 1: print "acceptance condition:", else: print "acceptance conditions:", sys.stdout.flush() spot.bdd_print_accset(spot.get_cout(), automaton.get_dict(), acc) else: print "no acceptance condition (all cycles are accepting)" print "
" sys.stdout.flush() def render_dot(basename): os.spawnlp(os.P_WAIT, 'dot', 'dot', '-Tpng', '-Gsize=14,14', '-o', basename + '.png', basename + '.dot') reset_alarm() print '
'
def render_automaton(basename, automata):
outfile = spot.ofstream(basename + '.dot')
spot.dotty_reachable(outfile, automata)
del outfile
render_dot(basename)
def render_bdd(basename, dictionary, bdd):
outfile = spot.ofstream(basename + '.dot')
spot.bdd_print_dot(outfile, dictionary, bdd)
del outfile
render_dot(basename)
print "' sys.stdout.flush() sys.stderr.flush() pel = spot.empty_parse_error_list() f = spot.parse(formula, pel, env, show_parse) if show_parse: print '' print '
' err = spot.format_parse_errors(spot.get_cout(), formula, pel) print '' if not f: print '
Aborting...
' sys.exit(0) if err: print 'Continuing anyway...
' print "Formula is", f, "
'; sys.stdout.flush()
s = spot.ostringstream()
spot.dotty(s, f)
print cgi.escape(s.str())
del s
print ''; sys.stdout.flush()
if show_formula_gif:
outfile = spot.ofstream(imgprefix + '-f.dot')
spot.dotty(outfile, f)
del outfile
render_dot(imgprefix + '-f')
print 'Building automaton...', sys.stdout.flush() if trans_lacim: automaton = spot.ltl_to_tgba_lacim(f, dict) elif trans_fm: automaton = spot.ltl_to_tgba_fm(f, dict) print 'done.
' sys.stdout.flush() print_stats(automaton) if show_automaton_dot: print ''; sys.stdout.flush()
s = spot.ostringstream()
spot.dotty_reachable(s, automaton)
print cgi.escape(s.str())
del s
print ''; sys.stdout.flush()
if show_automaton_gif:
render_automaton(imgprefix + '-a', automaton)
if show_degen_dot or show_degen_gif:
print ''; sys.stdout.flush() s = spot.ostringstream() spot.dotty_reachable(s, degen) print cgi.escape(s.str()) del s print ''; sys.stdout.flush() if show_degen_gif: render_automaton(imgprefix + '-d', degen) else: degen = 0 if show_dictionnay: print '
'
sys.stdout.flush()
automaton.get_dict().dump(spot.get_cout())
print ''
if (type(automaton) == spot.tgba_bdd_concretePtr
and (show_relation_dot or show_relation_set or show_relation_gif)):
print ''
sys.stdout.flush()
spot.lbtt_reachable(spot.get_cout(), automaton)
print ''
if degen:
print '' sys.stdout.flush() spot.lbtt_reachable(spot.get_cout(), degen) print '' sys.stdout.flush() spot.destroy(f) # Make sure degen is cleared before automaton. del degen del automaton print_footer()