algoo / preview-generator

generates previews of files with cache management
https://pypi.org/project/preview-generator/
MIT License
228 stars 51 forks source link

tests/input/txt/test_txt.py test_text_to_jpeg fail with wand and imconvert backend. #118

Closed JulienPalard closed 2 years ago

JulienPalard commented 4 years ago

Related to #113 (read first).

Wand and imconvert are telling they support plain text, but it looks like they don't.

I'm getting:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    def test_text_to_jpeg() -> None:
        manager = PreviewManager(cache_folder_path=CACHE_DIR, create_folder=True)
        image_file_path = IMAGE_FILE_PATH
        assert manager.has_jpeg_preview(file_path=image_file_path) is True
>       path_to_file = manager.get_jpeg_preview(file_path=image_file_path, force=True)

tests/input/txt/test_txt.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
preview_generator/manager.py:169: in get_jpeg_preview
    builder.build_jpeg_preview(
preview_generator/preview/builder/image__imconvert.py:100: in build_jpeg_preview
    build_png_result_code = check_call(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

popenargs = (['convert', '/home/mdk/clones/preview-generator/tests/input/txt/the_text.txt', '-layers', 'merge', '/tmp/61d29d63-c745-4b64-bdfa-be883fd1d411.png'],)
kwargs = {'stderr': -2, 'stdout': -3}, retcode = 1
cmd = ['convert', '/home/mdk/clones/preview-generator/tests/input/txt/the_text.txt', '-layers', 'merge', '/tmp/61d29d63-c745-4b64-bdfa-be883fd1d411.png']

    def check_call(*popenargs, **kwargs):
        """Run command with arguments.  Wait for command to complete.  If
        the exit code was zero then return, otherwise raise
        CalledProcessError.  The CalledProcessError object will have the
        return code in the returncode attribute.

        The arguments are the same as for the call function.  Example:

        check_call(["ls", "-l"])
        """
        retcode = call(*popenargs, **kwargs)
        if retcode:
            cmd = kwargs.get("args")
            if cmd is None:
                cmd = popenargs[0]
>           raise CalledProcessError(retcode, cmd)
E           subprocess.CalledProcessError: Command '['convert', '/home/mdk/clones/preview-generator/tests/input/txt/the_text.txt', '-layers', 'merge', '/tmp/61d29d63-c745-4b64-bdfa-be883fd1d411.png']' returned non-zero exit status 1.

../../.local/lib/python3.8/subprocess.py:364: CalledProcessError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /home/mdk/.local/lib/python3.8/subprocess.py(364)check_call()
-> raise CalledProcessError(retcode, cmd)
inkhey commented 4 years ago

@JulienPalard Look like part of the problem is related to imagemagick lib tel it support txt file, pdf, and other non-image type but cannot handle them properly.

We may think about making those builder be able to handle those type of file, but as we have clearly better builder for those mimetype, i don't think it's really useful (we may have many bug like encrypted pdf, etc...).

So i suggest first, to fix supported mimetype list by imagemagick by removing non-image type that can't be processed same way as other (although imagemagick support them at some point).

inkhey commented 4 years ago

created a pr with idea exposed here #153

inkhey commented 2 years ago

As imconvert backend is deprecated in favor of wand, we will not solve theses issues.