commit b7c6c44cd1844f3a7bb3454e30d228837bb63d57 Author: j Date: Wed Jan 27 23:39:58 2016 +0530 openmedialibrary-linux-package diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4325c8b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +debian/debhelper-build-stamp +debian/files +debian/openmedialibrary.debhelper.log +debian/openmedialibrary.substvars +debian/openmedialibrary/ +debian/stamp-makefile-build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..455335b --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +VERSION=0.1 +PROG = bin/openmedialibrary + +PREFIX ?= /usr +BINDIR ?= ${DESTDIR}${PREFIX}/bin +SHAREDIR ?= ${DESTDIR}${PREFIX}/share + +INSTALL = install + +all: ${PROG} ${DESKTOP} + +install: ${PROG} + @mkdir -p "${SHAREDIR}/applications" + @mkdir -p "${BINDIR}" + ${INSTALL} -m 555 -o root -g root ${PROG} ${BINDIR} + ${INSTALL} -m 755 -o root -g root -d ${SHAREDIR}/openmedialibrary + ${INSTALL} -m 444 -o root openmedialibrary.desktop ${SHAREDIR}/applications/openmedialibrary.desktop + @cp -r openmedialibrary ${SHAREDIR} + @chown -R root:root ${SHAREDIR}/openmedialibrary + +clean: + +uninstall: + @rm -rf ${BINDIR}/${PROG} ${SHAREDIR}/openmedialibrary ${SHAREDIR}/applications/openmedialibrary.desktop + +dist: + git archive --format=tar --prefix=openmedialibrary-${VERSION}/ master | xz >openmedialibrary-${VERSION}.tar.xz + +PKGBUILD: PKGBUILD.in dist + sed -e "s/VERSION/${VERSION}/g" -e "s/SHA1SUM/`sha1sum openmedialibrary-${VERSION}.tar.xz | cut -f1 -d' '`/g" PKGBUILD.in > PKGBUILD + +.PHONY: all install uninstall dist diff --git a/bin/openmedialibrary b/bin/openmedialibrary new file mode 100755 index 0000000..27cb7b4 --- /dev/null +++ b/bin/openmedialibrary @@ -0,0 +1,163 @@ +#!/usr/bin/python3 +# GPL3 2016 j +from __future__ import division, with_statement + +from contextlib import closing +import json +import os +import sys +import time +import tarfile +from urllib.request import urlopen +import http.server +import socketserver +from threading import Thread +import subprocess +import webbrowser + + +PORT = 9841 +static_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'openmedialibrary')) +if not os.path.exists(static_dir): + static_dir = '/usr/share/openmedialibrary' + +def makedirs(dirname): + if not os.path.exists(dirname): + os.makedirs(dirname) + +def get_platform(): + name = sys.platform + if name.startswith('darwin'): + name = 'darwin64' + elif name.startswith('linux'): + import platform + if platform.architecture()[0] == '64bit': + name = 'linux64' + else: + name = 'linux32' + return name + +class Handler(http.server.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).encode() + 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, 'rb') as fd: + content = fd.read() + self.send_response(200, 'OK') + content_type = { + 'html': 'text/html', + 'png': 'image/png', + 'svg': 'image/svg+xml', + 'txt': 'text/plain', + }.get(path.split('.')[-1], 'txt') + self.send_header('Content-Type', content_type) + else: + self.send_response(404, 'not found') + content = b'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 = { + 'step': 'Downloading...' + } + + 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): + webbrowser.open('http://127.0.0.1:%s'%PORT) + target = self.target + makedirs(target) + os.chdir(target) + self.status["step"] = 'Downloading...' + release = self.get_release() + self.status["release"] = release + self.status["progress"] = 0 + platform = get_platform() + for module in sorted(release['modules']): + if release['modules'][module].get('platform', platform) == platform: + package_tar = release['modules'][module]['name'] + url = self.release_url.replace('release.json', package_tar) + self.download(url, package_tar) + self.status["step"] = 'Installing...' + for module in sorted(release['modules']): + if release['modules'][module].get('platform', platform) == platform: + package_tar = release['modules'][module]['name'] + tar = tarfile.open(package_tar) + tar.extractall() + tar.close() + os.unlink(package_tar) + os.symlink('openmedialibrary/ctl', 'ctl') + makedirs('data') + with open('data/release.json', 'w') as fd: + json.dump(release, fd, indent=2) + self.status = {"relaunch": True} + os.system("./ctl start &") + time.sleep(5) + self.httpd.shutdown() + + def download(self, url, filename): + dirname = os.path.dirname(filename) + if dirname: + makedirs(dirname) + with open(filename, 'wb') as f: + with closing(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) + f.write(data) + data = u.read(4096) + + def get_release(self): + with closing(urlopen(self.release_url)) as u: + data = json.loads(u.read().decode()) + return data + +class Server(socketserver.ThreadingMixIn, socketserver.TCPServer): + allow_reuse_address = True + +def run(target): + httpd = Server(("", PORT), Handler) + install = Install(target, httpd) + httpd.install = install + httpd.serve_forever() + +if __name__ == '__main__': + if len(sys.argv) == 1: + target = os.path.expanduser('~/.local/share/openmedialibrary') + elif len(sys.argv) != 2: + print('usage: %s [target]' % sys.argv[0]) + sys.exit(1) + else: + target = sys.argv[1] + if os.path.exists(target): + subprocess.Popen([os.path.join(target, 'ctl'), 'open']) + else: + run(target) diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..cbb439a --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +openmedialibrary (0.1) unstable; urgency=medium + + * Initial release. + + -- Jan Gerber Wed, 27 Jan 2016 22:07:26 +0530 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..7fc7f7a --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: openmedialibrary +Maintainer: Jan Gerber +Section: text +Priority: optional +Build-Depends: debhelper (>= 9) +Standards-Version: 3.9.6 + +Package: openmedialibrary +Architecture: all +Depends: ${misc:Depends}, python3, + python3-pil, python3-lxml, python3-openssl (>= 0.15), python3-crypto, + poppler-utils, gir1.2-gtk-3.0 +Description: Open Media Library + manage and sync your digital media collections diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..ab49fd2 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,12 @@ +This package was debianized by Jan Gerber on +Wed Jan 27 23:54:31 IST 2016 + + +It was downloaded with git clone https://git.0x2620.org/openmedialibrary-linux-package + +Upstream Authors: 0x2620 <0x2620@0x2620.org> + +Copyright: GPL3 + +You can find the mentioned GNU General Public License 3 (GPL3) (on a +Debian system) in the file /usr/share/common-licenses/GPL-3. diff --git a/debian/openmedialibrary.dirs b/debian/openmedialibrary.dirs new file mode 100644 index 0000000..8fa061d --- /dev/null +++ b/debian/openmedialibrary.dirs @@ -0,0 +1,2 @@ +usr/bin +usr/share/applications diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..f8ce557 --- /dev/null +++ b/debian/rules @@ -0,0 +1,6 @@ +#!/usr/bin/make -f +%: + dh $@ + +override_dh_auto_install: + $(MAKE) DESTDIR=$$(pwd)/debian/openmedialibrary PREFIX=/usr install diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/openmedialibrary.desktop b/openmedialibrary.desktop new file mode 100644 index 0000000..c7d1830 --- /dev/null +++ b/openmedialibrary.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=Open Media Library +Keywords=OpenMediaLibrary OML +Comment=manage and sync your digital media collections +Exec=/usr/bin/openmedialibrary +Icon=/usr/share/openmedialibrary/svg/oml.svg +Terminal=false +Categories=Network;FileTransfer;P2P; diff --git a/openmedialibrary/index.html b/openmedialibrary/index.html new file mode 100644 index 0000000..dcda6dc --- /dev/null +++ b/openmedialibrary/index.html @@ -0,0 +1,11 @@ + + + + Open Media Library + + + + + + + diff --git a/openmedialibrary/js/install.js b/openmedialibrary/js/install.js new file mode 100644 index 0000000..1a5f7e6 --- /dev/null +++ b/openmedialibrary/js/install.js @@ -0,0 +1,148 @@ +'use strict'; + +(function() { + + loadImages(function(images) { + loadScreen(images); + initUpdate(); + }); + + function initUpdate(browserSupported) { + window.update = {}; + update.status = document.createElement('div'); + update.status.className = 'OxElement'; + update.status.style.position = 'absolute'; + update.status.style.left = '16px'; + update.status.style.top = '336px'; + update.status.style.right = 0; + update.status.style.bottom = 0; + update.status.style.width = '512px'; + update.status.style.height = '16px'; + update.status.style.margin = 'auto'; + update.status.style.textAlign = 'center'; + update.status.style.color = 'rgb(16, 16, 16)'; + update.status.style.fontFamily = 'Lucida Grande, Segoe UI, DejaVu Sans, Lucida Sans Unicode, Helvetica, Arial, sans-serif'; + update.status.style.fontSize = '11px'; + document.querySelector('#loadingScreen').appendChild(update.status); + update.status.innerHTML = ''; + updateStatus(); + } + + 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 loadImages(callback) { + var images = {}; + images.logo = document.createElement('img'); + images.logo.onload = function() { + images.logo.style.position = 'absolute'; + images.logo.style.left = 0; + images.logo.style.top = 0; + images.logo.style.right = 0; + images.logo.style.bottom = '96px'; + images.logo.style.width = '256px'; + images.logo.style.height = '256px'; + images.logo.style.margin = 'auto'; + images.logo.style.MozUserSelect = 'none'; + images.logo.style.MSUserSelect = 'none'; + images.logo.style.OUserSelect = 'none'; + images.logo.style.WebkitUserSelect = 'none'; + images.loadingIcon = document.createElement('img'); + images.loadingIcon.setAttribute('id', 'loadingIcon'); + images.loadingIcon.style.position = 'absolute'; + images.loadingIcon.style.left = '16px'; + images.loadingIcon.style.top = '256px' + images.loadingIcon.style.right = 0; + images.loadingIcon.style.bottom = 0; + images.loadingIcon.style.width = '32px'; + images.loadingIcon.style.height = '32px'; + images.loadingIcon.style.margin = 'auto'; + images.loadingIcon.style.MozUserSelect = 'none'; + images.loadingIcon.style.MSUserSelect = 'none'; + images.loadingIcon.style.OUserSelect = 'none'; + images.loadingIcon.style.WebkitUserSelect = 'none'; + images.loadingIcon.src = '/svg/symbolLoading.svg'; + callback(images); + }; + images.logo.src = '/png/oml.png'; + } + + function loadScreen(images) { + var loadingScreen = document.createElement('div'); + loadingScreen.setAttribute('id', 'loadingScreen'); + loadingScreen.className = 'OxScreen'; + loadingScreen.style.position = 'absolute'; + loadingScreen.style.width = '100%'; + loadingScreen.style.height = '100%'; + loadingScreen.style.backgroundColor = 'rgb(224, 224, 224)'; + loadingScreen.style.zIndex = '1002'; + loadingScreen.appendChild(images.logo); + loadingScreen.appendChild(images.loadingIcon); + // FF3.6 document.body can be undefined here + window.onload = function() { + document.body.style.margin = 0; + document.body.appendChild(loadingScreen); + startAnimation(); + }; + // IE8 does not call onload if already loaded before set + document.body && window.onload(); + } + + + function startAnimation() { + var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'), + previousTime = +new Date(); + var animationInterval = setInterval(function() { + var currentTime = +new Date(), + delta = (currentTime - previousTime) / 1000; + previousTime = currentTime; + deg = Math.round((deg + delta * 360) % 360 / 30) * 30; + css = 'rotate(' + deg + 'deg)'; + loadingIcon.style.MozTransform = css; + loadingIcon.style.MSTransform = css; + loadingIcon.style.OTransform = css; + loadingIcon.style.WebkitTransform = css; + loadingIcon.style.transform = css; + }, 83); + } + + function updateStatus() { + 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; + } + update.status.innerHTML = status; + setTimeout(updateStatus, 1000); + } else { + update.status.innerHTML = 'Relaunching...'; + setTimeout(load, 500); + } + }; + xhr.onerror = function() { + var status = update.status.innerHTML; + if (['Relaunching...', ''].indexOf(status) == -1) { + update.status.innerHTML = 'Installation failed'; + } + load(); + } + xhr.open('get', '/status'); + xhr.send(); + } + +}()); diff --git a/openmedialibrary/png/oml.png b/openmedialibrary/png/oml.png new file mode 100644 index 0000000..9bf0dc7 Binary files /dev/null and b/openmedialibrary/png/oml.png differ diff --git a/openmedialibrary/svg/oml.svg b/openmedialibrary/svg/oml.svg new file mode 100644 index 0000000..d7b9e9b --- /dev/null +++ b/openmedialibrary/svg/oml.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/openmedialibrary/svg/symbolLoading.svg b/openmedialibrary/svg/symbolLoading.svg new file mode 100644 index 0000000..eca747e --- /dev/null +++ b/openmedialibrary/svg/symbolLoading.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file