Verified Commit 22b9a6c5 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Run 2to3

parent f03c6dc2
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*- encoding: utf8 -*- # -*- encoding: utf8 -*-
from flask import Flask, flash, session, redirect, url_for, escape, request, Response, Markup from flask import Flask, flash, session, redirect, url_for, escape, request, Response, Markup
...@@ -25,7 +25,7 @@ app = Flask(__name__) ...@@ -25,7 +25,7 @@ app = Flask(__name__)
app.config.update( app.config.update(
UPLOAD_FOLDER = config.uploaddir, UPLOAD_FOLDER = config.uploaddir,
PROPAGATE_EXCEPTIONS = True, PROPAGATE_EXCEPTIONS = True,
MAX_CONTENT_LENGTH = 8388608L MAX_CONTENT_LENGTH = 8388608
) )
app.secret_key = config.app_secret app.secret_key = config.app_secret
genshi = Genshi(app) genshi = Genshi(app)
...@@ -82,7 +82,7 @@ def save_data(formdata, outfilename): ...@@ -82,7 +82,7 @@ def save_data(formdata, outfilename):
json.dump(formdata, outfile) json.dump(formdata, outfile)
def run_pdflatex(context, outputfilename, overwrite=True): def run_pdflatex(context, outputfilename, overwrite=True):
if not context.has_key('textemplate'): if 'textemplate' not in context:
context['textemplate'] = "text-image-quer.tex" context['textemplate'] = "text-image-quer.tex"
genshitex = TemplateLoader([config.textemplatedir]) genshitex = TemplateLoader([config.textemplatedir])
template = genshitex.load( template = genshitex.load(
...@@ -93,7 +93,7 @@ def run_pdflatex(context, outputfilename, overwrite=True): ...@@ -93,7 +93,7 @@ def run_pdflatex(context, outputfilename, overwrite=True):
context['text'] = publish_parts(context['text'], writer_name='latex')['body'] context['text'] = publish_parts(context['text'], writer_name='latex')['body']
#context['headline'] = publish_parts(context['headline'], writer_name='latex')['body'] #context['headline'] = publish_parts(context['headline'], writer_name='latex')['body']
tmpdir = tempfile.mkdtemp(dir=config.tmpdir) tmpdir = tempfile.mkdtemp(dir=config.tmpdir)
if context.has_key('img') and context['img'] and context['img'] != '__none': if 'img' in context and context['img'] and context['img'] != '__none':
try: try:
shutil.copy(os.path.join(config.imagedir, context['img']), shutil.copy(os.path.join(config.imagedir, context['img']),
os.path.join(tmpdir, context['img'])) os.path.join(tmpdir, context['img']))
...@@ -117,7 +117,7 @@ def run_pdflatex(context, outputfilename, overwrite=True): ...@@ -117,7 +117,7 @@ def run_pdflatex(context, outputfilename, overwrite=True):
try: try:
flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log') flash(Markup("<p>PDFLaTeX Output:</p><pre>%s</pre>" % e.output), 'log')
except: except:
print(e.output) print((e.output))
raise SyntaxWarning("PDFLaTeX bailed out") raise SyntaxWarning("PDFLaTeX bailed out")
finally: finally:
os.chdir(cwd) os.chdir(cwd)
...@@ -163,7 +163,7 @@ def index(**kwargs): ...@@ -163,7 +163,7 @@ def index(**kwargs):
data = defaultdict(str) data = defaultdict(str)
data.update(**kwargs) data.update(**kwargs)
filelist = glob.glob(config.datadir + '/*.schild') filelist = glob.glob(config.datadir + '/*.schild')
data['files'] = [unicode(os.path.basename(f)) for f in sorted(filelist)] data['files'] = [str(os.path.basename(f)) for f in sorted(filelist)]
return render_response('index.html', data) return render_response('index.html', data)
...@@ -174,7 +174,7 @@ def edit(**kwargs): ...@@ -174,7 +174,7 @@ def edit(**kwargs):
imagelist = sorted(glob.glob(config.imagedir + '/*.png')) imagelist = sorted(glob.glob(config.imagedir + '/*.png'))
data['images'] = [os.path.basename(f) for f in imagelist] data['images'] = [os.path.basename(f) for f in imagelist]
templatelist = glob.glob(config.textemplatedir + '/*.tex') templatelist = glob.glob(config.textemplatedir + '/*.tex')
data['templates'] = [unicode(os.path.basename(f)) data['templates'] = [str(os.path.basename(f))
for f in sorted(templatelist)] for f in sorted(templatelist)]
data['imageextensions'] = config.allowed_extensions data['imageextensions'] = config.allowed_extensions
return render_response('edit.html', data) return render_response('edit.html', data)
...@@ -190,7 +190,7 @@ def create(): ...@@ -190,7 +190,7 @@ def create():
if request.method == 'POST': if request.method == 'POST':
formdata = defaultdict(str, request.form.to_dict(flat=True)) formdata = defaultdict(str, request.form.to_dict(flat=True))
for a in ('headline', 'text'): for a in ('headline', 'text'):
formdata[a] = unicode(formdata[a]) formdata[a] = str(formdata[a])
try: try:
imgpath = save_and_convert_image_upload('imgupload') imgpath = save_and_convert_image_upload('imgupload')
if imgpath is not None: if imgpath is not None:
...@@ -205,18 +205,18 @@ def create(): ...@@ -205,18 +205,18 @@ def create():
save_data(formdata, outfilename) save_data(formdata, outfilename)
run_pdflatex(formdata, os.path.join(config.pdfdir, outpdfname)) run_pdflatex(formdata, os.path.join(config.pdfdir, outpdfname))
try: try:
flash(Markup(u"""PDF created and data saved. You might create another one. Here's a preview. Click to print.<br/> flash(Markup("""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>""" % <a href="%s"><img src="%s"/></a>""" %
(url_for('schild', filename=outfilename), url_for( (url_for('schild', filename=outfilename), url_for(
'pdfthumbnail', pdfname=outpdfname, maxgeometry=200)) 'pdfthumbnail', pdfname=outpdfname, maxgeometry=200))
)) ))
except: except:
print("%s created" % outpdfname) print(("%s created" % outpdfname))
except Exception as e: except Exception as e:
try: try:
flash(u"Could not create pdf or save data: %s" % str(e), 'error') flash("Could not create pdf or save data: %s" % str(e), 'error')
except: except:
print("Could not create pdf or save data: %s" % str(e)) print(("Could not create pdf or save data: %s" % str(e)))
data = {'form': formdata} data = {'form': formdata}
imagelist = glob.glob(config.imagedir + '/*.png') imagelist = glob.glob(config.imagedir + '/*.png')
...@@ -236,7 +236,7 @@ def create(): ...@@ -236,7 +236,7 @@ def create():
@app.route('/schild/<filename>') @app.route('/schild/<filename>')
def schild(filename): def schild(filename):
return render_response('schild.html', {'filename': filename, 'printer': [unicode(f) for f in sorted(config.printers.keys())]}) return render_response('schild.html', {'filename': filename, 'printer': [str(f) for f in sorted(config.printers.keys())]})
@app.route('/printout', methods=['POST']) @app.route('/printout', methods=['POST'])
...@@ -249,11 +249,11 @@ def printout(): ...@@ -249,11 +249,11 @@ def printout():
try: try:
lprout = check_output(['lpr', '-H', str(config.printserver), '-P', str( lprout = check_output(['lpr', '-H', str(config.printserver), '-P', str(
printer), '-#', str(copies)] + config.lproptions + [filename], stderr=STDOUT) printer), '-#', str(copies)] + config.lproptions + [filename], stderr=STDOUT)
flash(u'Schild wurde zum Drucker geschickt!') flash('Schild wurde zum Drucker geschickt!')
except CalledProcessError as e: except CalledProcessError as e:
flash(Markup("<p>Could not print:</p><pre>%s</pre>" % e.output), 'error') flash(Markup("<p>Could not print:</p><pre>%s</pre>" % e.output), 'error')
else: else:
flash(u'Ungültige Anzahl Kopien!') flash('Ungültige Anzahl Kopien!')
return redirect(url_for('index')) return redirect(url_for('index'))
def delete_file(filename): def delete_file(filename):
...@@ -261,10 +261,10 @@ def delete_file(filename): ...@@ -261,10 +261,10 @@ def delete_file(filename):
os.unlink(os.path.join(config.datadir, filename)) os.unlink(os.path.join(config.datadir, filename))
for f in glob.glob(os.path.join(config.pdfdir, filename + '.pdf*')): for f in glob.glob(os.path.join(config.pdfdir, filename + '.pdf*')):
os.unlink(f) os.unlink(f)
flash(u"Schild %s wurde gelöscht" % filename) flash("Schild %s wurde gelöscht" % filename)
return redirect(url_for('index')) return redirect(url_for('index'))
except: except:
flash(u"Schild %s konnte nicht gelöscht werden." % filename, 'error') flash("Schild %s konnte nicht gelöscht werden." % filename, 'error')
return redirect(url_for('schild', filename=filename)) return redirect(url_for('schild', filename=filename))
...@@ -312,8 +312,8 @@ def tplthumbnail(tplname, maxgeometry): ...@@ -312,8 +312,8 @@ def tplthumbnail(tplname, maxgeometry):
run_pdflatex( run_pdflatex(
{'textemplate': secure_filename(tplname), {'textemplate': secure_filename(tplname),
'img': 'pictograms-nps-misc-camera.png', 'img': 'pictograms-nps-misc-camera.png',
'headline': u'Überschrift', 'headline': 'Überschrift',
'text': u'Dies ist der Text, der in der UI als Text bezeichnet ist.', 'text': 'Dies ist der Text, der in der UI als Text bezeichnet ist.',
'markup': 'latex', 'markup': 'latex',
}, pdfpath, overwrite=False }, pdfpath, overwrite=False
) )
...@@ -338,13 +338,13 @@ def recreate_cache(): ...@@ -338,13 +338,13 @@ def recreate_cache():
glob.glob(os.path.join(config.imagedir, '*.png.*'))): glob.glob(os.path.join(config.imagedir, '*.png.*'))):
try: try:
os.unlink(filename) os.unlink(filename)
print("Deleted %s" % filename) print(("Deleted %s" % filename))
except Exception as e: except Exception as e:
print("Could not delete %s: %s" % (filename, str(e))) print(("Could not delete %s: %s" % (filename, str(e))))
for filename in glob.glob(os.path.join(config.datadir, '*.schild')): for filename in glob.glob(os.path.join(config.datadir, '*.schild')):
data = load_data(filename) data = load_data(filename)
pdfname = os.path.join(config.pdfdir, data['pdfname']) pdfname = os.path.join(config.pdfdir, data['pdfname'])
print("Recreating %s" % pdfname) print(("Recreating %s" % pdfname))
run_pdflatex(data, pdfname) run_pdflatex(data, pdfname)
if __name__ == '__main__': if __name__ == '__main__':
......
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