]> git.lyx.org Git - lyx.git/commitdiff
DocBook copy: don't error if the file was already copied.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sun, 26 Sep 2021 23:15:16 +0000 (01:15 +0200)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Sun, 26 Sep 2021 23:15:16 +0000 (01:15 +0200)
autotests/export/docbook/LilyPond_Book.xml
lib/scripts/docbook_copy.py

index 109e112ca1a3da4e31afc305b9855ae20b3e76e4..43df8e100fef64535076d46c251b3c19445e30d2 100644 (file)
@@ -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
index 044c3e15fee2249666d3278f60f9dabc74181852..7cb68dca43b05bdfa9c736f88a60acf3c999ad08 100644 (file)
@@ -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'):