diff --git a/README.md b/README.md index c3c9bf3ce9c94d3bb8d2beaf0e9a7b01eae79880..cad3611b4530e2ec60f66ebf8a9f3fa7816c6485 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,21 @@ Download Config ------ - * for all uses: copy config.py.example to config.py and edit it to your needs. - * for production use: copy schildergen.wsgi.example to schildergen.wsgi and edit it. + * *for all uses*: copy config.py.example to config.py and edit it to your needs. + * *for production use*: copy schildergen.wsgi.example to schildergen.wsgi and edit it. + + +Modify the templates +-------------------- + +In most cases, you just need to edit tex/support/header.tex and add your logo +in tex/support . After you changed it, you might want to run + + $ python schilder.py --recreate-cache + +to delete all cached pdf and image thumbnails, then re-run pdflatex on all +saved signs. Accessing the webinterface will recreate the rest of the cached +image thumbnails. Running in test/debug mode diff --git a/data/GenericEvent42-1331353749.schild b/data/GenericEvent42-1331353749.schild index 751fd5fbab81c65b9d2545ff75b3120758af3d48..a415cf201b21a3a2070892d273f22cdd4db29b75 100644 --- a/data/GenericEvent42-1331353749.schild +++ b/data/GenericEvent42-1331353749.schild @@ -1 +1 @@ -{"pdfname": "GenericEvent42-1331353749.schild.pdf", "img": "pictograms-nps-misc-camera.png", "headline": "Generic\r\nEvent42", "text": "Man kann Wiki-Syntax benutzen.\r\n\r\n* Zum Beispiel f\u00fcr\r\n* Bullet Lists\r\n", "markup": "rst", "reusefilename": "on", "textemplate": "image-left_bothtext-right.tex", "filename": "GenericEvent42-1331353749.schild"} \ No newline at end of file +{"pdfname": "GenericEvent42-1331353749.schild.pdf", "img": "pictograms-nps-misc-camera.png", "headline": "Generic\r\nEvent42", "text": "Man kann Wiki-Syntax benutzen.\r\n\r\n* Zum Beispiel f\u00fcr\r\n* Bullet Lists\r\n", "markup": "latex", "reusefilename": "on", "textemplate": "image-left_bothtext-right.tex", "filename": "GenericEvent42-1331353749.schild"} \ No newline at end of file diff --git a/schilder.py b/schilder.py index 9efca74115abdb78a7a9b2100019ea6377595320..1fe937c5347233014fbf285d37b8605be796406a 100755 --- a/schilder.py +++ b/schilder.py @@ -114,12 +114,18 @@ def run_pdflatex(context, outputfilename, overwrite=True): ['pdflatex', '--halt-on-error', tmptexfile], stderr=STDOUT) except CalledProcessError as e: if overwrite: - flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log') + try: + flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log') + except: + print(e.output) raise SyntaxWarning("PDFLaTeX bailed out") finally: os.chdir(cwd) if overwrite: - flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % texlog), 'log') + try: + flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % texlog), 'log') + except: + print(texlog) shutil.copy(tmppdffile, outputfilename) shutil.rmtree(tmpdir) @@ -197,22 +203,34 @@ def create(): formdata['pdfname'] = outpdfname save_data(formdata, outfilename) run_pdflatex(formdata, os.path.join(config.pdfdir, outpdfname)) - flash(Markup(u"""PDF created and data saved. You might create another one. Here's a preview. Click to print.<br/> - <a href="%s"><img src="%s"/></a>""" % + try: + flash(Markup(u"""PDF created and data saved. You might create another one. Here's a preview. Click to print.<br/> + <a href="%s"><img src="%s"/></a>""" % (url_for('schild', filename=outfilename), url_for( 'pdfthumbnail', pdfname=outpdfname, maxgeometry=200)) )) + except: + print("%s created" % outpdfname) except Exception as e: - flash(u"Could not create pdf or save data: %s" % str(e), 'error') + try: + flash(u"Could not create pdf or save data: %s" % str(e), 'error') + except: + print("Could not create pdf or save data: %s" % str(e)) data = {'form': formdata} imagelist = glob.glob(config.imagedir + '/*.png') data['images'] = [os.path.basename(f) for f in imagelist] templatelist = glob.glob(config.textemplatedir + '/*.tex') data['templates'] = [os.path.basename(f) for f in sorted(templatelist)] - return redirect(url_for('edit_one', filename=outfilename)) - flash("No POST data. You've been redirected to the edit page.", 'warning') - return redirect(url_for('edit')) + try: + return redirect(url_for('edit_one', filename=outfilename)) + except: + pass + try: + flash("No POST data. You've been redirected to the edit page.", 'warning') + return redirect(url_for('edit')) + except: + pass @app.route('/schild/<filename>') @@ -313,7 +331,24 @@ def pdfdownload(pdfname): return Response(pdffile.read(), mimetype="application/pdf") +def recreate_cache(): + for filename in (glob.glob(os.path.join(config.pdfdir, '*.pdf*')) + + glob.glob(os.path.join(config.cachedir, '*.pdf*')) + + glob.glob(os.path.join(config.imagedir, '*.png.*'))): + try: + os.unlink(filename) + print("Deleted %s" % filename) + except Exception as e: + print("Could not delete %s: %s" % (filename, str(e))) + for filename in glob.glob(os.path.join(config.datadir, '*.schild')): + data = load_data(filename) + pdfname = os.path.join(config.pdfdir, data['pdfname']) + print("Recreating %s" % pdfname) + run_pdflatex(data, pdfname) if __name__ == '__main__': - app.debug = True - app.run(host=config.listen, port=config.port) + if len(sys.argv) > 1 and sys.argv[1] == '--recreate-cache': + recreate_cache() + else: + app.debug = True + app.run(host=config.listen, port=config.port)