#! /usr/bin/env python
import os
import re
from abjad.tools import systemtools


def find_lower_camel_case_definitions():
    total_modules_with_lower_camel_case_definitions = 0
    lower_camel_case_definitions = []
    pattern = re.compile(r'.*def [_]*[a-z]+[A-Z]+.*')
    for directory_path, subdirectory_names, file_names in os.walk('.'):
        for file_name in file_names:
            found_lower_camel_case_definition = False
            if file_name.endswith('.py') and not file_name == 'GuileProxy.py':
                full_file_name = os.path.join(directory_path, file_name)
                fp = file(full_file_name, 'r')
                for line in fp:
                    if pattern.match(line):
                        lower_camel_case_definitions.append(line)
                        if not found_lower_camel_case_definition:
                            print full_file_name
                            found_lower_camel_case_definition = True
                            total_modules_with_lower_camel_case_definitions \
                                += 1
                        print line.strip()
            if found_lower_camel_case_definition:
                print
    
    total = total_modules_with_lower_camel_case_definitions
    print 'Total modules with lower camel case definitions: {}'.format(total)

    total = len(lower_camel_case_definitions)
    print 'Total lower camel case definitions:              {}'.format(total)


if __name__ == '__main__':
    systemtools.IOManager.clear_terminal()
    print 'Finding lower camel case definitions ...\n'
    find_lower_camel_case_definitions()
    print
