Compare commits

..

No commits in common. "1582cef26a0d9ceb7dfe86a79449a41424b38069" and "e8c8356dc9ca942b000c4a3f45e37656845e4bb9" have entirely different histories.

2 changed files with 14 additions and 21 deletions

View file

@ -41,7 +41,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let install_py = resourcePath?.stringByAppendingString("/install.py")
let install_html = resourcePath?.stringByAppendingString("/install.html")
let install = NSTask()
install.launchPath = "/usr/bin/python3"
install.launchPath = "/usr/bin/python"
install.arguments = [install_py!]
install.launch()
open(install_html!)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3
#!/usr/bin/env python
from __future__ import division, with_statement
from contextlib import closing
import json
@ -7,23 +7,19 @@ import os
import sys
import time
import tarfile
import urllib.request
import urllib.error
import urllib.parse
import http.server
import socketserver
import urllib2
import SimpleHTTPServer
import SocketServer
from threading import Thread
PORT = 9841
static_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
def makedirs(dirname):
if not os.path.exists(dirname):
os.makedirs(dirname)
def get_platform():
name = sys.platform
if name.startswith('darwin'):
@ -36,8 +32,7 @@ def get_platform():
name = 'linux32'
return name
class Handler(http.server.SimpleHTTPRequestHandler):
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_OPTIONS(self):
self.send_response(200, 'OK')
self.send_header('Allow', 'GET, POST, OPTIONS')
@ -54,7 +49,7 @@ class Handler(http.server.SimpleHTTPRequestHandler):
else:
path = os.path.join(static_dir, 'index.html' if self.path == '/' else self.path[1:])
if os.path.exists(path):
with open(path, 'rb') as fd:
with open(path) as fd:
content = fd.read()
self.send_response(200, 'OK')
content_type = {
@ -70,8 +65,6 @@ class Handler(http.server.SimpleHTTPRequestHandler):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Content-Length', str(len(content)))
self.end_headers()
if isinstance(content, str):
content = content.encode()
self.wfile.write(content)
@ -125,8 +118,8 @@ class Install(Thread):
dirname = os.path.dirname(filename)
if dirname:
makedirs(dirname)
with open(filename, 'wb') as f:
with closing(urllib.request.urlopen(url)) as u:
with open(filename, 'w') as f:
with closing(urllib2.urlopen(url)) as u:
size = int(u.headers.get('content-length', 0))
self.status["size"] = size
available = 0
@ -138,7 +131,7 @@ class Install(Thread):
data = u.read(4096)
def get_release(self):
with closing(urllib.request.urlopen(self.release_url)) as u:
with closing(urllib2.urlopen(self.release_url)) as u:
data = json.load(u)
return data
@ -147,12 +140,12 @@ if __name__ == '__main__':
if len(sys.argv) == 1:
target = os.path.expanduser("~/Library/Application Support/Open Media Library")
elif len(sys.argv) != 2:
print("usage: %s [target]" % sys.argv[0])
print "usage: %s [target]" % sys.argv[0]
sys.exit(1)
else:
target = sys.argv[1]
socketserver.TCPServer.allow_reuse_address = True
httpd = socketserver.TCPServer(("", PORT), Handler)
SocketServer.TCPServer.allow_reuse_address = True
httpd = SocketServer.TCPServer(("", PORT), Handler)
install = Install(target, httpd)
httpd.install = install
httpd.serve_forever()