def breakpoints(): "Add or remove breakpoints" # Get all .py files files = listdir(apath('', r=request), '.*\.py$') files = [ filename for filename in files if filename and 'languages' not in filename and not filename. startswith("admin") and not filename.startswith("examples") ] form = SQLFORM.factory( Field('filename', requires=IS_IN_SET(files), label=T("Filename")), Field('lineno', 'integer', label=T("Line number"), requires=IS_NOT_EMPTY()), Field('temporary', 'boolean', label=T("Temporary"), comment=T("deleted after first hit")), Field('condition', 'string', label=T("Condition"), comment=T("honored only if the expression evaluates to true")), ) if form.accepts(request.vars, session): filename = os.path.join(request.env['applications_parent'], 'applications', form.vars.filename) err = dbg_debugger.do_set_breakpoint(filename, form.vars.lineno, form.vars.temporary, form.vars.condition) response.flash = T("Set Breakpoint on %s at line %s: %s") % ( filename, form.vars.lineno, err or T('successful')) for item in request.vars: if item[:7] == 'delete_': dbg_debugger.do_clear(item[7:]) breakpoints = [{ 'number': bp[0], 'filename': os.path.basename(bp[1]), 'path': bp[1], 'lineno': bp[2], 'temporary': bp[3], 'enabled': bp[4], 'hits': bp[5], 'condition': bp[6] } for bp in dbg_debugger.do_list_breakpoint()] return dict(breakpoints=breakpoints, form=form)
def toggle_breakpoint(): "Set or clear a breakpoint" lineno = None ok = None try: filename = os.path.join(request.env['applications_parent'], 'applications', request.vars.filename) # normalize path name: replace slashes, references, etc... filename = os.path.normpath(os.path.normcase(filename)) if not request.vars.data: # ace send us the line number! lineno = int(request.vars.sel_start) + 1 else: # editarea send us the offset, manually check the cursor pos start = 0 sel_start = int(request.vars.sel_start) for lineno, line in enumerate(request.vars.data.split("\n")): if sel_start <= start: break start += len(line) + 1 else: lineno = None if lineno is not None: for bp in dbg_debugger.do_list_breakpoint(): no, bp_filename, bp_lineno, temporary, enabled, hits, cond = bp # normalize path name: replace slashes, references, etc... bp_filename = os.path.normpath(os.path.normcase(bp_filename)) if filename == bp_filename and lineno == bp_lineno: err = dbg_debugger.do_clear_breakpoint(filename, lineno) response.flash = T("Removed Breakpoint on %s at line %s", ( filename, lineno)) ok = False break else: err = dbg_debugger.do_set_breakpoint(filename, lineno) response.flash = T("Set Breakpoint on %s at line %s: %s") % ( filename, lineno, err or T('successful')) ok = True else: response.flash = T("Unable to determine the line number!") except Exception as e: session.flash = str(e) return response.json({'ok': ok, 'lineno': lineno})
def toggle_breakpoint(): "Set or clear a breakpoint" lineno = None ok = None try: filename = os.path.join(request.env['applications_parent'], 'applications', request.vars.filename) # normalize path name: replace slashes, references, etc... filename = os.path.normpath(os.path.normcase(filename)) if not request.vars.data: # ace send us the line number! lineno = int(request.vars.sel_start) + 1 else: # editarea send us the offset, manually check the cursor pos start = 0 sel_start = int(request.vars.sel_start) for lineno, line in enumerate(request.vars.data.split("\n")): if sel_start <= start: break start += len(line) + 1 else: lineno = None if lineno is not None: for bp in dbg_debugger.do_list_breakpoint(): no, bp_filename, bp_lineno, temporary, enabled, hits, cond = bp # normalize path name: replace slashes, references, etc... bp_filename = os.path.normpath(os.path.normcase(bp_filename)) if filename == bp_filename and lineno == bp_lineno: err = dbg_debugger.do_clear_breakpoint(filename, lineno) response.flash = T("Removed Breakpoint on %s at line %s", (filename, lineno)) ok = False break else: err = dbg_debugger.do_set_breakpoint(filename, lineno) response.flash = T("Set Breakpoint on %s at line %s: %s") % ( filename, lineno, err or T('successful')) ok = True else: response.flash = T("Unable to determine the line number!") except Exception as e: session.flash = str(e) return response.json({'ok': ok, 'lineno': lineno})
def breakpoints(): "Add or remove breakpoints" # Get all .py files files = listdir(apath('', r=request), '.*\.py$') files = [filename for filename in files if filename and 'languages' not in filename and not filename.startswith("admin") and not filename.startswith("examples")] form = SQLFORM.factory( Field('filename', requires=IS_IN_SET(files), label=T("Filename")), Field('lineno', 'integer', label=T("Line number"), requires=IS_NOT_EMPTY()), Field('temporary', 'boolean', label=T("Temporary"), comment=T("deleted after first hit")), Field('condition', 'string', label=T("Condition"), comment=T("honored only if the expression evaluates to true")), ) if form.accepts(request.vars, session): filename = os.path.join(request.env['applications_parent'], 'applications', form.vars.filename) err = dbg_debugger.do_set_breakpoint(filename, form.vars.lineno, form.vars.temporary, form.vars.condition) response.flash = T("Set Breakpoint on %s at line %s: %s") % ( filename, form.vars.lineno, err or T('successful')) for item in request.vars: if item[:7] == 'delete_': dbg_debugger.do_clear(item[7:]) breakpoints = [{'number': bp[0], 'filename': os.path.basename(bp[1]), 'path': bp[1], 'lineno': bp[2], 'temporary': bp[3], 'enabled': bp[4], 'hits': bp[5], 'condition': bp[6]} for bp in dbg_debugger.do_list_breakpoint()] return dict(breakpoints=breakpoints, form=form)