# Path: ob2/util/hooks.py
# def apply_filters(name, value, *args):
#     """
#     Applies all filters registered under NAME to VALUE.
# 
#     """
#     for _, hook in _HOOKS_FILTERS[name]:
#         value = hook(value, *args)
#     return value
# 
# def get_job(name):
#     """
#     Returns the job handler registered for NAME. If no job handler is registered, raises KeyError.
#     This function should only be used by ob2.dockergrader.worker.
# 
#     """
#     return _HOOKS_JOBS[name]


import re
import ob2.config as config
from glob import glob
from ob2.util.hooks import apply_filters, get_job
def get_assignment_by_name(name, default=None):
    global _assignment_by_name
    if _assignment_by_name is None:
        _assignment_by_name = {assignment.name: assignment
                               for assignment in config.assignments}
    return _assignment_by_name[name]


def get_repo_type(repo_name):
    """
    Returns either "group" or "personal", depending on what repo_name appears to be. If repo is
    unidentifiable, return None.

    """
    if re.match(r'^group\d+$', repo_name):
        repo_type = "group"
    elif re.match(r'^[a-z]{2,3}$', repo_name):
        repo_type = "personal"
    else:
        repo_type = None

    # This is a useful hook to change how repos are classified, based on their name. The default is
    # pretty good, but you may have extra repos that don't exactly follow this naming scheme.
    #
    # Arguments:
    #   repo_type -- The original guess for the repo_type (see code above)
    #   repo_name -- The name of the repo (e.g. "aa" or "group1")
    #
    # Returns:
    #   Either "group" or "personal"

# Path: ob2/util/hooks.py
# def apply_filters(name, value, *args):
#     """
#     Applies all filters registered under NAME to VALUE.
# 
#     """
#     for _, hook in _HOOKS_FILTERS[name]:
#         value = hook(value, *args)
#     return value
# 
# def get_job(name):
#     """
#     Returns the job handler registered for NAME. If no job handler is registered, raises KeyError.
#     This function should only be used by ob2.dockergrader.worker.
# 
#     """
#     return _HOOKS_JOBS[name]


# Path: ob2/util/config_data.py
import re
import ob2.config as config
from glob import glob
from ob2.util.hooks import apply_filters, get_job

def get_assignment_by_name(name, default=None):
    global _assignment_by_name
    if _assignment_by_name is None:
        _assignment_by_name = {assignment.name: assignment
                               for assignment in config.assignments}
    return _assignment_by_name[name]


def get_repo_type(repo_name):
    """
    Returns either "group" or "personal", depending on what repo_name appears to be. If repo is
    unidentifiable, return None.

    """
    if re.match(r'^group\d+$', repo_name):
        repo_type = "group"
    elif re.match(r'^[a-z]{2,3}$', repo_name):
        repo_type = "personal"
    else:
        repo_type = None

    # This is a useful hook to change how repos are classified, based on their name. The default is
    # pretty good, but you may have extra repos that don't exactly follow this naming scheme.
    #
    # Arguments:
    #   repo_type -- The original guess for the repo_type (see code above)
    #   repo_name -- The name of the repo (e.g. "aa" or "group1")
    #
    # Returns:
    #   Either "group" or "personal"

    repo_type = apply_filters("get-repo-type", repo_type, repo_name)