# Path: pypasta/MAINTAINERS.py
# class MAINTAINERS:
#     def get_sections_by_files(self, filenames):
#         sections = set()
#         for file in filenames:
#             if file.startswith('linux/'):
#                 file = file[len('linux/'):]
#             sections |= self.get_sections_by_file(file)
# 
#         return sections
# 
#     def get_sections_by_file(self, filename):
#         sections = set()
#         for section in self.sections.values():
#             if section.match(filename):
#                 sections.add(section.description)
#         return sections
# 
#     def get_maintainers(self, section):
#         return self.sections[section].get_maintainers()
# 
#     def __getitem__(self, item):
#         return self.sections[item]
# 
#     def __init__(self, d_cluster, project_name, repo, revision):
#         maintainers = repo.get_blob(revision, 'MAINTAINERS')
#         try:
#             maintainers = maintainers.decode('utf-8')
#         except:
#             # older versions use ISO8859
#             maintainers = maintainers.decode('iso8859')
# 
#         maintainers = maintainers.splitlines()
# 
#         if project_name in _prepare_maintainers:
#             maintainers = _prepare_maintainers[project_name](maintainers)
#         else:
#             raise NotImplementedError(
#                 'No MAINTAINERS implementation for project' % project_name)
# 
#         self.sections = dict()
# 
#         def add_section(content):
#             section = Section(repo, revision, content)
#             self.sections[section.description] = section
# 
#         tmp = list()
#         for line in maintainers:
#             if len(line.strip()) == 0:
#                 if len(tmp):
#                     add_section(tmp)
#                 tmp = list()
#             else:
#                 tmp.append(line)
#         add_section(tmp)
# 
#         f_maintainers_cluster = os.path.join(d_cluster, '%s.txt' % revision)
#         self.cluster = None
#         if os.path.exists(f_maintainers_cluster):
#             with open(f_maintainers_cluster, 'r') as f:
#                 cluster = f.read()
#             cluster = list(filter(None, cluster.split('\n\n')))
#             self.cluster = [set(x.split('\n')) for x in cluster]
#         else:
#             log.warning('No MAINTAINERS cluster for %s' % revision)
# 
# Path: pypasta/Util.py
# def file_to_string(filename, must_exist=True):
#     try:
#         # I HATE ENCONDING!
#         # Anyway, opening a file as binary and decoding it to iso8859 solves the problem :-)
#         with open(filename, 'rb') as f:
#             retval = str(f.read().decode('iso8859'))
#             f.close()
#     except FileNotFoundError:
#         print('Warning, file ' + filename + ' not found!')
#         if must_exist:
#             raise
#         return None
# 
#     return retval


import networkx as nx
import os
import pygit2
import sys
from argparse import ArgumentParser
from collections import defaultdict, Counter
from csv import writer
from itertools import combinations
from logging import getLogger
from multiprocessing import Pool, cpu_count
from subprocess import call
from pypasta.MAINTAINERS import MAINTAINERS
from pypasta.Util import file_to_string
                             'line of FILTER must contain the revision. '
                             'All files of the revision will be '
                             'considered if --filter is not specified.')
    parser.add_argument('--group-by', type=str, default='sections',
                        choices={'files', 'maintainers', 'sections'},
                        help='(only used in combination with --mode stats) '
                             'files: option shows all sections that are '
                             'assigned to the input files. '
                             'sections: option groups files by sections and '
                             'displays sections ordered by their size (LoC). '
                             'maintainers: option groups files by '
                             'maintainers and shows each maintainer '
                             'ordered by the LoC they are responsible for. '
                             'Default: %(default)s')
    parser.add_argument('--revision', type=str, help='Specify a commit hash or '
                        'a version name for a Linux repo')
    parser.add_argument('--mode', type=str, default='stats',
                        choices={'stats', 'graph'},
                        help='stats: dump stats to a csv-file. '
                             'graph: generate a csv-file that serves as a basis for a graph. '
                             'Default: %(default)s')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Verbose mode.')

    args = parser.parse_args(argv)

    repo = config.repo

    revision = 'HEAD'
    filter_by_files = list()
    if args.filter:

# Path: pypasta/MAINTAINERS.py
# class MAINTAINERS:
#     def get_sections_by_files(self, filenames):
#         sections = set()
#         for file in filenames:
#             if file.startswith('linux/'):
#                 file = file[len('linux/'):]
#             sections |= self.get_sections_by_file(file)
# 
#         return sections
# 
#     def get_sections_by_file(self, filename):
#         sections = set()
#         for section in self.sections.values():
#             if section.match(filename):
#                 sections.add(section.description)
#         return sections
# 
#     def get_maintainers(self, section):
#         return self.sections[section].get_maintainers()
# 
#     def __getitem__(self, item):
#         return self.sections[item]
# 
#     def __init__(self, d_cluster, project_name, repo, revision):
#         maintainers = repo.get_blob(revision, 'MAINTAINERS')
#         try:
#             maintainers = maintainers.decode('utf-8')
#         except:
#             # older versions use ISO8859
#             maintainers = maintainers.decode('iso8859')
# 
#         maintainers = maintainers.splitlines()
# 
#         if project_name in _prepare_maintainers:
#             maintainers = _prepare_maintainers[project_name](maintainers)
#         else:
#             raise NotImplementedError(
#                 'No MAINTAINERS implementation for project' % project_name)
# 
#         self.sections = dict()
# 
#         def add_section(content):
#             section = Section(repo, revision, content)
#             self.sections[section.description] = section
# 
#         tmp = list()
#         for line in maintainers:
#             if len(line.strip()) == 0:
#                 if len(tmp):
#                     add_section(tmp)
#                 tmp = list()
#             else:
#                 tmp.append(line)
#         add_section(tmp)
# 
#         f_maintainers_cluster = os.path.join(d_cluster, '%s.txt' % revision)
#         self.cluster = None
#         if os.path.exists(f_maintainers_cluster):
#             with open(f_maintainers_cluster, 'r') as f:
#                 cluster = f.read()
#             cluster = list(filter(None, cluster.split('\n\n')))
#             self.cluster = [set(x.split('\n')) for x in cluster]
#         else:
#             log.warning('No MAINTAINERS cluster for %s' % revision)
# 
# Path: pypasta/Util.py
# def file_to_string(filename, must_exist=True):
#     try:
#         # I HATE ENCONDING!
#         # Anyway, opening a file as binary and decoding it to iso8859 solves the problem :-)
#         with open(filename, 'rb') as f:
#             retval = str(f.read().decode('iso8859'))
#             f.close()
#     except FileNotFoundError:
#         print('Warning, file ' + filename + ' not found!')
#         if must_exist:
#             raise
#         return None
# 
#     return retval


# Path: bin/pasta_maintainers_stats.py
import networkx as nx
import os
import pygit2
import sys
from argparse import ArgumentParser
from collections import defaultdict, Counter
from csv import writer
from itertools import combinations
from logging import getLogger
from multiprocessing import Pool, cpu_count
from subprocess import call
from pypasta.MAINTAINERS import MAINTAINERS
from pypasta.Util import file_to_string

                             'line of FILTER must contain the revision. '
                             'All files of the revision will be '
                             'considered if --filter is not specified.')
    parser.add_argument('--group-by', type=str, default='sections',
                        choices={'files', 'maintainers', 'sections'},
                        help='(only used in combination with --mode stats) '
                             'files: option shows all sections that are '
                             'assigned to the input files. '
                             'sections: option groups files by sections and '
                             'displays sections ordered by their size (LoC). '
                             'maintainers: option groups files by '
                             'maintainers and shows each maintainer '
                             'ordered by the LoC they are responsible for. '
                             'Default: %(default)s')
    parser.add_argument('--revision', type=str, help='Specify a commit hash or '
                        'a version name for a Linux repo')
    parser.add_argument('--mode', type=str, default='stats',
                        choices={'stats', 'graph'},
                        help='stats: dump stats to a csv-file. '
                             'graph: generate a csv-file that serves as a basis for a graph. '
                             'Default: %(default)s')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Verbose mode.')

    args = parser.parse_args(argv)

    repo = config.repo

    revision = 'HEAD'
    filter_by_files = list()
    if args.filter:

        filter_by_files = file_to_string(args.filter).splitlines()