Commit 155ba42c authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Cache dot sources in the CGI script.

* wrap/python/ajax/spot.in (render_dot, render_dot_maybe)
(render_automaton, render_formula): Cache the dot source, so that
we do not have to regenerate two pictures from the same contents.
* wrap/python/spot.i: Typo in the ostringstream declaration.
parent 0d2ac81a
2011-06-08 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Cache dot sources in the CGI script.
* wrap/python/ajax/spot.in (render_dot, render_dot_maybe)
(render_automaton, render_formula): Cache the dot source, so that
we do not have to regenerate two pictures from the same contents.
* wrap/python/spot.i: Typo in the ostringstream declaration.
2011-06-08 Alexandre Duret-Lutz <adl@lrde.epita.fr> 2011-06-08 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Output a "Cache-Control:" header in the CGI script. Output a "Cache-Control:" header in the CGI script.
......
...@@ -152,8 +152,12 @@ def render_dot(basename): ...@@ -152,8 +152,12 @@ def render_dot(basename):
ext = 'svg' ext = 'svg'
else: else:
ext = 'png' ext = 'png'
outname = basename + '.' + ext
# Do not call "dot" to generate a file that already exists.
if not os.access(outname, os.F_OK):
os.spawnlp(os.P_WAIT, dot, dot, dot_bgcolor, '-T' + ext, os.spawnlp(os.P_WAIT, dot, dot, dot_bgcolor, '-T' + ext,
'-Gsize=8.2,8.2', '-o', basename + '.' + ext, basename + '.txt') '-Gsize=8.2,8.2', '-o', outname, basename + '.txt')
reset_alarm() reset_alarm()
b = cgi.escape(basename) b = cgi.escape(basename)
if svg_output: if svg_output:
...@@ -164,20 +168,37 @@ def render_dot(basename): ...@@ -164,20 +168,37 @@ def render_dot(basename):
+ '.txt">dot source</a>)') + '.txt">dot source</a>)')
print '</div>' print '</div>'
def render_automaton(basename, automata, dont_run_dot, issba, deco = False): def render_dot_maybe(dotsrc, dont_run_dot):
outfile = spot.ofstream(basename + '.txt') # The dot output is named after the SHA1 of the dot source.
if not deco: # This way we can cache two different request that generate
spot.dotty_reachable(outfile, automata, issba) # the same automaton (e.g. when changing a simplification
else: # option that has no influence).
spot.dotty_reachable(outfile, automata, issba, deco) autprefix = imgdir + '/' + hashlib.sha1(dotsrc).hexdigest()
del outfile dotname = autprefix + '.txt'
if not os.access(dotname, os.F_OK):
dotout = open(dotname, "w", 0)
dotout.write(dotsrc)
dotout.close()
if dont_run_dot: if dont_run_dot:
print ('<p>' + dont_run_dot + ''' to be rendered on-line. However print ('<p>' + dont_run_dot + ''' to be rendered on-line. However
you may download the <a href="''' + cgi.escape(basename) you may download the <a href="''' + cgi.escape(autprefix)
+ '.txt">source in dot format</a> and render it yourself.') + '.txt">source in dot format</a> and render it yourself.')
else: else:
render_dot(basename) render_dot(autprefix)
def render_automaton(automaton, dont_run_dot, issba, deco = False):
dotsrc = spot.ostringstream()
if not deco:
spot.dotty_reachable(dotsrc, automaton, issba)
else:
spot.dotty_reachable(dotsrc, automaton, issba, deco)
render_dot_maybe(dotsrc.str(), dont_run_dot)
def render_formula(f):
dotsrc = spot.ostringstream()
spot.dotty(dotsrc, f)
render_dot_maybe(dotsrc.str(), False)
def print_stats(automaton): def print_stats(automaton):
stats = spot.stats_reachable(automaton) stats = spot.stats_reachable(automaton)
...@@ -265,10 +286,7 @@ if output_type == 'f': ...@@ -265,10 +286,7 @@ if output_type == 'f':
print ('<div class="formula spin-format">' print ('<div class="formula spin-format">'
+ spot.to_spin_string(f) + '</div>') + spot.to_spin_string(f) + '</div>')
elif formula_format == 'g': elif formula_format == 'g':
outfile = spot.ofstream(imgprefix + '-f.txt') render_formula(f)
spot.dotty(outfile, f)
del outfile
render_dot(imgprefix + '-f')
finish() finish()
# Formula translation. # Formula translation.
...@@ -313,7 +331,7 @@ if output_type == 'm': ...@@ -313,7 +331,7 @@ if output_type == 'm':
print '<div class="automata-stats">' print '<div class="automata-stats">'
dont_run_dot = print_stats(automaton) dont_run_dot = print_stats(automaton)
print '</div>' print '</div>'
render_automaton(imgprefix + '-a', automaton, dont_run_dot, issba) render_automaton(automaton, dont_run_dot, issba)
automaton = 0 automaton = 0
finish() finish()
...@@ -372,7 +390,7 @@ if output_type == 'a': ...@@ -372,7 +390,7 @@ if output_type == 'a':
del s del s
else: # 't' or 's' else: # 't' or 's'
dont_run_dot = print_stats(degen) dont_run_dot = print_stats(degen)
render_automaton(imgprefix + '-a', degen, dont_run_dot, issba) render_automaton(degen, dont_run_dot, issba)
degen = 0 degen = 0
automaton = 0 automaton = 0
finish() finish()
...@@ -431,8 +449,7 @@ if output_type == 'r': ...@@ -431,8 +449,7 @@ if output_type == 'r':
if draw_acc_run: if draw_acc_run:
deco = spot.tgba_run_dotty_decorator(ec_run) deco = spot.tgba_run_dotty_decorator(ec_run)
dont_run_dot = print_stats(ec_a) dont_run_dot = print_stats(ec_a)
render_automaton(imgprefix + '-e', ec_a, dont_run_dot, render_automaton(ec_a, dont_run_dot, issba, deco)
issba, deco)
del deco del deco
del ec_run del ec_run
del ec_res del ec_res
......
// Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Dveloppement // Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Dveloppement
// de l'Epita (LRDE). // de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique // Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique
...@@ -216,7 +217,7 @@ using namespace spot; ...@@ -216,7 +217,7 @@ using namespace spot;
} }
%nodefault std::ostream; %nodefaultctor std::ostream;
namespace std { namespace std {
class ostream {}; class ostream {};
class ofstream : public ostream class ofstream : public ostream
...@@ -230,7 +231,7 @@ namespace std { ...@@ -230,7 +231,7 @@ namespace std {
public: public:
ostringstream(); ostringstream();
std::string str() const; std::string str() const;
~ofstream(); ~ostringstream();
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment