# Path: anchorhub/lib/bunch.py
# class Bunch(object):
#     """
#     Bunch - converts dictionaries into namespaces
#     """
#     def __init__(self, adict):
#         self.__dict__.update(adict)
# 
# Path: anchorhub/util/addsuffix.py
# def add_suffix(string, suffix):
#     """
#     Adds a suffix to a string, if the string does not already have that suffix.
# 
#     :param string: the string that should have a suffix added to it
#     :param suffix: the suffix to be added to the string
#     :return: the string with the suffix added, if it does not already end in
#         the suffix. Otherwise, it returns the original string.
#     """
#     if string[-len(suffix):] != suffix:
#         return string + suffix
#     else:
#         return string
# 
# Path: anchorhub/compatibility.py
# def get_path_separator():
#     """
#     Returns the appropriate file path separator depending on operating
#     system. That is, when run on UNIX-like systems it returns a forward slash
#     ('/'), and for Windows it returns a backslash ('\')
#     :return: String. The file path separator for the current operating system.
#     """
#     if os.name == 'nt':
#         return '\\'
#     else:
#         return '/'


import os.path as path
import re
from anchorhub.lib.bunch import Bunch
from anchorhub.util.addsuffix import add_suffix
from anchorhub.compatibility import get_path_separator


def normalize(opts):
    """
    Performs various normalization functions on opts, the provided namespace. It
    is assumed that opts has already been validated with
    anchorhub.validation_opts.validate().

    :param opts: a namespace containing options for AnchorHub
    :return: a namespace with the attributes modified
    """
    opts_dict = vars(opts)
    add_is_dir(opts_dict)
    ensure_directories_end_in_separator(opts_dict)
    add_abs_path_directories(opts_dict)
    add_open_close_wrappers(opts_dict)
    add_wrapper_regex(opts_dict)
    return Bunch(opts_dict)


def add_abs_path_directories(opts_dict):
    """
    Adds 'abs_input' and 'abs_output' to opts_dict

    :param opts_dict: dictionary that will be modified
    """
    assert_has_input_output(opts_dict)
    opts_dict['abs_input'] = path.abspath(opts_dict['input'])
    if opts_dict['is_dir']:
        # Only add path separator to input if it is a directory

# Path: anchorhub/lib/bunch.py
# class Bunch(object):
#     """
#     Bunch - converts dictionaries into namespaces
#     """
#     def __init__(self, adict):
#         self.__dict__.update(adict)
# 
# Path: anchorhub/util/addsuffix.py
# def add_suffix(string, suffix):
#     """
#     Adds a suffix to a string, if the string does not already have that suffix.
# 
#     :param string: the string that should have a suffix added to it
#     :param suffix: the suffix to be added to the string
#     :return: the string with the suffix added, if it does not already end in
#         the suffix. Otherwise, it returns the original string.
#     """
#     if string[-len(suffix):] != suffix:
#         return string + suffix
#     else:
#         return string
# 
# Path: anchorhub/compatibility.py
# def get_path_separator():
#     """
#     Returns the appropriate file path separator depending on operating
#     system. That is, when run on UNIX-like systems it returns a forward slash
#     ('/'), and for Windows it returns a backslash ('\')
#     :return: String. The file path separator for the current operating system.
#     """
#     if os.name == 'nt':
#         return '\\'
#     else:
#         return '/'


# Path: anchorhub/normalization/normalize_opts.py
import os.path as path
import re
from anchorhub.lib.bunch import Bunch
from anchorhub.util.addsuffix import add_suffix
from anchorhub.compatibility import get_path_separator



def normalize(opts):
    """
    Performs various normalization functions on opts, the provided namespace. It
    is assumed that opts has already been validated with
    anchorhub.validation_opts.validate().

    :param opts: a namespace containing options for AnchorHub
    :return: a namespace with the attributes modified
    """
    opts_dict = vars(opts)
    add_is_dir(opts_dict)
    ensure_directories_end_in_separator(opts_dict)
    add_abs_path_directories(opts_dict)
    add_open_close_wrappers(opts_dict)
    add_wrapper_regex(opts_dict)
    return Bunch(opts_dict)


def add_abs_path_directories(opts_dict):
    """
    Adds 'abs_input' and 'abs_output' to opts_dict

    :param opts_dict: dictionary that will be modified
    """
    assert_has_input_output(opts_dict)
    opts_dict['abs_input'] = path.abspath(opts_dict['input'])
    if opts_dict['is_dir']:
        # Only add path separator to input if it is a directory

        opts_dict['abs_input'] += get_path_separator()