move launcher installation from installer to oml

This commit is contained in:
Jan Gerber 2015-03-31 20:24:14 +02:00
parent d65ad0e8ea
commit 393fe7eb6e
5 changed files with 116 additions and 67 deletions

57
install
View file

@ -6,12 +6,7 @@ import json
import os
import sys
import tarfile
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
from threading import Thread
import subprocess
@ -59,7 +54,7 @@ class Install(Thread):
with open('config/release.json', 'w') as fd:
json.dump(release, fd, indent=2)
if sys.platform == 'darwin':
self.install_launchd()
os.system('./ctl install_launcher')
elif sys.platform.startswith('linux'):
apt_packages = ''
yum_packages = ''
@ -88,7 +83,7 @@ class Install(Thread):
print('You need to install pdftocairo (part of poppler-utils)')
if 'miredo' in apt_packages:
print('You need to install miredo (or get IPv6 in another way)')
self.install_application()
os.system('./ctl install_launcher')
self.status['done'] = True
def download(self, url, filename):
@ -112,54 +107,6 @@ class Install(Thread):
data = json.loads(u.read().decode('utf-8'))
return data
def install_application(self):
app = os.path.expanduser('~/.local/share/applications/openmedialibrary.desktop')
with open(app, 'w') as fd:
fd.write('''[Desktop Entry]
Type=Application
Name=Open Media Library
Comment=Open Media Library
Exec=%s/ctl open
Icon=%s/openmedialibrary/static/png/oml.png
Terminal=false
Categories=Network;FileTransfer;P2P;
''' % (self.target, self.target))
start = os.path.expanduser('~/.config/autostart/openmedialibrary.desktop')
makefolder(start)
with open(start, 'w') as fd:
fd.write('''[Desktop Entry]
Type=Application
Exec=%s/ctl start
Icon=%s/openmedialibrary/static/png/oml.png
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Start Open Media Library
Comment=
''' % (self.target, self.target))
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')
def url(self, url):
return self.base_url + url

View file

@ -9,19 +9,10 @@ import sys
import shutil
import settings
from utils import run, get
root_dir = dirname(settings.base_dir)
def run(*cmd):
p = subprocess.Popen(cmd, close_fds=True)
p.wait()
return p.returncode
def get(*cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
stdout, error = p.communicate()
return stdout.decode()
def r(*cmd):
print(' '.join(cmd))
return subprocess.call(cmd)
@ -64,6 +55,20 @@ def command_stop(*args):
"""
pass
def command_install_launcher(*args):
"""
Install launcher
"""
import integration
integration.install_launcher()
def command_uninstall_launcher(*args):
"""
Uninstall launcher
"""
import integration
integration.uninstall_launcher()
def command_install_update(*args):
"""
Install available updates

82
oml/integration.py Normal file
View file

@ -0,0 +1,82 @@
import os
import sys
import settings
from utils import run, makefolder
root_dir = os.path.dirname(settings.base_dir)
def install_launcher():
if sys.platform == 'darwin':
install_launchd()
elif sys.platform.startswith('linux'):
install_xdg()
else:
print('no launcher integration supported for %s' % sys.platform)
def uninstall_launcher():
if sys.platform == 'darwin':
name = 'com.openmedialibrary.loginscript'
plist = os.path.expanduser('~/Library/LaunchAgents/%s.plist'%name)
if os.path.exists(plist):
run('launchctl', 'stop', name)
run('launchctl', 'unload', plist)
os.unlink(plist)
elif sys.platform.startswith('linux'):
for f in map(os.path.expanduser, [
'~/.local/share/applications/openmedialibrary.desktop',
'~/.config/autostart/openmedialibrary.desktop'
]):
if os.path.exists(f):
os.unlink(f)
def install_launchd():
name = 'com.openmedialibrary.loginscript'
plist = os.path.expanduser('~/Library/LaunchAgents/%s.plist'%name)
if os.path.exists(plist):
run('launchctl', 'stop', name)
run('launchctl', 'unload', plist)
with open(plist, 'w') as f:
f.write('''<?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>Label</key>
<string>%s</string>
<key>ProgramArguments</key>
<array>
<string>%s/ctl</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>''' % (name, root_dir))
run('launchctl', 'load', plist)
run('launchctl', 'start', name)
def install_xdg():
app = os.path.expanduser('~/.local/share/applications/openmedialibrary.desktop')
with open(app, 'w') as fd:
fd.write('''[Desktop Entry]
Type=Application
Name=Open Media Library
Comment=Open Media Library
Exec=%(base)s/ctl open
Icon=%(base)s/openmedialibrary/static/png/oml.png
Terminal=false
Categories=Network;FileTransfer;P2P;
''' % {'base': root_dir})
start = os.path.expanduser('~/.config/autostart/openmedialibrary.desktop')
makefolder(start)
with open(start, 'w') as fd:
fd.write('''[Desktop Entry]
Type=Application
Name=Start Open Media Library
Exec=%(base)s/ctl start
Icon=%(base)s/openmedialibrary/static/png/oml.png
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
''' % {'base': root_dir})

View file

@ -230,3 +230,18 @@ def datetime2ts(dt):
def ts2datetime(ts):
return datetime.utcfromtimestamp(float(ts))
def run(*cmd):
p = subprocess.Popen(cmd, close_fds=True)
p.wait()
return p.returncode
def get(*cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
stdout, error = p.communicate()
return stdout.decode()
def makefolder(path):
dirname = os.path.dirname(path)
if not os.path.exists(dirname):
os.makedirs(dirname)

View file

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>Open Media Library</title>
<link href="../oxjs/min/UI/css/UI.css" rel="stylesheet" type="text/css" />
<link href="../../../oxjs/min/UI/css/UI.css" rel="stylesheet" type="text/css" />
<style>
#loading {
text-align: center;