Make CLI work with PyInstaller in macOS

This commit is contained in:
Micah Lee 2017-02-22 13:34:20 -08:00
parent 2625ab04f5
commit 9be8169233
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 55 additions and 6 deletions

View File

@ -9,12 +9,17 @@ rm -rf $ROOT/build $ROOT/dist &>/dev/null 2>&1
# build the .app
echo Building OnionShare.app
pyinstaller install/pyinstaller.spec
pyinstaller $ROOT/install/pyinstaller.spec
# create a symlink of onionshare-gui called onionshare, for the CLI version
cd $ROOT/dist/OnionShare.app/Contents/MacOS
ln -s onionshare-gui onionshare
cd $ROOT
if [ "$1" = "--release" ]; then
mkdir -p dist
APP_PATH="build/OnionShare.app"
PKG_PATH="dist/OnionShare.pkg"
APP_PATH="$ROOT/dist/OnionShare.app"
PKG_PATH="$ROOT/dist/OnionShare.pkg"
IDENTITY_NAME_APPLICATION="Developer ID Application: Micah Lee"
IDENTITY_NAME_INSTALLER="Developer ID Installer: Micah Lee"

View File

@ -6,7 +6,7 @@ p = platform.system()
version = open('share/version.txt').read().strip()
a = Analysis(
['scripts/onionshare-gui'],
['scripts/onionshare-pyinstaller'],
pathex=['.'],
binaries=None,
datas=[
@ -33,7 +33,7 @@ exe = EXE(
pyz,
a.scripts,
exclude_binaries=True,
name='onionshare',
name='onionshare-gui',
debug=False,
strip=False,
upx=True,
@ -46,7 +46,7 @@ coll = COLLECT(
a.datas,
strip=False,
upx=True,
name='onionshare')
name='onionshare-gui')
if p == 'Darwin':
app = BUNDLE(

View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
OnionShare | https://onionshare.org/
Copyright (C) 2017 Micah Lee <micah@micahflee.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys, os, platform
# In macOS, allow both CLI and GUI depending on the filename of the binary
# being executed
if platform.system() == 'Darwin':
# If the binary being executed is called 'onionshare', use CLI
basename = os.path.basename(sys.argv[0])
if basename == 'onionshare':
import onionshare
onionshare.main()
# Otherwise, use GUI
else:
import onionshare_gui
onionshare_gui.main()
# Unfortunately this trick won't work in Windows because I want to set
# console=False in the PyInstaller spec file, so there isn't a command prompt
# open in the background every you run the GUI. Hopefully Windows can get
# a built-in CLI when PyInstaller 3.3 comes out:
# https://pyinstaller.readthedocs.io/en/stable/spec-files.html#multipackage-bundles
else:
import onionshare_gui
onionshare_gui.main()