예제 #1
0
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)
예제 #2
0
    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)
예제 #3
0
파일: mime.py 프로젝트: disco0/public
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)
예제 #4
0
파일: mime.py 프로젝트: disco0/public
    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)
예제 #5
0
    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)
예제 #6
0
파일: inifile.py 프로젝트: ju1ius/uxdgmenu
            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)
예제 #8
0
def parse():
    for f in os.listdir(APP_DIR):
        if f.endswith('.desktop'):
            path = os.path.join(APP_DIR, f)
            IniFile(path)