From 7622292027f6bc851a47103164a58b8989916e4f Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 7 Feb 2021 23:18:54 +0100 Subject: [PATCH] ePub: share a bit of code for parsing arguments. --- lib/scripts/docbook2epub.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/scripts/docbook2epub.py b/lib/scripts/docbook2epub.py index b35296a558..1d39962be5 100644 --- a/lib/scripts/docbook2epub.py +++ b/lib/scripts/docbook2epub.py @@ -21,6 +21,10 @@ import tempfile import zipfile +def _parse_nullable_argument(arg): + return arg if arg != '' and arg != 'none' else None + + class DocBookToEpub: def __init__(self, args=None): if args is None: @@ -31,10 +35,10 @@ class DocBookToEpub: 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 None - self.saxon_path = sys.argv[2] if sys.argv[2] != '' and sys.argv[2] != 'none' else None - self.xsltproc_path = sys.argv[3] if sys.argv[3] != '' and sys.argv[3] != 'none' else None - self.xslt_path = sys.argv[4] if sys.argv[4] != '' and sys.argv[4] != 'none' else None + 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) + '/../'