Skip to content

Commit

Permalink
Switch to py2app compiler on macOS for 10.10 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Feb 3, 2017
1 parent 92bdafc commit dfe0955
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 30 deletions.
25 changes: 0 additions & 25 deletions PyInstaller/compile_mac.sh

This file was deleted.

32 changes: 28 additions & 4 deletions PyInstaller/boot.py → compile/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ def copyDlls(work_dir):

def setup():
work_dir = getWorkDir()

# Redirect stdout to file if running as .app
if sys.platform == "darwin" and not sys.stdout.isatty() and os.path.isdir(work_dir + "/log"):
print "Running as .app", sys.argv
try:
sys.stdout = open(work_dir + "/log/stdout.log", "w")
sys.stderr = sys.stdout
except Exception, err:
print "Error redirecting stdout:", err

# Remove weird -psn_ argument
if len(sys.argv) > 1 and sys.argv[1].startswith('-psn_'):
del sys.argv[1]

# Replace boot.py with the real executable
if sys.argv[0].endswith("Resources/boot.py"):
sys.argv[0] = sys.argv[0].replace("Resources/boot.py", "MacOS/ZeroNet")
sys.executable = sys.argv[0]

addSourcePaths(work_dir)
if sys.platform.startswith("win"):
copyDlls(work_dir)
Expand All @@ -77,13 +96,15 @@ def setup():

gui_root = None


def gui():
global gui_root
time.sleep(5)
sys.path.append("/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk")
sys.path.append("/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/")

# Wait for ui_server startup
while not (sys.modules.get("main") and "ui_server" in dir(sys.modules["main"]) and getattr(sys.modules["main"].ui_server, "server", None)):
time.sleep(0.1)

def click():
import webbrowser
webbrowser.open("http://127.0.0.1:43110")
Expand All @@ -97,6 +118,8 @@ def quit():
gui_root.iconify()
gui_root.createcommand('tk::mac::ReopenApplication', click)
gui_root.createcommand('tk::mac::Quit', quit)
if not os.environ.get("SECURITYSESSIONID"): # Not started by auto-run
click()
gui_root.mainloop()
except ExitCommand:
print "Stopping..."
Expand All @@ -114,6 +137,7 @@ def signalHandler(signal, frame):
raise ExitCommand()



def main(mode="main", open_browser=True):
if open_browser:
sys.argv = [sys.argv[0]] + ["--open_browser", "default_browser"] + sys.argv[1:] # Open browser window
Expand Down Expand Up @@ -145,13 +169,13 @@ def threadedExit(*args):
if sys.platform == "darwin":
import signal
signal.signal(signal.SIGUSR1, signalHandler)
# Start dock icon click watcher on macOS
from threading import Thread
t = Thread(target=main, kwargs={"mode": "thread", "open_browser": not os.environ.get("SECURITYSESSIONID")})
t = Thread(target=main, kwargs={"mode": "thread", "open_browser": False})
t.daemon = True
t.start()

try:
# Start dock icon click watcher on macOS
gui()
except ExitCommand:
pass
Expand Down
27 changes: 27 additions & 0 deletions compile/compile_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
rm -rf build
rm -rf dist
python zeronet_mac_py2app.py py2app -O2
cd ../../ZeroNet
git pull
cd -
git clone --depth 1 file://$(pwd)/../../ZeroNet/.git dist/ZeroNet.app/Contents/Resources/core
echo "Cleanup..."
rm -rf dist/ZeroNet.app/Contents/Resources/include
rm -rf dist/ZeroNet.app/Contents/Resources/core/.git
rm -rf dist/ZeroNet.app/Contents/Resources/core/src/Test/testdata
rm dist/ZeroNet.app/Contents/Resources/core/src/lib/opensslVerify/libeay32.dll
rm dist/ZeroNet.app/Contents/Resources/core/src/lib/opensslVerify/ssleay32.dll
rm dist/ZeroNet.app/Contents/Resources/core/src/lib/opensslVerify/openssl.exe
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/libev/*.c"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/libev/*.h"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/libev/*.ppyx"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/libev/*.pxd"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/libev/*.pyx"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/*.c"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/*.h"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/*.ppyx"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/*.pxd"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "gevent/*.pyx"
zip -d dist/ZeroNet.app/Contents/Resources/lib/python2.7/site-packages.zip "pydoc_data/*"
echo "Copy __error__.sh"
cp -f tools/__error__.sh dist/ZeroNet.app/Contents/Resources/__error__.sh
File renamed without changes.
2 changes: 1 addition & 1 deletion PyInstaller/release_mac.sh → compile/release_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rm ../../ZeroNet-mac/.DS_Store
rm -Rfv ../../ZeroNet-mac/ZeroNet.app/Contents/Resources/core
cp -fv dist/ZeroNet.app/Contents/MacOS/ZeroNet ../../ZeroNet-mac/ZeroNet.app/Contents/MacOS/ZeroNet
cp -Rv dist/ZeroNet.app/Contents/Resources/core ../../ZeroNet-mac/ZeroNet.app/Contents/Resources/
cp -v dist/ZeroNet.app/Contents/Resources/ZeroNet.pkg ../../ZeroNet-mac/ZeroNet.app/Contents/Resources/ZeroNet.pkg
cp -Rv dist/ZeroNet.app/Contents/Resources/*.py ../../ZeroNet-mac/ZeroNet.app/Contents/Resources/
codesign --verbose=3 --force --sign "Developer ID Application: Tamas Kocsis (4977YF9Q3Z)" ../../ZeroNet-mac/ZeroNet.app
cd ../../ZeroNet-mac/
git status
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions compile/tools/__error__.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
#
# This is the default apptemplate error script
#
if ( test -n "$2" ) ; then
echo "$1 Error"
echo "An unexpected error has occurred during execution of the main script"
echo ""
echo "$2: $3"
echo ""
echo "See the Console for a detailed traceback."
else
echo "$1 Error"
echo ""
echo "ERRORURL: https://github.com/HelloZeroNet/ZeroNet/issues/new Please report it"
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions compile/zeronet_mac_py2app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""

from setuptools import setup

APP = ['boot.py']
DATA_FILES = []

OPTIONS = {
"includes": ["gevent", "msgpack", "sqlite3", 'queue', 'aifc', 'antigravity', 'argparse', 'asynchat', 'asyncore', 'audiodev', 'BaseHTTPServer', 'Bastion', 'binhex', 'cgi', 'CGIHTTPServer', 'cgitb', 'chunk', 'code', 'codeop', 'colorsys', 'commands', 'compileall', 'ConfigParser', 'Cookie', 'cProfile', 'csv', 'dircache', 'DocXMLRPCServer', 'filecmp', 'fileinput', 'formatter', 'fpformat', 'fractions', 'glob', 'hmac', 'htmlentitydefs', 'htmllib', 'HTMLParser', 'ihooks', 'imaplib', 'imghdr', 'imputil', 'macpath', 'macurl2path', 'mailbox', 'mailcap', 'markupbase', 'md5', 'mhlib', 'MimeWriter', 'mimify', 'modulefinder', 'multifile', 'mutex', 'netrc', 'new', 'nntplib', 'pickletools', 'pipes', 'pkgutil', 'popen2', 'poplib', 'posixfile', 'profile', 'pstats', 'pty', 'pyclbr', 'pydoc', 'rexec', 'rlcompleter', 'robotparser', 'runpy', 'sched', 'sets', 'sgmllib', 'sha', 'shelve', 'SimpleHTTPServer', 'SimpleXMLRPCServer', 'site', 'smtpd', 'smtplib', 'sndhdr', 'SocketServer', 'statvfs', 'stringold', 'struct', 'sunau', 'sunaudio', 'symbol', 'symtable', 'tabnanny', 'telnetlib', 'this', 'timeit', 'toaiff', 'trace', 'tty', 'user', 'UserList', 'UserString', 'uuid', 'wave', 'webbrowser', 'xdrlib', 'xmllib', 'xmlrpclib', '_pyio', '__phello__.foo', 'compiler.ast', 'compiler.consts', 'compiler.future', 'compiler.misc', 'compiler.pyassem', 'compiler.pycodegen', 'compiler.symbols', 'compiler.syntax', 'compiler.transformer', 'compiler.visitor', 'curses.ascii', 'curses.has_key', 'curses.panel', 'curses.textpad', 'curses.wrapper', 'email.mime.application', 'email.mime.audio', 'email.mime.base', 'email.mime.image', 'email.mime.message', 'email.mime.multipart', 'email.mime.nonmultipart', 'email.mime.text', 'gevent.aresd', 'gevent.backdoor', 'gevent.baseserver', 'gevent.corecextd', 'gevent.coros', 'gevent.pywsgi', 'gevent.server', 'gevent.util', 'gevent.wsgi', 'gevent._semaphore', 'gevent._semaphored', 'gevent._socket3', 'hotshot.log', 'hotshot.stats', 'hotshot.stones', 'json.decoder', 'json.encoder', 'json.scanner', 'json.tool', 'logging.config', 'logging.handlers', 'msgpack._packerd', 'msgpack._unpackerd', 'msilib.schema', 'msilib.sequence', 'msilib.text', 'multiprocessing.connection', 'multiprocessing.forking', 'multiprocessing.heap', 'multiprocessing.managers', 'multiprocessing.pool', 'multiprocessing.process', 'multiprocessing.queues', 'multiprocessing.reduction', 'multiprocessing.sharedctypes', 'multiprocessing.synchronize', 'multiprocessing.util', 'multiprocessing.dummy.connection', 'unittest.__main__', 'wsgiref.handlers', 'wsgiref.headers', 'wsgiref.simple_server', 'wsgiref.util', 'wsgiref.validate', 'xml.dom.domreg', 'xml.dom.expatbuilder', 'xml.dom.minicompat', 'xml.dom.minidom', 'xml.dom.NodeFilter', 'xml.dom.pulldom', 'xml.dom.*', 'xml.etree.cElementTree', 'xml.etree.ElementInclude', 'xml.etree.ElementPath', 'xml.etree.*', 'xml.parsers.*', 'Queue', 'pyexpat', 'gevent.builtins'],
"excludes": ["Carbon", "test", "bsddb", "Tkinter"],
"iconfile": 'zeronet.icns'
}

setup(
app=APP,
name="ZeroNet",
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
File renamed without changes.

0 comments on commit dfe0955

Please sign in to comment.