]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/docbook2epub.py
GuiSearch: make search options visible/accessible in minimal mode
[lyx.git] / lib / scripts / docbook2epub.py
index 9836240913572b0c36d8bbe0aba167c6116282e2..89a2cb58ac562c176c5e304cd331c2a88735f9e4 100644 (file)
@@ -9,7 +9,7 @@
 # Full author contact details are available in file CREDITS
 
 # Usage:
-#   python docbook2epub.py java_binary in.docbook out.epub
+#   python docbook2epub.py java_binary saxon_path xsltproc_path xslt_path in.docbook out.epub
 
 from __future__ import print_function
 
@@ -19,6 +19,11 @@ import shutil
 import sys
 import tempfile
 import zipfile
+from io import open  # Required for Python 2.
+
+
+def _parse_nullable_argument(arg):
+    return arg if arg != '' and arg != 'none' else None
 
 
 class DocBookToEpub:
@@ -26,22 +31,25 @@ class DocBookToEpub:
         if args is None:
             args = sys.argv
 
-        if len(args) != 5:
-            print('Five arguments are expected, only %s found.' % len(sys.argv))
-            print(args)
+        if len(args) != 7:
+            print('Seven arguments are expected, only %s found: %s.' % (len(args), args))
             sys.exit(1)
 
         self.own_path = sys.argv[0]
-        self.java_path = sys.argv[1] if sys.argv[1] != '' and sys.argv[1] != 'none' else ''
-        self.xsltproc_path = sys.argv[2] if sys.argv[2] != '' and sys.argv[2] != 'none' else ''
-        self.input = sys.argv[3]
-        self.output = sys.argv[4]
+        self.java_path = _parse_nullable_argument(sys.argv[1])
+        self.saxon_path = _parse_nullable_argument(sys.argv[2])
+        self.xsltproc_path = _parse_nullable_argument(sys.argv[3])
+        self.xslt_path = _parse_nullable_argument(sys.argv[4])
+        self.input = sys.argv[5]
+        self.output = sys.argv[6]
         self.script_folder = os.path.dirname(self.own_path) + '/../'
 
         print('Generating ePub with the following parameters:')
         print(self.own_path)
         print(self.java_path)
+        print(self.saxon_path)
         print(self.xsltproc_path)
+        print(self.xslt_path)
         print(self.input)
         print(self.output)
 
@@ -50,10 +58,16 @@ class DocBookToEpub:
         self.package_opf = self.output_dir + '/OEBPS/package.opf'  # Does not exist yet,
         print('Temporary output directory: %s' % self.output_dir)
 
-        self.xslt = self.script_folder + 'docbook/epub3/chunk.xsl'
+        if self.xslt_path is None:
+            self.xslt = self.script_folder + 'docbook/epub3/chunk.xsl'
+        else:
+            self.xslt = self.xslt_path + '/epub3/chunk.xsl'
         print('XSLT style sheet to use:')
         print(self.xslt)
 
+        if self.saxon_path is None:
+            self.saxon_path = self.script_folder + 'scripts/saxon6.5.5.jar'
+
         # These will be filled during the execution of the script.
         self.renamed = None
 
@@ -64,9 +78,9 @@ class DocBookToEpub:
 
     def start_xslt_transformation(self):
         command = None
-        if self.xsltproc_path != '':
+        if self.xsltproc_path is not None:
             command = self.start_xslt_transformation_xsltproc()
-        elif self.java_path != '':
+        elif self.java_path is not None:
             command = self.start_xslt_transformation_saxon6()
 
         if command is None:
@@ -92,9 +106,8 @@ class DocBookToEpub:
         return '"' + self.xsltproc_path + '" ' + params + ' "' + self.xslt + '" "' + self.input + '"'
 
     def start_xslt_transformation_saxon6(self):
-        saxon_jar = self.script_folder + 'scripts/saxon6.5.5.jar'
         params = 'base.dir=%s' % self.output_dir
-        executable = '"' + self.java_path + '" -jar "' + saxon_jar + '"'
+        executable = '"' + self.java_path + '" -jar "' + self.saxon_path + '"'
         return executable + ' "' + self.input + '" "' + self.xslt + '" "' + params + '"'
 
     def get_images_from_package_opf(self):