This commit is contained in:
j 2014-08-07 11:49:59 +02:00
parent c72189069e
commit 462be8859e
2 changed files with 19 additions and 21 deletions

View File

@ -11,12 +11,11 @@ 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')
@ -45,13 +44,10 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
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):
release_url = "http://downloads.openmedialibrary.com/release.json"
status = {}
def __init__(self, target, httpd):
@ -67,39 +63,36 @@ class Install(Thread):
if not os.path.exists(target):
os.makedirs(target)
os.chdir(target)
release = get_release()
release = self.get_release()
self.status["release"] = release
for module in release['modules']:
self.status["installing"] = module
self.status["step"] = 'downloading %s' % module
self.status["progress"] = 0
self.status["size"] = 0
package_tar = release['modules'][module]['name']
url = release_url.replace('release.json', package_tar)
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["installing"] = "setup"
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)
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.install_launchd()
self.status = {"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))
@ -113,6 +106,11 @@ class Install(Thread):
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
def install_launchd(self):
plist = os.path.expanduser('~/Library/LaunchAgents/com.openmedialibrary.loginscript.plist')
with open(plist, 'w') as f:

View File

@ -11,8 +11,8 @@ function update() {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = JSON.parse(this.responseText);
if (response.installing) {
var status = response.installing;
if (response.step) {
var status = response.step;
if (response.progress) {
status = parseInt(response.progress * 100) + '% ' + status;
}