# Path: memsql_loader/util/attr_dict.py
# class AttrDict(dict):
#     def __getattr__(self, key):
#         try:
#             return self.__getitem__(key)
#         except KeyError:
#             # This lets you use dict-type attributes that aren't keys
#             return getattr(super(AttrDict, self), key)
# 
#     def __setattr__(self, key, value):
#         return self.__setitem__(key, value)
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def __repr__(self):
#         return '%s(%s)' % (self.__class__.__name__, dict.__repr__(self))
# 
#     @staticmethod
#     def from_dict(source):
#         def _transform(d):
#             """ Turns a nested dict into nested AttrDict's """
#             for k, v in d.iteritems():
#                 if isinstance(v, dict):
#                     d[k] = _transform(v)
#             return AttrDict(d)
# 
#         return _transform(source)
# 
# Path: memsql_loader/util/log.py
# def setup(log_path=None, stdout_enabled=True):
# def update_verbosity(debug=False, extra_verbose=False):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
# def configure(parser):
# def get_logger(name, level=None):
#     def format(self, record):
#     def __init__(self, name, level=logging.DEBUG):
# class _SetDebug(argparse.Action):
# class _SetStdout(argparse.Action):
# class _SetLogPath(argparse.Action):
# class Formatter(logging.Formatter):
# class Logger(logging.Logger):


import os
import shlex
import urlparse
import voluptuous as V
from memsql_loader.util.attr_dict import AttrDict
from memsql_loader.util import log
from memsql_loader.vendor import glob2
        schema_path = ".".join(map(str, full_key_path))

        if isinstance(val, V.Schema):
            # Recurse on a subspec
            base_val = base_spec[key_s] if key_s in base_spec else {}
            newval = build_spec_recursive(logger, options, base_val, val, full_key_path)
        else:
            # Match it to a command line option (and assert that exactly one exists)
            cl_options = get_command_line_options(map(str, full_key_path))
            found = False
            for opt in cl_options:
                if hasattr(options, opt):
                    assert not found, "Multiple keys for path %s have options (%s)" % (schema_path, cl_options)
                    newval = getattr(options, opt)
                    set_command_line_mapping(full_key_path, opt)
                    found = True
            assert found, "No command line option for %s (%s)" % (schema_path, cl_options)

        if newval is not None:
            # this means that the user passed in an option that overrides the spec
            ret[key_s] = newval
        elif key_s in base_spec:
            ret[key_s] = base_spec[key_s]

    return ret

def build_spec(base_spec, options):
    # for each part in the base_spec, we expect one of two
    # things to be exposed in the options -> either the key name
    # itself or full-schema-path-to-keyname.

# Path: memsql_loader/util/attr_dict.py
# class AttrDict(dict):
#     def __getattr__(self, key):
#         try:
#             return self.__getitem__(key)
#         except KeyError:
#             # This lets you use dict-type attributes that aren't keys
#             return getattr(super(AttrDict, self), key)
# 
#     def __setattr__(self, key, value):
#         return self.__setitem__(key, value)
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     def __repr__(self):
#         return '%s(%s)' % (self.__class__.__name__, dict.__repr__(self))
# 
#     @staticmethod
#     def from_dict(source):
#         def _transform(d):
#             """ Turns a nested dict into nested AttrDict's """
#             for k, v in d.iteritems():
#                 if isinstance(v, dict):
#                     d[k] = _transform(v)
#             return AttrDict(d)
# 
#         return _transform(source)
# 
# Path: memsql_loader/util/log.py
# def setup(log_path=None, stdout_enabled=True):
# def update_verbosity(debug=False, extra_verbose=False):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
# def configure(parser):
# def get_logger(name, level=None):
#     def format(self, record):
#     def __init__(self, name, level=logging.DEBUG):
# class _SetDebug(argparse.Action):
# class _SetStdout(argparse.Action):
# class _SetLogPath(argparse.Action):
# class Formatter(logging.Formatter):
# class Logger(logging.Logger):


# Path: memsql_loader/util/schema.py
import os
import shlex
import urlparse
import voluptuous as V
from memsql_loader.util.attr_dict import AttrDict
from memsql_loader.util import log
from memsql_loader.vendor import glob2

        schema_path = ".".join(map(str, full_key_path))

        if isinstance(val, V.Schema):
            # Recurse on a subspec
            base_val = base_spec[key_s] if key_s in base_spec else {}
            newval = build_spec_recursive(logger, options, base_val, val, full_key_path)
        else:
            # Match it to a command line option (and assert that exactly one exists)
            cl_options = get_command_line_options(map(str, full_key_path))
            found = False
            for opt in cl_options:
                if hasattr(options, opt):
                    assert not found, "Multiple keys for path %s have options (%s)" % (schema_path, cl_options)
                    newval = getattr(options, opt)
                    set_command_line_mapping(full_key_path, opt)
                    found = True
            assert found, "No command line option for %s (%s)" % (schema_path, cl_options)

        if newval is not None:
            # this means that the user passed in an option that overrides the spec
            ret[key_s] = newval
        elif key_s in base_spec:
            ret[key_s] = base_spec[key_s]

    return ret

def build_spec(base_spec, options):
    # for each part in the base_spec, we expect one of two
    # things to be exposed in the options -> either the key name
    # itself or full-schema-path-to-keyname.

    logger = log.get_logger('Schema')