Use open instead of webbrowser.open on macOS >= 10.12.5

Works around an osascript bug. Fixes #4035.
This commit is contained in:
ridiculousfish 2017-05-27 23:46:25 -07:00 committed by David Adam
parent f234637e53
commit 2f5af733ba

View file

@ -4,10 +4,12 @@ from __future__ import unicode_literals
from __future__ import print_function from __future__ import print_function
import binascii import binascii
import cgi import cgi
from distutils.version import LooseVersion
import glob import glob
import multiprocessing.pool import multiprocessing.pool
import operator import operator
import os import os
import platform
import random import random
import re import re
import select import select
@ -29,6 +31,12 @@ else:
import socketserver as SocketServer import socketserver as SocketServer
from urllib.parse import parse_qs from urllib.parse import parse_qs
def isMacOS10_12_5_OrLater():
""" Return whether this system is macOS 10.12.5 or a later version. """
version = platform.mac_ver()[0]
return version and LooseVersion(version) >= LooseVersion('10.12.5')
# Disable CLI web browsers # Disable CLI web browsers
term = os.environ.pop('TERM', None) term = os.environ.pop('TERM', None)
if term: if term:
@ -1124,9 +1132,13 @@ f.write(redirect_template_html % (url, url))
f.close() f.close()
# Open temporary file as URL # Open temporary file as URL
# Use open on macOS >= 10.12.5 to work around #4035.
fileurl = 'file://' + filename fileurl = 'file://' + filename
print("Web config started at '%s'. Hit enter to stop." % fileurl) print("Web config started at '%s'. Hit enter to stop." % fileurl)
webbrowser.open(fileurl) if isMacOS10_12_5_OrLater():
subprocess.check_call(['open', fileurl])
else:
webbrowser.open(fileurl)
# Select on stdin and httpd # Select on stdin and httpd
stdin_no = sys.stdin.fileno() stdin_no = sys.stdin.fileno()