#! /usr/bin/env python

from abjad.cfg.cfg import ABJADPATH
from abjad.tools import iotools
import itertools
import os
import pprint


def _find_duplicate_module_names():
   file_path_pairs = [ ]
   tools_directory = os.path.join(ABJADPATH, 'tools')
   for path, subdirectories, files in os.walk(tools_directory):
      for f in files:
         if f.endswith('.py'):
            if not f == '__init__.py':
               file_path_pair = (f, path)
               file_path_pairs.append(file_path_pair)
   file_path_pairs.sort()
   result = [ ]
   pairs_generator = itertools.groupby(file_path_pairs, lambda x: x[0])
   for key, values_generator in pairs_generator:
      values = list(values_generator)
      if 1 < len(values):
         full_paths = [ ]
         for f, path in values:
            full_path = os.path.join(path, f)
            full_path = full_path.replace(ABJADPATH, '')
            full_paths.append(full_path)
         result.append(full_paths)
   return result


if __name__ == '__main__':
   iotools.clear_terminal()
   result = _find_duplicate_module_names()
   if not result:
      print 'No duplicate tools module names found.'
   else:
      pprint.pprint(result)
   print ''
