Added complex rules to find the soffice executable, to deal with LibreOffice on MacOSX, and Linux OpenOffice/LibreOffice vender installation.

This commit is contained in:
依瑪貓 2016-12-23 17:12:35 +08:00
parent 0ad8fcbacf
commit 28c877c6fa
2 changed files with 33 additions and 3 deletions

1
TODO
View File

@ -5,4 +5,3 @@ obasync TODO
* Linux system-bundled LibreOffice.
* Writes the README (reStructureText).
* Documentation.
* Python 3

View File

@ -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()