def main():
    'Walks through the directory and finds and parses .cmd files.'
    (log_level, directory, output) = parse_arguments()
    level = getattr(logging, log_level)
    logging.basicConfig(format='%(levelname)s: %(message)s', level=level)
    filename_matcher = re.compile(_FILENAME_PATTERN)
    line_matcher = re.compile(_LINE_PATTERN)
    compile_commands = []
    for (dirpath, _, filenames) in os.walk(directory):
        for filename in filenames:
            if (not filename_matcher.match(filename)):
                continue
            filepath = os.path.join(dirpath, filename)
            with open(filepath, 'rt') as f:
                for line in f:
                    result = line_matcher.match(line)
                    if (not result):
                        continue
                    try:
                        entry = process_line(directory, dirpath, result.group(1), result.group(2))
                        compile_commands.append(entry)
                    except ValueError as err:
                        logging.info('Could not add line from %s: %s', filepath, err)
    with open(output, 'wt') as f:
        json.dump(compile_commands, f, indent=2, sort_keys=True)
    count = len(compile_commands)
    if (count < _LOW_COUNT_THRESHOLD):
        logging.warning('Found %s entries. Have you compiled the kernel?', count)
Walks through the directory and finds and parses .cmd files.
def main():
    
    (log_level, directory, output) = parse_arguments()
    level = getattr(logging, log_level)
    logging.basicConfig(format='%(levelname)s: %(message)s', level=level)
    filename_matcher = re.compile(_FILENAME_PATTERN)
    line_matcher = re.compile(_LINE_PATTERN)
    compile_commands = []
    for (dirpath, _, filenames) in os.walk(directory):
        for filename in filenames:
            if (not filename_matcher.match(filename)):
                continue
            filepath = os.path.join(dirpath, filename)
            with open(filepath, 'rt') as f:
                for line in f:
                    result = line_matcher.match(line)
                    if (not result):
                        continue
                    try:
                        entry = process_line(directory, dirpath, result.group(1), result.group(2))
                        compile_commands.append(entry)
                    except ValueError as err:
                        logging.info('Could not add line from %s: %s', filepath, err)
    with open(output, 'wt') as f:
        json.dump(compile_commands, f, indent=2, sort_keys=True)
    count = len(compile_commands)
    if (count < _LOW_COUNT_THRESHOLD):
        logging.warning('Found %s entries. Have you compiled the kernel?', count)