From 9dee96270bf1552f72bb157f5da16e54680606f5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 18 Feb 2015 22:10:12 +0530 Subject: [PATCH] Start linux implementation of Open with --- src/calibre/gui2/open_with.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/calibre/gui2/open_with.py diff --git a/src/calibre/gui2/open_with.py b/src/calibre/gui2/open_with.py new file mode 100644 index 0000000000..7297a42a3c --- /dev/null +++ b/src/calibre/gui2/open_with.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python2 +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2015, Kovid Goyal ' + +import os + +from calibre import force_unicode, walk +from calibre.constants import iswindows, isosx, filesystem_encoding + +if iswindows: + pass +elif isosx: + pass +else: + def parse_desktop_file(path): + try: + with open(path, 'rb') as f: + raw = f.read() + raw + except EnvironmentError: + return + + def find_programs(extensions): + extensions = {ext.lower() for ext in extensions} + data_dirs = [os.environ.get('XDG_DATA_HOME') or os.path.expanduser('~/.local/share')] + data_dirs += (os.environ.get('XDG_DATA_DIRS') or '/usr/local/share/:/usr/share/').split(os.pathsep) + data_dirs = [force_unicode(x, filesystem_encoding).rstrip(os.sep) for x in data_dirs] + data_dirs = [x for x in data_dirs if x and os.path.isdir(x)] + desktop_files = {} + for base in data_dirs: + for f in walk(os.path.join(base, 'applications')): + if f.endswith('.desktop'): + bn = os.path.basename(f) + if f not in desktop_files: + desktop_files[bn] = f + +if __name__ == '__main__': + print (find_programs('jpg jpeg'.split())) +