def FindCommand(pKey, pFilePath, pSearchPath, pSection, pList=False, pVerbose=False):
    '''
    Find command keyword and extract containing line
    pKey         -- String identifying line to use as command template
    pFilePath    -- File to use in macro expansion
    pSearchPath  -- File to scan for command 
    pSection     -- Section containing command
    pList        -- 
    '''
    if pVerbose:
        print 'DoM.py FindCommand:', pKey, pFilePath, pSearchPath, pSection
    
    if not os.path.exists(pSearchPath):
        lCommand = ''
        print 'DoM.py Could not find menu file', pSearchPath
    else:
        lSection = pSection.lower()
        lKey = pKey.lower()

#       ---- Load menu file
        lFile = open(pSearchPath, 'r')
        lText = lFile.readlines()
        lFile.close()
        if len(lText) < 1:
            print 'DoM.py Menu', pSearchPath, 'read failed'

        lFound = False
        lCommand = ''
        lCount = 0
        if pList:
            print 'DoM.py Available commands in', pSearchPath

#       ---- Scan menu file
        for lLine in lText:
            lLine = lLine.lstrip()
            if len(lLine) < 1:
                continue

#           ---- Start of section
            if lLine[0] == '[':
                lCount = 0
                lPos = lLine.find(']')
                if lPos > 0:
                    lFoundSection = lLine[1:lPos].lower()
                else:
                    lFoundSection = ''
                    
#               ---- Check for conditions, conditions are ignored                    
                if lFoundSection[0] == '/':
                    lPos2 = lFoundSection.rfind('/')
                    if lPos2 >= 0:
                        lFoundSection = lFoundSection[lPos2+1:]
                elif lFoundSection[0] == '!':
                    lPos2 = lFoundSection.rfind('!')
                    if lPos2 >= 0:
                        lFoundSection = lFoundSection[lPos2+1:]
                #if lSection != lFoundSection and lSection != '*':
                if not lFoundSection.startswith(lSection) and lSection != '*':
                    if pVerbose:
                        print 'DoM.py not found', lSection, 'in', lFoundSection
                    if lFound == True:
                        break
                    continue
                elif lSection != '*' and lFound == True:
                    break
                else:
                    if pVerbose:
                        print 'DoM.py found', lSection, 'in', lFoundSection
                    if pList:
                        print 'DoM.py Section:', lFoundSection
                    lFound = True

#           ---- Comments
            elif lLine[0] == ';':
                if lFound and pList:
                    print 'DoM.py        ', lLine,

#           ---- Command lines and label lines
            else:
                if not lFound:
                    continue
                if lLine[0] == '-':
                    continue
                lPos = lLine.find(',')
                if lPos > 0:
                    lMatch = lLine[0:lPos].lower()
                else:
                    continue
                    
#               ---- Check for conditions, conditions are ignored                    
                if lMatch[0] == '/':
                    lPos2 = lMatch.rfind('/')
                    if lPos2 >= 0:
                        lMatch = lMatch[lPos2+1:]
                elif lMatch[0] == '!':
                    lPos2 = lMatch.rfind('!')
                    if lPos2 >= 0:
                        lMatch = lMatch[lPos2+1:]
                
                lCount += 1
                if pList:
                    if lPos > 0:
                        lLineText = lLine[lPos+1:]
                    print "DoM.py %5d: %-20s| %s" % (lCount, lMatch, lLineText),

#               ---- Check for matching command
                #if lKey == lMatch:                   # must match command key
                if lMatch.startswith(lKey):           # command key starts with key
                    lCommand = lLine[lPos+1:]
                    if pVerbose:
                        print 'DoM.py found command', lKey, 'in', lMatch, 'for', lCommand
                    break
        else:
            print 'DoM.py no command found in', pSearchPath, pSection
                    
    return lCommand[0:-1]

    Find command keyword and extract containing line
    pKey         -- String identifying line to use as command template
    pFilePath    -- File to use in macro expansion
    pSearchPath  -- File to scan for command 
    pSection     -- Section containing command
    pList        -- 
    
recipes/Python/577453_Extract_expexecute_commQEditor_menu_file_file/recipe-577453.py