add bundled app

This commit is contained in:
j 2015-11-30 17:46:10 +01:00
parent 2fea3d524e
commit e978f4cee3
10 changed files with 269 additions and 0 deletions

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15C40a</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Open Media Library</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIdentifier</key>
<string>com.openmedialibrary.oml</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Open Media Library</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>7B1005</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>15A278</string>
<key>DTSDKName</key>
<string>macosx10.11</string>
<key>DTXcode</key>
<string>0711</string>
<key>DTXcodeBuild</key>
<string>7B1005</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.education</string>
<key>LSMinimumSystemVersion</key>
<string>10.6</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View file

@ -0,0 +1 @@
APPL????

View file

@ -0,0 +1,10 @@
<html>
<head>
<title>Open Media Library</title>
</head>
<body>
Installing Open Media Library...<br>
<div id="status"></div>
<script src="js/install.js"></script>
</body>
</html>

View file

@ -0,0 +1,24 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Open Media Library</title>
</head>
<body>
<script>
function load() {
var base = 'http://127.0.0.1:9841';
var xhr = new XMLHttpRequest();
xhr.onload = function() {
document.location.href = base;
};
xhr.onerror = function() {
setTimeout(load, 1000);
}
xhr.open('get', base + '/status');
xhr.send();
}
load();
</script>
</body>
</html>

View file

@ -0,0 +1,131 @@
#!/usr/bin/env python
from __future__ import division, with_statement
from contextlib import closing
import json
import os
import sys
import time
import tarfile
import urllib2
import SimpleHTTPServer
import SocketServer
from threading import Thread
PORT = 9841
static_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__)))
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_OPTIONS(self):
self.send_response(200, 'OK')
self.send_header('Allow', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Headers', 'X-Requested-With')
self.send_header('Content-Length', '0')
self.end_headers()
def do_GET(self):
if self.path == '/status':
content = json.dumps(self.server.install.status)
self.send_response(200, 'OK')
else:
path = os.path.join(static_dir, 'index.html' if self.path == '/' else self.path[1:])
if os.path.exists(path):
with open(path) as fd:
content = fd.read()
self.send_response(200, 'OK')
else:
self.send_response(404, 'not found')
content = '404 not found'
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Content-Length', str(len(content)))
self.end_headers()
self.wfile.write(content)
class Install(Thread):
release_url = "http://downloads.openmedialibrary.com/release.json"
status = {}
def __init__(self, target, httpd):
target = os.path.normpath(os.path.join(os.path.abspath(target)))
self.target = target
self.httpd = httpd
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
target = self.target
if not os.path.exists(target):
os.makedirs(target)
os.chdir(target)
release = self.get_release()
self.status["release"] = release
for module in release['modules']:
self.status["step"] = 'downloading %s' % module
self.status["progress"] = 0
self.status["size"] = 0
package_tar = release['modules'][module]['name']
url = self.release_url.replace('release.json', package_tar)
self.download(url, package_tar)
self.status["step"] = 'extracting %s' % module
self.status["progress"] = 0
tar = tarfile.open(package_tar)
tar.extractall()
tar.close()
os.unlink(package_tar)
os.symlink('openmedialibrary/ctl', 'ctl')
self.status["progress"] = 0
self.status["step"] = "setup"
os.system("./ctl setup")
self.status["progress"] = 1
with open('config/release.json', 'w') as fd:
json.dump(release, fd, indent=2)
self.status = {"installation finished. starting...": True}
os.system("./ctl start &")
time.sleep(1)
self.httpd.shutdown()
def download(self, url, filename):
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
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
data = u.read(4096)
while data:
if size:
available += len(data)
self.status["progress"] = available/size
f.write(data)
data = u.read(4096)
def get_release(self):
with closing(urllib2.urlopen(self.release_url)) as u:
data = json.load(u)
return data
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]
sys.exit(1)
else:
target = sys.argv[1]
SocketServer.TCPServer.allow_reuse_address = True
httpd = SocketServer.TCPServer(("", PORT), Handler)
install = Install(target, httpd)
httpd.install = install
httpd.serve_forever()

View file

@ -0,0 +1,44 @@
function load() {
var base = '//127.0.0.1:9842',
ws = new WebSocket('ws:' + base + '/ws');
ws.onopen = function(event) {
document.location.href = 'http:' + base;
};
ws.onerror = function(event) {
ws.close();
setTimeout(load, 500);
};
ws.onclose = function(event) {
setTimeout(load, 500);
};
};
function update() {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = JSON.parse(this.responseText);
if (response.step) {
var status = response.step;
if (response.progress) {
status = parseInt(response.progress * 100) + '% ' + status;
}
document.getElementById('status').innerHTML = status;
setTimeout(update, 1000);
} else {
document.getElementById('status').innerHTML = "done";
setTimeout(load, 500);
}
};
xhr.onerror = function() {
var status = document.getElementById('status').innerHTML;
if (['done', 'setup'].indexOf(status) == -1) {
document.getElementById('status').innerHTML = "error";
}
load();
}
xhr.open('get', '/status');
xhr.send();
}
update();