#!/usr/bin/env python3
"""hos-utils utils module: Various utilities, wrappers etc."""

import os
import shutil

GZIP_MAGIC_NUMBER = b"\x1f\x8b"

def search_file(where, filename, extensions):
    """Search recursively for file in a path.

    Parameters
    ----------
    str : where
        The path where to search.
    str : filename
        The filename to search
    list(str) : extensions
        A list of possible extensions for the filename.

    Returns
    -------
    str
        Full path to the found file.

    Raises
    ------
    LookupError
        File not found.

    """
    for root, _, files in os.walk(where):
        for _file in files:
            for ext in extensions:
                if _file == filename + '.' + ext:
                    return os.path.join(root, _file)
    raise LookupError

def clean_dir(path):
    """Remove the content of a directory.

    Parameters
    ----------
    str : path
        The path to clean up.

    Returns
    -------
    None
    """
    for entry in os.listdir(path):
        entry_path = os.path.join(path, entry)
        if os.path.isfile(entry_path) or os.path.islink(entry_path):
            os.unlink(entry_path)
        elif os.path.isdir(entry_path):
            shutil.rmtree(entry_path)
