From 9db3ca59c8cca28db2df591621a5f4935666c368 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Wed, 25 Jun 2014 14:42:39 -0700 Subject: [PATCH] made pyinstaller work for OSX (#43) --- BUILD.md | 6 ++--- onionshare/onionshare.py | 19 +++++++++----- onionshare_gui/onionshare_gui.py | 7 +++-- setup.py | 19 -------------- setup/onionshare-osx.spec | 45 ++++++++++++++++++++++++++++++++ setup/py2app.patch | 12 --------- 6 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 setup/onionshare-osx.spec delete mode 100644 setup/py2app.patch diff --git a/BUILD.md b/BUILD.md index ecd1f957..e5dd2b42 100644 --- a/BUILD.md +++ b/BUILD.md @@ -42,9 +42,7 @@ brew install qt4 pyqt sudo pip install virtualenv virtualenv env . env/bin/activate -pip install flask stem py2app -# fixes a silly bug https://bitbucket.org/ronaldoussoren/py2app/issue/143/resulting-app-mistakenly-looks-for-pyside -patch env/lib/python2.7/site-packages/py2app/util.py < setup/py2app.patch +pip install flask stem pyinstaller ``` Each time you start work: @@ -56,7 +54,7 @@ Each time you start work: Build the .app: ```sh -python setup.py py2app +pyinstaller -w -y setup/onionshare-osx.spec ``` Now you should have `dist/OnionShare.app`. diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index d91aea88..e8f374d6 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -14,6 +14,12 @@ def random_string(num_bytes): b = os.urandom(num_bytes) return base64.b32encode(b).lower().replace('=','') +def get_platform(): + p = platform.system() + if p == 'Linux' and platform.uname()[0:2] == ('Linux', 'amnesia'): + p = 'Tails' + return p + # information about the file filename = filesize = filehash = None def set_file_info(new_filename, new_filehash, new_filesize): @@ -24,8 +30,13 @@ def set_file_info(new_filename, new_filehash, new_filesize): app = Flask(__name__) +# get path of onioshare directory +if get_platform() == 'Darwin': + onionshare_dir = os.path.dirname(__file__) +else: + onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + strings = {} -onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) slug = random_string(16) download_count = 0 stay_open = False @@ -130,12 +141,6 @@ def page_not_found(e): add_request(REQUEST_OTHER, request.path) return render_template_string(open('{0}/404.html'.format(onionshare_dir)).read()) -def get_platform(): - p = platform.system() - if p == 'Linux' and platform.uname()[0:2] == ('Linux', 'amnesia'): - p = 'Tails' - return p - def is_root(): return os.geteuid() == 0 diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 81ffdbd9..3516f558 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -1,9 +1,12 @@ -import os, sys, subprocess, inspect +import os, sys, subprocess, inspect, platform from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * -onionshare_gui_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +if platform.system() == 'Darwin': + onionshare_gui_dir = os.path.dirname(__file__) +else: + onionshare_gui_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) try: import onionshare diff --git a/setup.py b/setup.py index 475111c4..024966d6 100644 --- a/setup.py +++ b/setup.py @@ -19,25 +19,6 @@ def file_list(path): version = open('version').read().strip() args = {} -if platform.system() == 'Darwin': - args['data_files'] = ['LICENSE', 'README.md', 'version'] - args['app'] = ['setup/onionshare-launcher.py'] - args['options'] = { - 'py2app': { - 'argv_emulation': True, - 'packages': ['flask', 'stem', 'jinja2', 'onionshare_gui', 'onionshare'], - 'includes': ['PyQt4'], - 'excludes': ['PyQt4.QtDesigner', 'PyQt4.QtOpenGL', 'PyQt4.QtScript', 'PyQt4.QtSql', 'PyQt4.QtTest', 'PyQt4.QtXml', 'PyQt4.phonon'], - 'iconfile': 'setup/onionshare.icns', - 'qt_plugins': 'imageformats', - 'site_packages': True, - 'plist': { - 'CFBundleName': 'OnionShare', - } - } - } - args['setup_requires'] = 'py2app' - else: args['packages'] = ['onionshare', 'onionshare_gui'] args['include_package_data'] = True diff --git a/setup/onionshare-osx.spec b/setup/onionshare-osx.spec new file mode 100644 index 00000000..9371d2f0 --- /dev/null +++ b/setup/onionshare-osx.spec @@ -0,0 +1,45 @@ +# -*- mode: python -*- +a = Analysis(['setup/onionshare-launcher.py'], + pathex=['.'], + hiddenimports=['onionshare', 'onionshare_gui'], + hookspath=None, + runtime_hooks=None) +a.datas += [ + ('onionshare/strings.json', 'onionshare/strings.json', 'DATA'), + ('onionshare/index.html', 'onionshare/index.html', 'DATA'), + ('onionshare/404.html', 'onionshare/404.html', 'DATA'), + ('onionshare_gui/onionshare-icon.png', 'onionshare_gui/onionshare-icon.png', 'DATA'), + ('onionshare_gui/static/jquery-1.11.1.min.js', 'onionshare_gui/static/jquery-1.11.1.min.js', 'DATA'), + ('onionshare_gui/static/helpers.js', 'onionshare_gui/static/helpers.js', 'DATA'), + ('onionshare_gui/static/onionshare.js', 'onionshare_gui/static/onionshare.js', 'DATA'), + ('onionshare_gui/static/style.css', 'onionshare_gui/static/style.css', 'DATA'), + ('onionshare_gui/static/loader.gif', 'onionshare_gui/static/loader.gif', 'DATA'), + ('onionshare_gui/static/logo.png', 'onionshare_gui/static/logo.png', 'DATA'), + ('onionshare_gui/templates/index.html', 'onionshare_gui/templates/index.html', 'DATA'), +] +pyz = PYZ(a.pure) +exe = EXE(pyz, + a.scripts, + exclude_binaries=True, + name='onionshare-launcher', + debug=False, + strip=False, + upx=True, + console=False ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + name='onionshare') +app = BUNDLE(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + name='OnionShare.app', + appname='OnionShare', + icon='setup/onionshare.icns', + version=open('version').read().strip()) diff --git a/setup/py2app.patch b/setup/py2app.patch deleted file mode 100644 index 23a7039c..00000000 --- a/setup/py2app.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- original-util.py 2014-06-17 12:50:15.000000000 -0700 -+++ util.py 2014-06-17 12:51:33.000000000 -0700 -@@ -148,6 +148,9 @@ - log.info("copying file %s -> %s", source, destination) - with zipio.open(source, 'rb') as fp_in: - if not dry_run: -+ if os.path.exists(destination): -+ os.unlink(destination) -+ - with open(destination, 'wb') as fp_out: - data = fp_in.read() - fp_out.write(data)