import os import sys import settings 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(): 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(''' Label %s ProgramArguments %s/ctl start RunAtLoad ''' % (name, root_dir)) run('launchctl', 'load', plist) run('launchctl', 'start', name) def install_xdg(): app = os.path.expanduser('~/.local/share/applications/openmedialibrary.desktop') ox.makedirs(os.path.dirname(app)) with open(app, 'w') as fd: fd.write('''[Desktop Entry] Type=Application Name=Open Media Library 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})