Open Media Library.app

This commit is contained in:
j 2014-08-04 21:41:30 +02:00
commit c72189069e
9 changed files with 270 additions and 0 deletions

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>Open Media Library</string>
<key>CFBundleGetInfoString</key>
<string>Open Media Library</string>
<key>CFBundleIconFile</key>
<string>Open Media Library.icns</string>
<key>CFBundleIdentifier</key>
<string>com.openmedialibrary.app</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.0.1</string>
<key>CFBundleSignature</key>
<string>OML</string>
<key>CFBundleVersion</key>
<string>0.0.20140804</string>
</dict>
</plist>

View file

@ -0,0 +1,10 @@
#!/bin/sh
cd "`dirname "$0"`"
BASE="$HOME/Library/Application Support/Open Media Library/"
if [ -e "$BASE" ]; then
launchctl start com.openmedialibrary.loginscript
open "$BASE/openmedialibrary/static/html/load.html"
else
python install.py "$BASE" &
open ../Resources/static/install.html
fi

View file

@ -0,0 +1,150 @@
#!/usr/bin/env python
from __future__ import division, with_statement
from contextlib import closing
import json
import os
import sys
import tarfile
import urllib2
import SimpleHTTPServer
import SocketServer
from threading import Thread
release_url = "http://downloads.openmedialibrary.com/release.json"
PORT = 9842
static_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'Resources', 'static'))
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)
def get_release():
with closing(urllib2.urlopen(release_url)) as u:
data = json.load(u)
return data
class Install(Thread):
status = {}
def __init__(self, target, httpd):
self.target = target
self.httpd = httpd
Thread.__init__(self)
self.daemon = True
self.start()
def run(self):
target = self.target
target = os.path.normpath(os.path.join(os.path.abspath(target)))
if not os.path.exists(target):
os.makedirs(target)
os.chdir(target)
release = get_release()
self.status["release"] = release
for module in release['modules']:
self.status["installing"] = module
self.status["progress"] = 0
self.status["size"] = 0
package_tar = release['modules'][module]['name']
url = release_url.replace('release.json', package_tar)
self.download(url, package_tar)
tar = tarfile.open(package_tar)
tar.extractall()
tar.close()
os.unlink(package_tar)
os.symlink('openmedialibrary/ctl', 'ctl')
self.status["progress"] = 0
self.status["installing"] = "setup"
os.system("./ctl setup")
self.status["progress"] = 1
with open('config/release.json', 'w') as fd:
json.dump(release, fd, indent=2)
if sys.platform == 'darwin':
self.install_launchd()
elif sys.platform == 'linux2':
#fixme, do only if on debian/ubuntu
os.sysrem('sudo apt-get install python-imaging python-setproctitle python-simplejson')
self.status = json.dumps({"done": True})
self.httpd.shutdown()
def download(self, url, filename):
dirname = os.path.dirname(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
print url, filename
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 install_launchd(self):
plist = os.path.expanduser('~/Library/LaunchAgents/com.openmedialibrary.loginscript.plist')
with open(plist, 'w') as f:
f.write('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.openmedialibrary.loginscript</string>
<key>ProgramArguments</key>
<array>
<string>%s/ctl</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>''' % self.target)
os.system('launchctl load "%s"' % plist)
os.system('launchctl start com.openmedialibrary.loginscript')
if __name__ == '__main__':
if len(sys.argv) == 1:
target = os.path.join(os.curdir, 'openmedialibrary')
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,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:9842';
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,38 @@
function load() {
var base = 'http://[::1]:9842',
img = new Image();
img.onload = function(event) {
document.location.href = base;
};
img.src = base + '/static/oxjs/build/Ox.UI/png/transparent.png?' + new Date;
};
function update() {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = JSON.parse(this.responseText);
if (response.installing) {
var status = response.installing;
if (response.progress) {
status = parseInt(response.progress * 100) + '% ' + status;
}
document.getElementById('status').innerHTML = status;
setTimeout(update, 1000);
} else {
document.getElementById('status').innerHTML = "done";
load();
}
};
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();

6
README Normal file
View file

@ -0,0 +1,6 @@
Open Media Library OS X Launcher and Installer
place "Open Media Library.app" into /Applications
On first launch it will install Open Media Library for each user.
Later you can use it to start or open Open Media Library.

6
build.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
tmpdir=`mktemp -d -t oml`
cp -r "Open Media Library.app" $tmpdir/
hdiutil create -srcfolder "$tmpdir" -volname "Open Media Library" -format UDZO "Open Media Library.tmp.dmg"
hdiutil convert -format UDZO -imagekey zlib-level=9 -o "Open Media Library.dmg" "Open Media Library.tmp.dmg"
rm -rf $tmpdir "Open Media Library.tmp.dmg"