From cd92b7838d0c8b959dbb5626a1b7615dd4f42e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 24 Dec 2016 06:42:44 +0800 Subject: [PATCH] Added complex fules to determine whether soffice is LibreOffice, for the vender-installed LibreOffice on Linux. --- bin/obasync | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/obasync b/bin/obasync index 988ee1b..b73c936 100755 --- a/bin/obasync +++ b/bin/obasync @@ -362,7 +362,7 @@ class Office: self.port # LibreOffice on POSIX systems uses --accept instead of # -accept now. - if ooexec.lower().find("libreoffice") != -1: + if self.is_ooexec_lo(ooexec): param = "-" + param try: os.execl(ooexec, ooexec, param) @@ -399,5 +399,21 @@ class Office: # Not found return None + def is_ooexec_lo(self, ooexec): + """ Checks whether the soffice executable is LibreOffice. + LibreOffice on POSIX systems uses --accept instead of + -accept now. """ + # This works for most cases. + if ooexec.lower().find("libreoffice") != -1: + return True + + # Checks the symbolic link at /usr/bin/soffice + if ooexec == "/usr/bin/soffice" and os.path.islink(ooexec): + if os.readlink(ooexec).lower().find("libreoffice") != -1: + return True + + # Not found + return False + if __name__ == "__main__": main()