def create_dir_stats(aliases, directory):
     dir_stats = DirStats(directory)
     for category in dir_stats.categories:
         aliased_category = aliases.get(category, None)
         if aliased_category:
             dir_stats.add_category(aliased_category)
     return dir_stats
    def calculate_percentages_for_git_repository(self, aliases, max_files):
        git_lines_per_committer_for_file = subprocess.Popen("git ls-files master .",
                                                            shell=True, bufsize=1, stdout=subprocess.PIPE).stdout
        lines = git_lines_per_committer_for_file.readlines()
        dir_stat_list = {}
        total_file_count = 0

        for line in lines:
            full_file_name = line.strip().decode("unicode_escape", "ignore")
            full_file_name = full_file_name.encode("latin-1", "replace")
            full_file_name = full_file_name.decode("utf-8", "replace")

            file_components = full_file_name.split(".", 1)
            if len(file_components) != 2:
                continue
            extension = file_components[1]
            if extension != "java":
                continue

            total_file_count += 1
            directory = full_file_name[:full_file_name.rfind("/")]
            contributors = self.get_contributors_for_file(full_file_name)

            dir_stats = dir_stat_list.get(directory)
            if dir_stats is None:
                dir_stats = DirStats(directory)
                for category in dir_stats.categories:
                    aliased_category = aliases.get(category, None)
                    if aliased_category:
                        dir_stats.add_category(aliased_category)
                dir_stat_list[directory] = dir_stats

            dir_stats.add_file_contributions(full_file_name, contributors)

            if max_files is not None and total_file_count > max_files:
                break
        print 'Total Files: ', total_file_count
        sorted_dir_list = sorted(dir_stat_list)
        return dir_stat_list, sorted_dir_list
 def __init__(self, name):
     DirStats.__init__(self)
     self.name = name
     self.dir_stats = []