# Path: openelex/tasks/utils.py
# def load_module(state, mod_list=[]):
#     """Dynamically load modules for states
# 
#     USAGE
# 
#        mod = load_module(state, ['datasource', 'loader'])
#        mod.datasource.Datasource()
# 
#     """
#     return __import__('openelex.us.%s' % state.lower(), fromlist=mod_list)
# 
# def split_args(raw_args, separator=','):
#     """Helper for parsing command-line options"""
#     return [func_name.strip() for func_name in raw_args.split(separator)]


import sys
import click
from collections import OrderedDict
from .utils import load_module, split_args
            print(out + "\n")

@click.command(name='validate.run', help="Run data validations for state")
@click.option('--state', required=True, help="Two-letter state-abbreviation, e.g. NY")
@click.option('--include', help="Validations to run (comma-separated list)")
@click.option('--exclude', help="Validations to skip (comma-separated list)")
def run(state, include=None, exclude=None):
    """
    Run data validations for state.

    State is required. Optionally filter validations using include/exclude flags.
    """
    if include and exclude:
        sys.exit("ERROR: You can not use both include and exclude flags!")

    state_mod = load_module(state, ['validate'])
    # Load all validations in order found
    validations = OrderedDict()
    for name in dir(state_mod.validate):
        if name.startswith('validate_'):
            func = getattr(state_mod.validate, name)
            validations[name] = func

    # Filter validations based in include/exclude flags
    if include:
        to_run = split_args(include)
        for val in validations:
            if val not in to_run:
                validations.pop(val)
    if exclude:

# Path: openelex/tasks/utils.py
# def load_module(state, mod_list=[]):
#     """Dynamically load modules for states
# 
#     USAGE
# 
#        mod = load_module(state, ['datasource', 'loader'])
#        mod.datasource.Datasource()
# 
#     """
#     return __import__('openelex.us.%s' % state.lower(), fromlist=mod_list)
# 
# def split_args(raw_args, separator=','):
#     """Helper for parsing command-line options"""
#     return [func_name.strip() for func_name in raw_args.split(separator)]


# Path: openelex/tasks/validate.py
import sys
import click
from collections import OrderedDict
from .utils import load_module, split_args

            print(out + "\n")

@click.command(name='validate.run', help="Run data validations for state")
@click.option('--state', required=True, help="Two-letter state-abbreviation, e.g. NY")
@click.option('--include', help="Validations to run (comma-separated list)")
@click.option('--exclude', help="Validations to skip (comma-separated list)")
def run(state, include=None, exclude=None):
    """
    Run data validations for state.

    State is required. Optionally filter validations using include/exclude flags.
    """
    if include and exclude:
        sys.exit("ERROR: You can not use both include and exclude flags!")

    state_mod = load_module(state, ['validate'])
    # Load all validations in order found
    validations = OrderedDict()
    for name in dir(state_mod.validate):
        if name.startswith('validate_'):
            func = getattr(state_mod.validate, name)
            validations[name] = func

    # Filter validations based in include/exclude flags
    if include:
        to_run = split_args(include)
        for val in validations:
            if val not in to_run:
                validations.pop(val)
    if exclude:

        to_skip = split_args(exclude)