Created
April 10, 2012 10:06
-
-
Save kwatch/2350065 to your computer and use it in GitHub Desktop.
Alternative template file for pyramid_debugtoolbar to open errored file quickly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| <%! | |
| ## | |
| ## This is an alternative template file for pyramid_debugtoolbar. | |
| ## Using this template, you can open errored file very quickly. | |
| ## | |
| ## | |
| ## Usage: | |
| ## | |
| ## | |
| ## file 'yourapp/development.ini': | |
| ## | |
| ## [app:main] | |
| ## ## 'txmt': TextMate, 'mvim': MacVim, 'emacs': Emacs (with EmacsHandler.app) | |
| ## editorkicker.url_schema = txmt | |
| ## | |
| ## | |
| ## file 'yourapp/__ini__.py': | |
| ## | |
| ## def main(global_config, **settings): | |
| ## if settings.get('editorkicker.url_schema'): | |
| ## config.override_asset('pyramid_debugtoolbar:templates/exception_summary.dbtmako', | |
| ## '/some/where/to/exception_summary.dbtmako') | |
| ## | |
| ## | |
| import re | |
| import pyramid.threadlocal | |
| def get_url_schema(): | |
| return pyramid.threadlocal.get_current_registry().settings.get('editorkicker.url_schema') | |
| stacktrace_rexp = re.compile(r'<h4>(File <cite class="filename">"(.*?)"</cite>.*?,\s+line .*?(\d+).*?)</h4>', re.S) | |
| def add_editorkicker_links(string): | |
| url_schema = get_url_schema() | |
| if not url_schema: | |
| return string | |
| def fn(m, url_schema=url_schema): | |
| cont, filepath, linenum = m.groups() | |
| return '<h4><a href="%s://open/?url=file://%s&line=%s">%s</a></h4>' % \ | |
| (url_schema, filepath, linenum, cont) | |
| return stacktrace_rexp.sub(fn, string) | |
| %> | |
| <div class="${classes}"> | |
| ${title|n} | |
| <ul>${add_editorkicker_links(frames)|n}</ul> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment