commit 6d3be39587c83590d2d8e91b1fe93261593a2b25
Author: Thibaut Cuvelier <[email protected]>
Date:   Mon Sep 27 01:15:16 2021 +0200

    DocBook copy: don't error if the file was already copied.
---
 autotests/export/docbook/LilyPond_Book.xml |   14 ++++++++------
 lib/scripts/docbook_copy.py                |   14 +++++++++++---
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/autotests/export/docbook/LilyPond_Book.xml 
b/autotests/export/docbook/LilyPond_Book.xml
index 109e112..43df8e1 100644
--- a/autotests/export/docbook/LilyPond_Book.xml
+++ b/autotests/export/docbook/LilyPond_Book.xml
@@ -3,11 +3,13 @@
   See https://www.lyx.org/ for more information -->
 <article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:m="http://www.w3.org/1998/Math/MathML"; 
xmlns:xi="http://www.w3.org/2001/XInclude"; version="5.2">
 <title>LilyPond-book and LyX</title>
-<mediaobject>
-<textobject>
-<programlisting language='lilypond' role='fragment verbatim staffsize=16 
ragged-right relative=2'>
+<programlisting>
+
 \relative c'' {  g a b c}
-</programlisting>
-</textobject>
-</mediaobject>
+</programlisting><mediaobject><imageobject role="latex">
+  <imagedata fileref="ff\lily-3ed27d76.pdf" format="PDF"/>
+</imageobject>
+<imageobject role="html">
+  <imagedata fileref="ff\lily-3ed27d76.png" format="PNG"/>
+</imageobject></mediaobject>
 </article>
\ No newline at end of file
diff --git a/lib/scripts/docbook_copy.py b/lib/scripts/docbook_copy.py
index 044c3e1..7cb68dc 100644
--- a/lib/scripts/docbook_copy.py
+++ b/lib/scripts/docbook_copy.py
@@ -77,8 +77,14 @@ class DocBookCopier:
         os.unlink(self.in_file)
 
     def postprocess_output_for_lilypond(self):
-        # TODO.
         pass
+        # # Erase the <programlisting> that LilyPond left behind in the XML.
+        # in_file_before = self.in_file + '.tmp'
+        # shutil.move(self.in_file, in_file_before)
+        # with open(in_file_before, 'r', encoding='utf-8') as f_before, 
open(self.in_file, 'w', encoding='utf-8') as f_after:
+        #     looking_for_end_programlisting = False
+        #     for line in f_before:
+        #         # TODO: find an efficient way to distinguish those 
left-overs.
 
     def call_lilypond(self):
         # LilyPond requires that its input file has the .lyxml extension (plus 
bugs in LilyPond).
@@ -125,17 +131,19 @@ class DocBookCopier:
         if failed:
             sys.exit(1)
 
-        # Now, in_file should have the LilyPond-processed contents.
         # LilyPond has a distressing tendency to leave the raw LilyPond code 
in the new file.
         self.postprocess_output_for_lilypond()
 
+        # Now, in_file should have the clean LilyPond-processed contents.
+
     def copy_lilypond_generated_images(self):
         # LilyPond generates a lot of files in LyX' temporary folder, within 
the ff folder: source LilyPond files
         # for each snippet to render, images in several formats.
         in_generated_images_folder = os.path.join(self.in_folder, 'ff')
         out_generated_images_folder = os.path.join(self.out_folder, 'ff')
 
-        os.mkdir(out_generated_images_folder)
+        if not os.path.isdir(out_generated_images_folder):
+            os.mkdir(out_generated_images_folder)
 
         for img in os.listdir(in_generated_images_folder):
             if not img.endswith('.png') and not img.endswith('.pdf'):
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to