Detect from a list of files which are TeX or images.

    :param: file_list (list): list of absolute file paths
    :param: allowed_image_types (list): list of allows image formats
    :param: timeout (int): the timeout value on shell commands.

    :return: (image_list, tex_file) (([string, string, ...], string)):
        list of images in the tarball and the name of the TeX file in the
        tarball.

def detect_images_and_tex(
        file_list,
        allowed_image_types=('eps', 'png', 'ps', 'jpg', 'pdf'),
        timeout=20):
    """Detect from a list of files which are TeX or images.

    :param: file_list (list): list of absolute file paths
    :param: allowed_image_types (list): list of allows image formats
    :param: timeout (int): the timeout value on shell commands.

    :return: (image_list, tex_file) (([string, string, ...], string)):
        list of images in the tarball and the name of the TeX file in the
        tarball.
    """
    tex_file_extension = 'tex'

    image_list = []
    might_be_tex = []

    for extracted_file in file_list:
        # Ignore directories and hidden (metadata) files
        if os.path.isdir(extracted_file) \
           or os.path.basename(extracted_file).startswith('.'):
            continue

        magic_str = magic.from_file(extracted_file, mime=True)

        if magic_str == "application/x-tex":
            might_be_tex.append(extracted_file)
        elif magic_str.startswith('image/') \
                or magic_str == "application/postscript":
            image_list.append(extracted_file)

        # If neither, maybe it is TeX or an image anyway, otherwise,
        # we don't care.
        else:
            _, dotted_file_extension = os.path.splitext(extracted_file)
            file_extension = dotted_file_extension[1:]

            if file_extension == tex_file_extension:
                might_be_tex.append(extracted_file)
            elif file_extension in allowed_image_types:
                image_list.append(extracted_file)

    return image_list, might_be_tex