Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A protoype of a update script for the hardware mimetypes
#!/usr/bin/env python
from xdg import BaseDirectory
from xdg.IniFile import IniFile
from os import path
from glob import glob
desktop_files = []
for dirname in BaseDirectory.xdg_data_dirs:
desktops_path = path.join(dirname, 'applications/*.desktop')
desktop_files += glob(desktops_path)
mimes = {}
for desktop in desktop_files:
desktop_ini = IniFile(filename=desktop)
desktop_entry = desktop_ini.content.get('Desktop Entry')
if not desktop_entry.has_key('X-HwType'):
continue
desktop_mimes = desktop_entry.get('X-HwType')
if desktop_mimes.endswith(';'):
desktop_mimes = desktop_mimes.strip(';')
desktop_mimes = desktop_mimes.split(';')
desktop_file = path.basename(desktop)
for mime in desktop_mimes:
if mimes.has_key(mime):
mimes[mime] = mimes[mime] + desktop_file + ';'
else:
mimes[mime] = desktop_file + ';'
mimeapps = BaseDirectory.xdg_data_dirs[0]
for mime in mimes:
mimeapps.content['Default Applications'][mime] = mimes[mime]
mimeapps.write()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment