cleanup
This commit is contained in:
parent
c72189069e
commit
462be8859e
2 changed files with 19 additions and 21 deletions
|
@ -11,12 +11,11 @@ import SimpleHTTPServer
|
||||||
import SocketServer
|
import SocketServer
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
release_url = "http://downloads.openmedialibrary.com/release.json"
|
|
||||||
PORT = 9842
|
PORT = 9842
|
||||||
|
|
||||||
|
|
||||||
static_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'Resources', 'static'))
|
static_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'Resources', 'static'))
|
||||||
|
|
||||||
|
|
||||||
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
def do_OPTIONS(self):
|
def do_OPTIONS(self):
|
||||||
self.send_response(200, 'OK')
|
self.send_response(200, 'OK')
|
||||||
|
@ -45,13 +44,10 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(content)
|
self.wfile.write(content)
|
||||||
|
|
||||||
def get_release():
|
|
||||||
with closing(urllib2.urlopen(release_url)) as u:
|
|
||||||
data = json.load(u)
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class Install(Thread):
|
class Install(Thread):
|
||||||
|
|
||||||
|
release_url = "http://downloads.openmedialibrary.com/release.json"
|
||||||
status = {}
|
status = {}
|
||||||
|
|
||||||
def __init__(self, target, httpd):
|
def __init__(self, target, httpd):
|
||||||
|
@ -67,39 +63,36 @@ class Install(Thread):
|
||||||
if not os.path.exists(target):
|
if not os.path.exists(target):
|
||||||
os.makedirs(target)
|
os.makedirs(target)
|
||||||
os.chdir(target)
|
os.chdir(target)
|
||||||
release = get_release()
|
release = self.get_release()
|
||||||
self.status["release"] = release
|
self.status["release"] = release
|
||||||
for module in release['modules']:
|
for module in release['modules']:
|
||||||
self.status["installing"] = module
|
self.status["step"] = 'downloading %s' % module
|
||||||
self.status["progress"] = 0
|
self.status["progress"] = 0
|
||||||
self.status["size"] = 0
|
self.status["size"] = 0
|
||||||
package_tar = release['modules'][module]['name']
|
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.download(url, package_tar)
|
||||||
|
self.status["step"] = 'extracting %s' % module
|
||||||
|
self.status["progress"] = 0
|
||||||
tar = tarfile.open(package_tar)
|
tar = tarfile.open(package_tar)
|
||||||
tar.extractall()
|
tar.extractall()
|
||||||
tar.close()
|
tar.close()
|
||||||
os.unlink(package_tar)
|
os.unlink(package_tar)
|
||||||
os.symlink('openmedialibrary/ctl', 'ctl')
|
os.symlink('openmedialibrary/ctl', 'ctl')
|
||||||
self.status["progress"] = 0
|
self.status["progress"] = 0
|
||||||
self.status["installing"] = "setup"
|
self.status["step"] = "setup"
|
||||||
os.system("./ctl setup")
|
os.system("./ctl setup")
|
||||||
self.status["progress"] = 1
|
self.status["progress"] = 1
|
||||||
with open('config/release.json', 'w') as fd:
|
with open('config/release.json', 'w') as fd:
|
||||||
json.dump(release, fd, indent=2)
|
json.dump(release, fd, indent=2)
|
||||||
if sys.platform == 'darwin':
|
self.install_launchd()
|
||||||
self.install_launchd()
|
self.status = {"done": True}
|
||||||
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()
|
self.httpd.shutdown()
|
||||||
|
|
||||||
def download(self, url, filename):
|
def download(self, url, filename):
|
||||||
dirname = os.path.dirname(filename)
|
dirname = os.path.dirname(filename)
|
||||||
if dirname and not os.path.exists(dirname):
|
if dirname and not os.path.exists(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
print url, filename
|
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
with closing(urllib2.urlopen(url)) as u:
|
with closing(urllib2.urlopen(url)) as u:
|
||||||
size = int(u.headers.get('content-length', 0))
|
size = int(u.headers.get('content-length', 0))
|
||||||
|
@ -113,6 +106,11 @@ class Install(Thread):
|
||||||
f.write(data)
|
f.write(data)
|
||||||
data = u.read(4096)
|
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):
|
def install_launchd(self):
|
||||||
plist = os.path.expanduser('~/Library/LaunchAgents/com.openmedialibrary.loginscript.plist')
|
plist = os.path.expanduser('~/Library/LaunchAgents/com.openmedialibrary.loginscript.plist')
|
||||||
with open(plist, 'w') as f:
|
with open(plist, 'w') as f:
|
||||||
|
|
|
@ -11,8 +11,8 @@ function update() {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
var response = JSON.parse(this.responseText);
|
var response = JSON.parse(this.responseText);
|
||||||
if (response.installing) {
|
if (response.step) {
|
||||||
var status = response.installing;
|
var status = response.step;
|
||||||
if (response.progress) {
|
if (response.progress) {
|
||||||
status = parseInt(response.progress * 100) + '% ' + status;
|
status = parseInt(response.progress * 100) + '% ' + status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue