debugger
This commit is contained in:
+1
-1
@@ -1970,7 +1970,7 @@ class PostgreSQLAdapter(BaseAdapter):
|
||||
if self.drivers.get('psycopg2'):
|
||||
self.driver = self.drivers['psycopg2']
|
||||
elif self.drivers.get('pg8000'):
|
||||
self.driver = drivers['pg8000']
|
||||
self.driver = drivers.get('pg8000')
|
||||
elif library == "postgres:psycopg2":
|
||||
self.driver = self.drivers.get('psycopg2')
|
||||
elif library == "postgres:pg8000":
|
||||
|
||||
+100
@@ -10,6 +10,7 @@ License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pdb
|
||||
import Queue
|
||||
import sys
|
||||
@@ -82,7 +83,106 @@ def communicate(command=None):
|
||||
return ''.join(result)
|
||||
|
||||
|
||||
# New debugger implementation using qdb and a web UI
|
||||
|
||||
import gluon.contrib.qdb as qdb
|
||||
from gluon import portalocker
|
||||
|
||||
|
||||
def lock(name=''):
|
||||
from gluon.globals import current
|
||||
locker = open(os.path.join(current.request.folder, 'debug_%s.lock' % name),
|
||||
'a')
|
||||
portalocker.lock(locker, portalocker.LOCK_EX)
|
||||
return locker
|
||||
|
||||
|
||||
def unlock(locker):
|
||||
portalocker.unlock(locker)
|
||||
locker.close()
|
||||
|
||||
|
||||
def check_interaction(fn):
|
||||
"Decorator to clean and prevent interaction when not available"
|
||||
def check_fn(self, *args, **kwargs):
|
||||
locker = lock('interact')
|
||||
try:
|
||||
if self.filename:
|
||||
self.clear_interaction()
|
||||
fn(self, *args, **kwargs)
|
||||
finally:
|
||||
unlock(locker)
|
||||
return check_fn
|
||||
|
||||
|
||||
class WebDebugger(qdb.Frontend):
|
||||
"Qdb web2py interface"
|
||||
|
||||
def __init__(self, pipe, completekey='tab', stdin=None, stdout=None, skip=None):
|
||||
qdb.Frontend.__init__(self, pipe)
|
||||
self.clear_interaction()
|
||||
|
||||
def clear_interaction(self):
|
||||
self.filename = None
|
||||
self.lineno = None
|
||||
self.exception_info = None
|
||||
|
||||
# redefine Frontend methods:
|
||||
|
||||
def run(self):
|
||||
locker = lock('run')
|
||||
try:
|
||||
while self.pipe.poll():
|
||||
qdb.Frontend.run(self)
|
||||
finally:
|
||||
unlock(locker)
|
||||
|
||||
def interaction(self, filename, lineno, line):
|
||||
# store current status
|
||||
locker = lock('interact')
|
||||
try:
|
||||
self.filename = filename
|
||||
self.lineno = lineno
|
||||
finally:
|
||||
unlock(locker)
|
||||
|
||||
def exception(self, title, extype, exvalue, trace, request):
|
||||
self.exception_info = {'title': title,
|
||||
'extype': extype, 'exvalue': exvalue,
|
||||
'trace': trace, 'request': request}
|
||||
|
||||
@check_interaction
|
||||
def do_continue(self):
|
||||
qdb.Frontend.do_continue(self)
|
||||
|
||||
@check_interaction
|
||||
def do_step(self):
|
||||
qdb.Frontend.do_step(self)
|
||||
|
||||
@check_interaction
|
||||
def do_return(self):
|
||||
qdb.Frontend.do_return(self)
|
||||
|
||||
@check_interaction
|
||||
def do_next(self):
|
||||
qdb.Frontend.do_next(self)
|
||||
|
||||
@check_interaction
|
||||
def do_quit(self):
|
||||
qdb.Frontend.do_quit(self)
|
||||
|
||||
|
||||
|
||||
# create the connection between threads:
|
||||
|
||||
parent_queue, child_queue = Queue.Queue(), Queue.Queue()
|
||||
front_conn = qdb.QueuePipe("parent", parent_queue, child_queue)
|
||||
child_conn = qdb.QueuePipe("child", child_queue, parent_queue)
|
||||
|
||||
web_debugger = WebDebugger(front_conn) # frontend
|
||||
qdb_debugger = qdb.Qdb(pipe=child_conn, redirect_stdio=False) # backend
|
||||
dbg = qdb_debugger
|
||||
|
||||
import gluon.main
|
||||
gluon.main.global_settings.debugging = True
|
||||
|
||||
|
||||
@@ -255,6 +255,7 @@ def highlight(
|
||||
counter=1,
|
||||
styles=None,
|
||||
highlight_line=None,
|
||||
context_lines=None,
|
||||
attributes=None,
|
||||
):
|
||||
styles = styles or {}
|
||||
@@ -311,6 +312,14 @@ def highlight(
|
||||
lines[lineno] = '<div style="%s">%s</div>' % (linehighlight_style, lines[lineno])
|
||||
linenumbers[lineno] = '<div style="%s">%s</div>' % (linehighlight_style, linenumbers[lineno])
|
||||
|
||||
if context_lines:
|
||||
if lineno + context_lines < len(lines):
|
||||
del lines[lineno + context_lines:]
|
||||
del linenumbers[lineno + context_lines:]
|
||||
if lineno -context_lines > 0:
|
||||
del lines[0:lineno - context_lines]
|
||||
del linenumbers[0:lineno - context_lines]
|
||||
|
||||
code = '<br/>'.join(lines)
|
||||
numbers = '<br/>'.join(linenumbers)
|
||||
|
||||
|
||||
@@ -1413,6 +1413,7 @@ class CODE(DIV):
|
||||
link = self['link']
|
||||
counter = self.attributes.get('counter', 1)
|
||||
highlight_line = self.attributes.get('highlight_line', None)
|
||||
context_lines = self.attributes.get('context_lines', None)
|
||||
styles = self['styles'] or {}
|
||||
return highlight(
|
||||
join(self.components),
|
||||
@@ -1422,6 +1423,7 @@ class CODE(DIV):
|
||||
styles=styles,
|
||||
attributes=self.attributes,
|
||||
highlight_line=highlight_line,
|
||||
context_lines=context_lines,
|
||||
)
|
||||
|
||||
|
||||
|
||||
+5
-3
@@ -490,6 +490,11 @@ def wsgibase(environ, responder):
|
||||
# run controller
|
||||
# ##################################################
|
||||
|
||||
if global_settings.debugging and request.application != "admin":
|
||||
import gluon.debug
|
||||
# activate the debugger and wait to reach application code
|
||||
gluon.debug.dbg.do_debug(mainpyfile=request.folder)
|
||||
|
||||
serve_controller(request, response, session)
|
||||
|
||||
except HTTP, http_response:
|
||||
@@ -591,9 +596,6 @@ def wsgibase(environ, responder):
|
||||
if response and hasattr(response, 'session_file') \
|
||||
and response.session_file:
|
||||
response.session_file.close()
|
||||
# if global_settings.debugging:
|
||||
# import gluon.debug
|
||||
# gluon.debug.stop_trace()
|
||||
|
||||
session._unlock(response)
|
||||
http_response, new_environ = rewrite.try_rewrite_on_error(
|
||||
|
||||
Reference in New Issue
Block a user