From 28c877c6fa2e223caab78aff43ed978d73eb6a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 23 Dec 2016 17:12:35 +0800 Subject: [PATCH] Added complex rules to find the soffice executable, to deal with LibreOffice on MacOSX, and Linux OpenOffice/LibreOffice vender installation. --- TODO | 1 - bin/obasync | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index b647e50..9e1187b 100644 --- a/TODO +++ b/TODO @@ -5,4 +5,3 @@ obasync TODO * Linux system-bundled LibreOffice. * Writes the README (reStructureText). * Documentation. -* Python 3 diff --git a/bin/obasync b/bin/obasync index 1538a41..77e4ee8 100755 --- a/bin/obasync +++ b/bin/obasync @@ -352,8 +352,12 @@ class Office: time.sleep(2) return os.setsid() - ooexec = os.path.join( - os.path.dirname(uno.__file__), "soffice") + ooexec = self.find_posix_ooexec() + if ooexec is None: + print("Failed to find the " + "OpenOffice/LibreOffice installation.", + file=sys.stderr) + sys.exit(1) try: os.execl(ooexec, ooexec, "-accept=socket,host=localhost,port=%d;urp;" % @@ -364,5 +368,32 @@ class Office: file=sys.stderr) sys.exit(1) + def find_posix_ooexec(self): + """ Finds the OpenOffice/LibreOffice executable on POSIX + systems (Linux or MacOSX). """ + # Checkes soffice in the same directory of uno.py + # This works for Linux OpenOffice/LibreOffice local + # installation, and OpenOffice on MacOSX. + ooexec = os.path.join( + os.path.dirname(uno.__file__), "soffice") + if os.path.exists(ooexec): + return ooexec + + # Now we have LibreOffice on MacOSX and Linux + # OpenOffice/LibreOffice vender installation. + + # LibreOffice on MacOSX. + ooexec = "/Applications/LibreOffice.app/Contents/MacOS/soffice" + if os.path.exists(ooexec): + return ooexec + + # Linux OpenOffice/LibreOffice vender installation. + ooexec = "/usr/bin/soffice" + if os.path.exists(ooexec): + return ooexec + + # Not found + return None + if __name__ == "__main__": main()