mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Start linux implementation of Open with
This commit is contained in:
parent
eed947ae57
commit
9dee96270b
43
src/calibre/gui2/open_with.py
Normal file
43
src/calibre/gui2/open_with.py
Normal file
@ -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 <kovid at kovidgoyal.net>'
|
||||
|
||||
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()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user