use python3 for installer, current osx does not have python2 anymore
This commit is contained in:
parent
0b612a1873
commit
1582cef26a
2 changed files with 20 additions and 13 deletions
|
@ -41,7 +41,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
let install_py = resourcePath?.stringByAppendingString("/install.py")
|
let install_py = resourcePath?.stringByAppendingString("/install.py")
|
||||||
let install_html = resourcePath?.stringByAppendingString("/install.html")
|
let install_html = resourcePath?.stringByAppendingString("/install.html")
|
||||||
let install = NSTask()
|
let install = NSTask()
|
||||||
install.launchPath = "/usr/bin/python"
|
install.launchPath = "/usr/bin/python3"
|
||||||
install.arguments = [install_py!]
|
install.arguments = [install_py!]
|
||||||
install.launch()
|
install.launch()
|
||||||
open(install_html!)
|
open(install_html!)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
from __future__ import division, with_statement, print_function
|
|
||||||
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
import json
|
import json
|
||||||
|
@ -7,19 +7,23 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import tarfile
|
import tarfile
|
||||||
import urllib2
|
import urllib.request
|
||||||
import SimpleHTTPServer
|
import urllib.error
|
||||||
import SocketServer
|
import urllib.parse
|
||||||
|
import http.server
|
||||||
|
import socketserver
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
|
|
||||||
PORT = 9841
|
PORT = 9841
|
||||||
static_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
static_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
|
||||||
def makedirs(dirname):
|
def makedirs(dirname):
|
||||||
if not os.path.exists(dirname):
|
if not os.path.exists(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
|
|
||||||
|
|
||||||
def get_platform():
|
def get_platform():
|
||||||
name = sys.platform
|
name = sys.platform
|
||||||
if name.startswith('darwin'):
|
if name.startswith('darwin'):
|
||||||
|
@ -32,7 +36,8 @@ def get_platform():
|
||||||
name = 'linux32'
|
name = 'linux32'
|
||||||
return name
|
return name
|
||||||
|
|
||||||
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
|
||||||
|
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||||
def do_OPTIONS(self):
|
def do_OPTIONS(self):
|
||||||
self.send_response(200, 'OK')
|
self.send_response(200, 'OK')
|
||||||
self.send_header('Allow', 'GET, POST, OPTIONS')
|
self.send_header('Allow', 'GET, POST, OPTIONS')
|
||||||
|
@ -49,7 +54,7 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
path = os.path.join(static_dir, 'index.html' if self.path == '/' else self.path[1:])
|
path = os.path.join(static_dir, 'index.html' if self.path == '/' else self.path[1:])
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
with open(path) as fd:
|
with open(path, 'rb') as fd:
|
||||||
content = fd.read()
|
content = fd.read()
|
||||||
self.send_response(200, 'OK')
|
self.send_response(200, 'OK')
|
||||||
content_type = {
|
content_type = {
|
||||||
|
@ -65,6 +70,8 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
self.send_header('Access-Control-Allow-Origin', '*')
|
self.send_header('Access-Control-Allow-Origin', '*')
|
||||||
self.send_header('Content-Length', str(len(content)))
|
self.send_header('Content-Length', str(len(content)))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
if isinstance(content, str):
|
||||||
|
content = content.encode()
|
||||||
self.wfile.write(content)
|
self.wfile.write(content)
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,8 +125,8 @@ class Install(Thread):
|
||||||
dirname = os.path.dirname(filename)
|
dirname = os.path.dirname(filename)
|
||||||
if dirname:
|
if dirname:
|
||||||
makedirs(dirname)
|
makedirs(dirname)
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'wb') as f:
|
||||||
with closing(urllib2.urlopen(url)) as u:
|
with closing(urllib.request.urlopen(url)) as u:
|
||||||
size = int(u.headers.get('content-length', 0))
|
size = int(u.headers.get('content-length', 0))
|
||||||
self.status["size"] = size
|
self.status["size"] = size
|
||||||
available = 0
|
available = 0
|
||||||
|
@ -131,7 +138,7 @@ class Install(Thread):
|
||||||
data = u.read(4096)
|
data = u.read(4096)
|
||||||
|
|
||||||
def get_release(self):
|
def get_release(self):
|
||||||
with closing(urllib2.urlopen(self.release_url)) as u:
|
with closing(urllib.request.urlopen(self.release_url)) as u:
|
||||||
data = json.load(u)
|
data = json.load(u)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -144,8 +151,8 @@ if __name__ == '__main__':
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
target = sys.argv[1]
|
target = sys.argv[1]
|
||||||
SocketServer.TCPServer.allow_reuse_address = True
|
socketserver.TCPServer.allow_reuse_address = True
|
||||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||||
install = Install(target, httpd)
|
install = Install(target, httpd)
|
||||||
httpd.install = install
|
httpd.install = install
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
Loading…
Reference in a new issue