[Pkg-privacy-commits] [onionshare] 91/256: Make CLI work with PyInstaller in macOS

Ulrike Uhlig ulrike at moszumanska.debian.org
Fri May 26 12:53:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

ulrike pushed a commit to branch master
in repository onionshare.

commit 9be81692338d9d3b7f725e5770a74196cf2c3da2
Author: Micah Lee <micah at micahflee.com>
Date:   Wed Feb 22 13:34:20 2017 -0800

    Make CLI work with PyInstaller in macOS
---
 install/build_osx.sh                   | 11 ++++++---
 install/pyinstaller.spec               |  6 ++---
 install/scripts/onionshare-pyinstaller | 44 ++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/install/build_osx.sh b/install/build_osx.sh
index a8259a4..44883fd 100755
--- a/install/build_osx.sh
+++ b/install/build_osx.sh
@@ -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"
 
diff --git a/install/pyinstaller.spec b/install/pyinstaller.spec
index de88dd0..1b8be28 100644
--- a/install/pyinstaller.spec
+++ b/install/pyinstaller.spec
@@ -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(
diff --git a/install/scripts/onionshare-pyinstaller b/install/scripts/onionshare-pyinstaller
new file mode 100644
index 0000000..c955212
--- /dev/null
+++ b/install/scripts/onionshare-pyinstaller
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+OnionShare | https://onionshare.org/
+
+Copyright (C) 2017 Micah Lee <micah at 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()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list