# Path: vcstool/crawler.py
# def find_repositories(paths, nested=False):
#     repos = []
#     visited = []
#     for path in paths:
#         _find_repositories(path, repos, visited, nested=nested)
#     return repos
# 
# Path: vcstool/executor.py
# def execute_jobs(
#     jobs, show_progress=False, number_of_workers=10, debug_jobs=False
# ):
#     global windows_force_posix
#     from vcstool.streams import stdout
#     if debug_jobs:
#         logger.setLevel(logging.DEBUG)
# 
#     if windows_force_posix:
#         logger.debug('force POSIX paths on Windows')
# 
#     results = []
# 
#     job_queue = Queue()
#     result_queue = Queue()
# 
#     # create worker threads
#     workers = []
#     for _ in range(min(number_of_workers, len(jobs))):
#         worker = Worker(job_queue, result_queue)
#         workers.append(worker)
# 
#     # fill job_queue with jobs for each worker
#     pending_jobs = list(jobs)
#     running_job_paths = []
#     while job_queue.qsize() < len(workers):
#         job = get_ready_job(pending_jobs)
#         if not job:
#             break
#         running_job_paths.append(job['client'].path)
#         logger.debug("started '%s'" % job['client'].path)
#         job_queue.put(job)
#     logger.debug('ongoing %s' % running_job_paths)
# 
#     # start all workers
#     [w.start() for w in workers]
# 
#     # collect results
#     while len(results) < len(jobs):
#         (job, result) = result_queue.get()
#         logger.debug("finished '%s'" % job['client'].path)
#         running_job_paths.remove(result['job']['client'].path)
#         if show_progress and len(jobs) > 1:
#             if result['returncode'] == NotImplemented:
#                 stdout.write('s')
#             elif result['returncode']:
#                 stdout.write('E')
#             else:
#                 stdout.write('.')
#             if debug_jobs:
#                 stdout.write('\n')
#             stdout.flush()
#         result.update(job)
#         results.append(result)
#         if pending_jobs:
#             for pending_job in pending_jobs:
#                 pending_job.get('depends', set()).discard(job['client'].path)
#             while job_queue.qsize() < len(workers):
#                 job = get_ready_job(pending_jobs)
#                 if not job:
#                     break
#                 running_job_paths.append(job['client'].path)
#                 logger.debug("started '%s'" % job['client'].path)
#                 job_queue.put(job)
#             assert running_job_paths
#         if running_job_paths:
#             logger.debug('ongoing ' + str(running_job_paths))
#     if show_progress and len(jobs) > 1 and not debug_jobs:
#         print('', file=stdout)  # finish progress line
# 
#     # join all workers
#     for w in workers:
#         w.done = True
#     [w.join() for w in workers]
#     return results
# 
# Path: vcstool/executor.py
# def generate_jobs(clients, command):
#     jobs = []
#     realpaths = {}
#     for client in clients:
#         # check if client is a duplicate of another path
#         realpath = os.path.realpath(client.path)
#         if realpath not in realpaths:
#             realpaths[realpath] = [client.path]
#         else:
#             # override command on client to ignore multiple invocations
#             # on same repository
#             duplicate_path = realpaths[realpath][0]
#             realpaths[realpath].append(client.path)
#             method_name = command.__class__.command
#             method = getattr(client, method_name, None)
#             if method is not None:
#                 setattr(client, method_name, DuplicateCommandHandler(
#                     client, duplicate_path))
# 
#         job = {'client': client, 'command': command}
#         jobs.append(job)
#     return jobs
# 
# Path: vcstool/executor.py
# def output_repositories(clients):
#     from vcstool.streams import stdout
#     ordered_clients = {client.path: client for client in clients}
#     for k in sorted(ordered_clients.keys()):
#         client = ordered_clients[k]
#         print(
#             '%s (%s)' % (fix_output_path(k), client.__class__.type),
#             file=stdout)
# 
# Path: vcstool/executor.py
# def output_results(results, output_handler=output_result, hide_empty=False):
#     # output results in alphabetic order
#     path_to_idx = {
#         result['client'].path: i for i, result in enumerate(results)}
#     idxs_in_order = [path_to_idx[path] for path in sorted(path_to_idx.keys())]
#     for i in idxs_in_order:
#         output_handler(results[i], hide_empty=hide_empty)


import argparse
import os
from multiprocessing import cpu_count
from vcstool.crawler import find_repositories
from vcstool.executor import execute_jobs
from vcstool.executor import generate_jobs
from vcstool.executor import output_repositories
from vcstool.executor import output_results
    try:
        value = int(value)
    except ValueError:
        raise argparse.ArgumentTypeError("invalid int value: '%s'" % value)
    if value <= 0:
        raise argparse.ArgumentTypeError(
            "invalid positive int value: '%d'" % value)
    return value


def add_common_arguments(
    parser, skip_hide_empty=False, skip_nested=False, path_nargs='*',
    path_help=None
):
    parser.formatter_class = argparse.ArgumentDefaultsHelpFormatter
    group = parser.add_argument_group('Common parameters')
    group.add_argument(
        '--debug', action='store_true', default=False,
        help='Show debug messages')
    if not skip_hide_empty:
        group.add_argument(
            '-s', '--hide-empty', '--skip-empty', action='store_true',
            default=False, help='Hide repositories with empty output')
    if not skip_nested:
        group.add_argument(
            '-n', '--nested', action='store_true',
            default=False, help='Search for nested repositories')
    try:
        default_workers = cpu_count()
    except NotImplementedError:

# Path: vcstool/crawler.py
# def find_repositories(paths, nested=False):
#     repos = []
#     visited = []
#     for path in paths:
#         _find_repositories(path, repos, visited, nested=nested)
#     return repos
# 
# Path: vcstool/executor.py
# def execute_jobs(
#     jobs, show_progress=False, number_of_workers=10, debug_jobs=False
# ):
#     global windows_force_posix
#     from vcstool.streams import stdout
#     if debug_jobs:
#         logger.setLevel(logging.DEBUG)
# 
#     if windows_force_posix:
#         logger.debug('force POSIX paths on Windows')
# 
#     results = []
# 
#     job_queue = Queue()
#     result_queue = Queue()
# 
#     # create worker threads
#     workers = []
#     for _ in range(min(number_of_workers, len(jobs))):
#         worker = Worker(job_queue, result_queue)
#         workers.append(worker)
# 
#     # fill job_queue with jobs for each worker
#     pending_jobs = list(jobs)
#     running_job_paths = []
#     while job_queue.qsize() < len(workers):
#         job = get_ready_job(pending_jobs)
#         if not job:
#             break
#         running_job_paths.append(job['client'].path)
#         logger.debug("started '%s'" % job['client'].path)
#         job_queue.put(job)
#     logger.debug('ongoing %s' % running_job_paths)
# 
#     # start all workers
#     [w.start() for w in workers]
# 
#     # collect results
#     while len(results) < len(jobs):
#         (job, result) = result_queue.get()
#         logger.debug("finished '%s'" % job['client'].path)
#         running_job_paths.remove(result['job']['client'].path)
#         if show_progress and len(jobs) > 1:
#             if result['returncode'] == NotImplemented:
#                 stdout.write('s')
#             elif result['returncode']:
#                 stdout.write('E')
#             else:
#                 stdout.write('.')
#             if debug_jobs:
#                 stdout.write('\n')
#             stdout.flush()
#         result.update(job)
#         results.append(result)
#         if pending_jobs:
#             for pending_job in pending_jobs:
#                 pending_job.get('depends', set()).discard(job['client'].path)
#             while job_queue.qsize() < len(workers):
#                 job = get_ready_job(pending_jobs)
#                 if not job:
#                     break
#                 running_job_paths.append(job['client'].path)
#                 logger.debug("started '%s'" % job['client'].path)
#                 job_queue.put(job)
#             assert running_job_paths
#         if running_job_paths:
#             logger.debug('ongoing ' + str(running_job_paths))
#     if show_progress and len(jobs) > 1 and not debug_jobs:
#         print('', file=stdout)  # finish progress line
# 
#     # join all workers
#     for w in workers:
#         w.done = True
#     [w.join() for w in workers]
#     return results
# 
# Path: vcstool/executor.py
# def generate_jobs(clients, command):
#     jobs = []
#     realpaths = {}
#     for client in clients:
#         # check if client is a duplicate of another path
#         realpath = os.path.realpath(client.path)
#         if realpath not in realpaths:
#             realpaths[realpath] = [client.path]
#         else:
#             # override command on client to ignore multiple invocations
#             # on same repository
#             duplicate_path = realpaths[realpath][0]
#             realpaths[realpath].append(client.path)
#             method_name = command.__class__.command
#             method = getattr(client, method_name, None)
#             if method is not None:
#                 setattr(client, method_name, DuplicateCommandHandler(
#                     client, duplicate_path))
# 
#         job = {'client': client, 'command': command}
#         jobs.append(job)
#     return jobs
# 
# Path: vcstool/executor.py
# def output_repositories(clients):
#     from vcstool.streams import stdout
#     ordered_clients = {client.path: client for client in clients}
#     for k in sorted(ordered_clients.keys()):
#         client = ordered_clients[k]
#         print(
#             '%s (%s)' % (fix_output_path(k), client.__class__.type),
#             file=stdout)
# 
# Path: vcstool/executor.py
# def output_results(results, output_handler=output_result, hide_empty=False):
#     # output results in alphabetic order
#     path_to_idx = {
#         result['client'].path: i for i, result in enumerate(results)}
#     idxs_in_order = [path_to_idx[path] for path in sorted(path_to_idx.keys())]
#     for i in idxs_in_order:
#         output_handler(results[i], hide_empty=hide_empty)


# Path: vcstool/commands/command.py
import argparse
import os
from multiprocessing import cpu_count
from vcstool.crawler import find_repositories
from vcstool.executor import execute_jobs
from vcstool.executor import generate_jobs
from vcstool.executor import output_repositories
from vcstool.executor import output_results

    try:
        value = int(value)
    except ValueError:
        raise argparse.ArgumentTypeError("invalid int value: '%s'" % value)
    if value <= 0:
        raise argparse.ArgumentTypeError(
            "invalid positive int value: '%d'" % value)
    return value


def add_common_arguments(
    parser, skip_hide_empty=False, skip_nested=False, path_nargs='*',
    path_help=None
):
    parser.formatter_class = argparse.ArgumentDefaultsHelpFormatter
    group = parser.add_argument_group('Common parameters')
    group.add_argument(
        '--debug', action='store_true', default=False,
        help='Show debug messages')
    if not skip_hide_empty:
        group.add_argument(
            '-s', '--hide-empty', '--skip-empty', action='store_true',
            default=False, help='Hide repositories with empty output')
    if not skip_nested:
        group.add_argument(
            '-n', '--nested', action='store_true',
            default=False, help='Search for nested repositories')
    try:
        default_workers = cpu_count()
    except NotImplementedError:

        default_workers = 4