[LyX/master] ePub: copy images into the ePub archive.

Stephan Witt st.witt at gmx.net
Mon Feb 8 07:25:28 UTC 2021


Am 08.02.2021 um 06:42 schrieb Thibaut Cuvelier <tcuvelier at lyx.org>:
> 
> On Mon, 8 Feb 2021 at 00:56, Stephan Witt <st.witt at gmx.net> wrote:
> Hi Thibaut,
> 
> sorry for having python 2.7 on Mac…
> 
> It's not like you have a choice there :)!

…

> 
> I had to add
> 
> "from io import open"
> 
> to docbook2epub.py (patch attached).
> 
> I've pushed this patch, it does not seem to cause problems elsewhere at least.

Thanks.
 
> Next problem is the image path of the referenced clipart „Fussnote.png“:
> 
> 00:52:28.850: Exportiere ...
> 00:52:28.855: (buffer-export epub)
> 00:52:28.981: python "/Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/docbook2epub.py" none none "xsltproc" none "Intro.xml" "Intro.epub"
> 00:52:29.188: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/ar01-toc.xhtml for article
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/ar01s02.xhtml for section
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/ar01s03.xhtml for section(sec.Helfen)
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/index.xhtml for article
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/docbook-epub.css for article
> 00:52:29.292: Generating EPUB package files.
> 00:52:29.292: Generating image list ...
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/package.opf for article
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/../META-INF/container.xml for article
> 00:52:29.292: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/../mimetype for article
> 00:52:29.293: Generating NCX file ...
> 00:52:29.293: Writing /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ/OEBPS/toc.ncx for article
> 00:52:29.397: Generating ePub with the following parameters:
> 00:52:29.397: /Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/docbook2epub.py
> 00:52:29.397: None
> 00:52:29.397: None
> 00:52:29.397: xsltproc
> 00:52:29.397: None
> 00:52:29.397: Intro.xml
> 00:52:29.398: Intro.epub
> 00:52:29.398: Temporary output directory: /var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ
> 00:52:29.398: XSLT style sheet to use:
> 00:52:29.398: /Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/../docbook/epub3/chunk.xsl
> 00:52:29.398: Command to execute:
> 00:52:29.398: "xsltproc" -stringparam base.dir "/var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ" "/Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/../docbook/epub3/chunk.xsl" "In
> 00:52:29.399: tro.xml"
> 00:52:29.399: Generated ePub contents.
> 00:52:29.399: Traceback (most recent call last):
> 00:52:29.399:   File "/Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/docbook2epub.py", line 180, in <module>
> 00:52:29.399:     DocBookToEpub(sys.argv).transform()
> 00:52:29.399:   File "/Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/docbook2epub.py", line 175, in transform
> 00:52:29.399:     self.copy_images()
> 00:52:29.400:   File "/Users/stephan/git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/scripts/docbook2epub.py", line 161, in copy_images
> 00:52:29.400:     shutil.copyfile(old, self.output_dir + '/OEBPS/' + new)
> 00:52:29.400:   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 96, in copyfile
> 00:52:29.400:     with open(src, 'rb') as fsrc:
> 00:52:29.400: IOError: [Errno 2] No such file or directory: u'../../../git/lyx-build/LyX-2.4.0dev.app/Contents/Resources/doc/de/clipart/Fussnote.png’
> 
> Here I’m clueless.
> 
> That one is trickier… Just to be sure: you tried to convert the German introduction, is that right? I can get an ePub with Fussnote.png on Windows, so there must be something platform-dependent.

Yes. It’s the German Intro bundled with the package. The directory doc/de contains the Intro.lyx and there is the reference to the image clipart/Fussnote.png relative to the location of the LyX-file. The exported xml Intro.xml is somewhere outside the package and has the path to the image converted relative to that location. At this point the path is valid.

> In your temporary folder (/var/folders/y8/l_k5f2ms4rngwbwvt9jp53hw0000gt/T/tmpxYSbzQ in your example), what does OEBPS/package.opf look like before it is rewritten by docbook2epub.py?

Looks normal. There is a reference to the image.

    <item id="idm133279468352" href="images/Fussnote.png" media-type="image/png“/>

> You may want to comment out self.copy_images() in line 175. What is the path to Fussnote.png there? 

The image name entry from self.get_images_from_package_opf is relative to the Intro.xml - the current directory of the python script is not the same. IMO that’s the problem.

> Also: what is the actual path to Fussnote.png? 
> 
> I suppose this is due to the fact I assume that, originally, in package.opf, the paths are absolute. 

No, the path names are relative to the target directory.

Stephan


More information about the lyx-devel mailing list