comparison piecrust/admin/web.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents e1cadbfddb48
children
comparison
equal deleted inserted replaced
978:7e51d14097cb 979:45ad976712ec
1 import os.path 1 import os.path
2 import logging 2 import logging
3 from flask import Flask 3 from flask import Flask
4 from werkzeug import SharedDataMiddleware
5 4
6 5
7 logger = logging.getLogger(__name__) 6 logger = logging.getLogger(__name__)
8 7
9 8
36 35
37 # Debugging stuff 36 # Debugging stuff
38 if app.config.get('FOODTRUCK_DEBUG_404'): 37 if app.config.get('FOODTRUCK_DEBUG_404'):
39 @app.errorhandler(404) 38 @app.errorhandler(404)
40 def page_not_found(e): 39 def page_not_found(e):
41 return _debug_page_not_found(e) 40 return _debug_page_not_found(app, e)
42 41
43 logger.debug("Created FoodTruck app with admin root: %s" % root_dir) 42 logger.debug("Created FoodTruck app with admin root: %s" % root_dir)
44 43
45 return app 44 return app
46 45
47 46
48 def _debug_page_not_found(e): 47 def _debug_page_not_found(app, e):
49 from flask import request, url_for 48 from flask import request, url_for
50 output = [] 49 output = []
51 for rule in app.url_map.iter_rules(): 50 for rule in app.url_map.iter_rules():
52 options = {} 51 options = {}
53 for arg in rule.arguments: 52 for arg in rule.arguments:
58 except: 57 except:
59 url = '???' 58 url = '???'
60 line = ("{:50s} {:20s} {}".format(rule.endpoint, methods, url)) 59 line = ("{:50s} {:20s} {}".format(rule.endpoint, methods, url))
61 output.append(line) 60 output.append(line)
62 61
63 resp = 'FOODTRUCK_ROOT_URL=%s<br/>\n' % str(app.config['FOODTRUCK_ROOT_URL']) 62 resp = 'FOODTRUCK_ROOT_URL=%s<br/>\n' % str(
63 app.config['FOODTRUCK_ROOT_URL'])
64 resp += 'PATH=%s<br/>\n' % request.path 64 resp += 'PATH=%s<br/>\n' % request.path
65 resp += 'ENVIRON=%s<br/>\n' % str(request.environ) 65 resp += 'ENVIRON=%s<br/>\n' % str(request.environ)
66 resp += 'URL RULES:<br/>\n' 66 resp += 'URL RULES:<br/>\n'
67 resp += '<br/>\n'.join(sorted(output)) 67 resp += '<br/>\n'.join(sorted(output))
68 return resp, 404 68 return resp, 404