def parse_advise(): #files = [] for f in os.listdir(APP_DIR): if f.endswith('.desktop'): path = os.path.join(APP_DIR, f) fd = os.open(path, os.O_RDONLY) posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_WILLNEED) IniFile(path)
def _read_mimeinfos(self): assert not self.mimeinfos self.mimeinfos = generate_mimeinfo_filenames() for filename in self.mimeinfos: ini = IniFile(filename) group = ini.content.get("MIME Cache") for mime, apps in group.items(): for app in ini.getList(apps): self.add_association(mime, app)
def load_xdg_mime_lists(environment=None): for filename in xdg_mimeapps_files(environment): if os.path.isfile(filename): try: ini_file = IniFile() ini_file.parse(filename) except ParsingError as exc: yield MimeAppsList(filename, None, False, exc) else: yield MimeAppsList(filename, ini_file, True, None)
def from_file(cls, filename, log=None): ini_file = IniFile() try: ini_file.parse(filename) except ParsingError as exc: ini_file = None parsed = False parse_exc = exc else: parsed = True parse_exc = None return cls(filename=filename, ini_file=ini_file, parsed=parsed, parse_exc=parse_exc)
def _read_mimeapps(self): assert not self.mimeapps self.mimeapps = generate_mimeapps_filenames() # Highest priority is first, so we reverse this for filename in reversed(self.mimeapps): ini = IniFile(filename) removed = ini.content.get("Removed Associations", {}) for mime, apps in removed.items(): for app in ini.getList(apps): self.remove_association(mime, app) added = ini.content.get("Added Associations", {}) for mime, apps in added.items(): for app in ini.getList(apps): self.add_association(mime, app) default = ini.content.get("Default Applications", {}) for mime, apps in default.items(): for app in reversed(ini.getList(apps)): self.add_default_app(mime, app)
if headers in content: self.defaultGroup = header break from xdg.IniFile import IniFile path = '/usr/share/applications' apps = [ os.path.join(path, f) for f in os.listdir(path) if f.endswith('.desktop') ] print "Test parsing %s desktop files" % len(apps) start = time.time() for app in apps: res = IniFile(app) end = time.time() print "xdg.IniFile:", end - start IniFile.parse = parse start = time.time() for app in apps: res = IniFile(app) end = time.time() print "Patched xdg.IniFile:", end - start from gi.repository import GLib start = time.time() for app in apps:
glob(os.path.join(path, '*.desktop')) for path in BaseDirectory.load_data_paths('applications') ): desktop = DesktopEntry(dfile) fname = os.path.splitext(os.path.basename(dfile))[0] try: cmd = FILTER.sub('', desktop.getExec()).split(' ', 1) cmd[0] = which(cmd[0]) except ProgramNotFound: continue if desktop.getTerminal(): cmd.insert(0, withpty) #service_path = os.path.join(generator_dir, fname) service_path = os.path.join(generator_dir, fname + "@.service") service = IniFile() service.addGroup('Unit') service.set('SourcePath', dfile, 'Unit') if not desktop.getHidden(): service.set('X-ShowInMenu', "True", 'Unit') service.set('Description', desktop.getName(), 'Unit') service.addGroup('Service') service.set('EnvironmentFile', "%t/sessions/%i/environ", 'Service') service.set('ExecStart', " ".join(cmd), 'Service') service.defaultGroup = 'Unit' service.write(service_path)
def parse(): for f in os.listdir(APP_DIR): if f.endswith('.desktop'): path = os.path.join(APP_DIR, f) IniFile(path)