def ene_plot_figview(sername, simname): """A plot of a .ene file, in PNG format.""" sim = Simulation(sername, simname) ene_fn = sim.ene_fn() eneplot_fn = os.path.join(CACHEDIR, "graphics", sername, simname, f"{simname}.ene.png") if (flask.request.values.get("nocache") or need_to_regenerate(eneplot_fn, [ene_fn])): logging.info("Generating a new image") os.makedirs(os.path.dirname(eneplot_fn), exist_ok=True) fig = create_ene_figure(ene_fn) FigureCanvas(fig).print_png(eneplot_fn) else: logging.info("Serving a cached image") with open(eneplot_fn, "rb") as eneplot_f: return Response(eneplot_f.read(), mimetype='image/png')
def serve_ene_raw(sername, simname): """Serve a raw .ene file.""" sim = Simulation(sername, simname) ene_fn = sim.ene_fn() with open(ene_fn) as ene_f: return Response(ene_f.read(), mimetype="text/plain")