From cef4425d28a870123437d38fefbfc6cd1f931317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 20 Dec 2016 22:01:37 +0800 Subject: [PATCH] Added setuptools and published to PyPI, so that it can be installed with pip. --- README.rst | 0 obasync.py => bin/obasync | 32 +++++++++++++++++--------------- setup.py | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 README.rst rename obasync.py => bin/obasync (96%) mode change 100755 => 100644 create mode 100755 setup.py diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..e69de29 diff --git a/obasync.py b/bin/obasync old mode 100755 new mode 100644 similarity index 96% rename from obasync.py rename to bin/obasync index 6520c39..7ead307 --- a/obasync.py +++ b/bin/obasync @@ -8,26 +8,28 @@ import os import sys import time -# Finds uno.py for MS-Windows -is_found_uno = False -for p in sys.path: - if os.path.exists(os.path.join(p, "uno.py")): - is_found_uno = True - break -if not is_found_uno: + +def append_uno_path(): + """ Appends the path of the uno module to the import path. """ + + is_found_uno = False + for p in sys.path: + if os.path.exists(os.path.join(p, "uno.py")): + return + # For uno.py on MacOS + cand = "/Applications/OpenOffice.app/Contents/MacOS" + if os.path.exists(os.path.join(cand, "uno.py")): + sys.path.append(cand) + return + # Finds uno.py for MS-Windows cand = sys.executable while cand != os.path.dirname(cand): cand = os.path.dirname(cand) if os.path.exists(os.path.join(cand, "uno.py")): sys.path.append(cand) - is_found_uno = True - break -# For uno.py on MacOS -if not is_found_uno: - cand = "/Applications/OpenOffice.app/Contents/MacOS" - if os.path.exists(os.path.join(cand, "uno.py")): - sys.path.append(cand) - is_found_uno = True + return + +append_uno_path() import uno from com.sun.star.connection import NoConnectException diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..0e0603e --- /dev/null +++ b/setup.py @@ -0,0 +1,22 @@ +import os +import sys +from setuptools import setup + +# For Python shipped with OpenOffice, python is a wrapper +# for python.bin that fixes the import and library path. We should +# call python instead of python.bin. """ +import os +import sys +if os.path.basename(sys.executable) == "python.bin": + sys.executable = os.path.join( + os.path.dirname(sys.executable), "python") + +setup(name="obasync", + version="0.1", + description="Office Basic macro source synchronizer", + url="https://github.com/imacat/obasync", + author="imacat", + author_email="imacat@mail.imacat.idv.tw", + license="Apache License, Version 2.0", + zip_safe=False, + scripts=["bin/obasync"])