mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Linux installer: Manually presereve the defaults.list mimetype association file to workaround buggy xdg-desktop-menu implementations in some distros. Fixes #926559 (File associations)
This commit is contained in:
parent
91643b20a3
commit
aba3f4686f
@ -40,6 +40,46 @@ entry_points = {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PreserveMIMEDefaults(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.initial_values = {}
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
def_data_dirs = '/usr/local/share:/usr/share'
|
||||||
|
paths = os.environ.get('XDG_DATA_DIRS', def_data_dirs)
|
||||||
|
paths = paths.split(':')
|
||||||
|
paths.append(os.environ.get('XDG_DATA_HOME', os.path.expanduser(
|
||||||
|
'~/.local/share')))
|
||||||
|
paths = list(filter(os.path.isdir, paths))
|
||||||
|
if not paths:
|
||||||
|
# Env var had garbage in it, ignore it
|
||||||
|
paths = def_data_dirs.split(':')
|
||||||
|
paths = list(filter(os.path.isdir, paths))
|
||||||
|
self.paths = {os.path.join(x, 'applications/defaults.list') for x in
|
||||||
|
paths}
|
||||||
|
self.initial_values = {}
|
||||||
|
for x in self.paths:
|
||||||
|
try:
|
||||||
|
with open(x, 'rb') as f:
|
||||||
|
self.initial_values[x] = f.read()
|
||||||
|
except:
|
||||||
|
self.initial_values[x] = None
|
||||||
|
|
||||||
|
def __exit__(self, *args):
|
||||||
|
for path, val in self.initial_values.iteritems():
|
||||||
|
if val is None:
|
||||||
|
try:
|
||||||
|
os.remove(path)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
elif os.path.exists(path):
|
||||||
|
with open(path, 'r+b') as f:
|
||||||
|
if f.read() != val:
|
||||||
|
f.seek(0)
|
||||||
|
f.truncate()
|
||||||
|
f.write(val)
|
||||||
|
|
||||||
# Uninstall script {{{
|
# Uninstall script {{{
|
||||||
UNINSTALL = '''\
|
UNINSTALL = '''\
|
||||||
#!{python}
|
#!{python}
|
||||||
@ -333,12 +373,10 @@ class PostInstall:
|
|||||||
|
|
||||||
def setup_desktop_integration(self): # {{{
|
def setup_desktop_integration(self): # {{{
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.info('Setting up desktop integration...')
|
self.info('Setting up desktop integration...')
|
||||||
|
|
||||||
|
with TemporaryDirectory() as tdir, CurrentDir(tdir), \
|
||||||
with TemporaryDirectory() as tdir:
|
PreserveMIMEDefaults():
|
||||||
with CurrentDir(tdir):
|
|
||||||
render_img('mimetypes/lrf.png', 'calibre-lrf.png')
|
render_img('mimetypes/lrf.png', 'calibre-lrf.png')
|
||||||
check_call('xdg-icon-resource install --noupdate --context mimetypes --size 128 calibre-lrf.png application-lrf', shell=True)
|
check_call('xdg-icon-resource install --noupdate --context mimetypes --size 128 calibre-lrf.png application-lrf', shell=True)
|
||||||
self.icon_resources.append(('mimetypes', 'application-lrf', '128'))
|
self.icon_resources.append(('mimetypes', 'application-lrf', '128'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user