Python脚本设置断点和遇到一个common

2024-04-23 08:51:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图构建一个脚本,在winIDEA中设置断点(这个ide将运行一个具有不同注释的项目)。在识别特定注释后,必须在winIDEA中设置断点。我对这种语言有点陌生,我在制作这个脚本时遇到了一些问题。我不确定这里的代码是否正确,但我正在尝试获取注释被识别的行,然后在程序中的这一行设置一个断点。在

import inspect
import logging

import isystem.connect as ic
import sys

connMgr = ic.ConnectionMgr()
connMgr.connectMRU('')

dbg = ic.CDebugFacade(connMgr)
bc = ic.CBreakpointController(connMgr)
exe = ic.CExecutionController(connMgr)

logging.basicConfig(
    format = "%(levelname) -10s %(asctime)s %(message)s",
    level = logging.DEBUG

def test():

    caller_list = []
    frame = inspect.currentframe()

    this_frame = frame  # Save current frame.

    while frame.f_back:
        print frame
        caller_list.append('{0}()'.format(frame.f_code.co_name))
        frame = frame.f_back

    caller_line = this_frame.f_back.f_lineno
    callers =  '/'.join(reversed(caller_list))

    logging.info('Line {0} : {1}'.format(caller_line, callers))
    print caller_line

def foo():
   test()

def bar():
   foo()

test()

datafile= file(r'C:\Documents and Settings\stiral1\Desktop\function.py')
stringfile=datafile.read()
item_search="haha"
counter=0

print stringfile.find(item_search,counter)


while counter != -1:
    print stringfile.find(item_search,counter)
    bc.setBP(counter,r'C:\_DevTools\winIDEA\2012\Examples\Simulator\PPC\Simple\main.c')

取而代之的是一个随机行,以及我在字符串中遇到元素的位置(我使在ide中运行的脚本在某一点上成为字符串)。我不知道还有什么。。。帮助一个新手!在


Tags: testimport脚本formatloggingdefcounterframe
1条回答
网友
1楼 · 发布于 2024-04-23 08:51:15

这就是我的想法:

def wdSetBPComment(wdPrmStr):
    assert(wdGetNrOfSubStrings(wdPrmStr) == 2)
    comment = wdGetSubString_1(wdPrmStr)
    function = wdGetSubString_2(wdPrmStr)

    gl_tpLocation.setResourceName(function)
    gl_tpLocation.setSearch(ic.E_TRUE)
    gl_tpLocation.setMatchingType(ic.CTestLocation.E_MATCH_PLAIN)
    gl_tpLocation.setSearchPattern(comment)
    lineLocation = addrCtrl.getSourceLocation(gl_tpLocation)
    wdSetBreakpoint(lineLocation.getFileName()+lineLocation.getLineNumber())
    gl_bcCtrl.setBP(lineNo,fileName)

    return (gl_wdOkStr)

相关问题 更多 >