openmedialibrary/oml/integration.py

75 lines
2.2 KiB
Python
Raw Normal View History

import os
import sys
import settings
2016-01-17 06:44:08 +00:00
import ox
from utils import run
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():
2015-11-02 23:28:09 +00:00
return
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')
2016-01-17 06:44:08 +00:00
ox.makedirs(os.path.dirname(app))
with open(app, 'w') as fd:
fd.write('''[Desktop Entry]
Type=Application
Name=Open Media Library
2016-01-09 10:55:49 +00:00
Keywords=OpenMediaLibrary OML
Comment=manage and sync your digital media collections
Exec=%(base)s/ctl open
Icon=%(base)s/openmedialibrary/static/png/oml.png
Terminal=false
Categories=Network;FileTransfer;P2P;
''' % {'base': root_dir})