# Path: os_brick/initiator/connector.py
# LOG = logging.getLogger(__name__)
# def _get_connector_list():
# def _set_aliases():
# def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath,
#                              host=None, execute=None):
# def get_connector_mapping(arch=None):
#     def factory(protocol, root_helper, driver=None,
#                 use_multipath=False,
#                 device_scan_attempts=initiator.DEVICE_SCAN_ATTEMPTS_DEFAULT,
#                 arch=None,
#                 *args, **kwargs):
# class InitiatorConnector(object):


import argparse
import inspect
import json
import operator
import os
import textwrap
from pydoc import locate
from os_brick.initiator import connector

parser.add_argument("--format", default='str', choices=['str', 'dict'],
                    help="Output format type")

# Keep backwards compatibilty with the gate-docs test
# The tests pass ['docs'] on the cmdln, but it's never been used.
parser.add_argument("output_list", default=None, nargs='?')


def _ensure_loaded(connector_list):
    """Loads everything in a given path.

    This will make sure all classes have been loaded and therefore all
    decorators have registered class.

    :param start_path: The starting path to load.
    """
    classes = []
    for conn in connector_list:
        try:
            conn_class = locate(conn)
            classes.append(conn_class)
        except Exception:
            pass

    return classes


def get_connectors():
    """Get a list of all connectors."""

# Path: os_brick/initiator/connector.py
# LOG = logging.getLogger(__name__)
# def _get_connector_list():
# def _set_aliases():
# def get_connector_properties(root_helper, my_ip, multipath, enforce_multipath,
#                              host=None, execute=None):
# def get_connector_mapping(arch=None):
#     def factory(protocol, root_helper, driver=None,
#                 use_multipath=False,
#                 device_scan_attempts=initiator.DEVICE_SCAN_ATTEMPTS_DEFAULT,
#                 arch=None,
#                 *args, **kwargs):
# class InitiatorConnector(object):


# Path: tools/generate_connector_list.py
import argparse
import inspect
import json
import operator
import os
import textwrap
from pydoc import locate
from os_brick.initiator import connector


parser.add_argument("--format", default='str', choices=['str', 'dict'],
                    help="Output format type")

# Keep backwards compatibilty with the gate-docs test
# The tests pass ['docs'] on the cmdln, but it's never been used.
parser.add_argument("output_list", default=None, nargs='?')


def _ensure_loaded(connector_list):
    """Loads everything in a given path.

    This will make sure all classes have been loaded and therefore all
    decorators have registered class.

    :param start_path: The starting path to load.
    """
    classes = []
    for conn in connector_list:
        try:
            conn_class = locate(conn)
            classes.append(conn_class)
        except Exception:
            pass

    return classes


def get_connectors():
    """Get a list of all connectors."""

    classes = _ensure_loaded(connector._get_connector_list())