예제 #1
0
    def activate(self):
        """
        Displays gajim in the Messaging Menu.
        """
        if not HAS_INDICATE:
            raise GajimPluginException("python-indicate is missing!")
        if not HAS_PYXDG:
            raise GajimPluginException("python-xdg is missing!")

        self.server = indicate.indicate_server_ref_default()
        self.server.set_type("message.im")
        self.server.connect("server-display", self.on_server_activate)
        dfile = ""
        for file in load_data_paths("applications/gajim.desktop"):
            dfile = file
            break
        if not dfile:
            raise GajimPluginException("Can't locate gajim.desktop!")
        self.server.set_desktop_file(dfile)
        self.server.show()

        # {(account, jid): (indicator, [event, ...]), ...}
        self.events = {}

        gajim.events.event_added_subscribe(self.on_event_added)
        gajim.events.event_removed_subscribe(self.on_event_removed)
예제 #2
0
def find_desktop_files():
    filenames = set()
    for root, dirs, files in chain(*map(os.walk,
                                        load_data_paths("applications"))):
        for desktop_file in fnmatch.filter(files, "*.desktop"):
            if desktop_file not in filenames:
                filenames.add(desktop_file)
                yield os.path.join(root, desktop_file)
예제 #3
0
def load_base_colour_scheme():
    kdeglobals = ConfigParser()
    kdeglobals.read(load_first_config("kdeglobals"))
    base_colour_scheme = kdeglobals["General"]["ColorScheme"]

    for color_schemes_dir in load_data_paths("color-schemes"):
        for filename in os.listdir(color_schemes_dir):
            if filename == "{}.colors".format(base_colour_scheme):
                colour_scheme = ConfigParser()
                colour_scheme.read(os.path.join(color_schemes_dir, filename))
                return colour_scheme

    raise EnvironmentError(("Could not find colour scheme {}"
                            ).format(base_colour_scheme))
예제 #4
0
def parse_args():
    parser = argparse.ArgumentParser('i3hub')
    parser.add_argument('--load', action='append', default=[])
    data_dirs = list(
            list(load_config_paths('i3hub')) + list(load_data_paths('i3hub')))
    extension_path = ':'.join('{}/extensions'.format(p) for p in data_dirs)
    parser.add_argument('--extension-path', default=extension_path)
    config_candidates = list(c for c in
            (os.path.join(p, 'i3hub.cfg') for p in data_dirs)
            if os.path.exists(c))
    if not config_candidates:
        config_candidates.append('{}/i3hub/i3hub.cfg'.format(xdg_config_home))
    parser.add_argument('-c', '--config', default=config_candidates[0])
    extra_config_dirs = reversed(list(d for d in
            (os.path.join(p, 'config.d') for p in data_dirs)
            if os.path.isdir(d)))
    parser.add_argument('--extra-config-dirs',
            default=':'.join(extra_config_dirs))
    parser.add_argument('--run-as-status', default=False, action='store_true')
    parser.add_argument('--log-file', default=None)
    return parser.parse_args()
예제 #5
0
import re
import shlex
import subprocess
from functools import partial
from pathlib import Path

from collections import namedtuple

from xdg.BaseDirectory import load_data_paths
from xdg.DesktopEntry import DesktopEntry
from xdg.IconTheme import getIconPath

from PyQt5.QtCore import QProcess


class App(namedtuple('App', 'name icon launch')):
    def __new__(cls, desk):
        desk = DesktopEntry(str(a))
        name = desk.getName()
        icon = getIconPath(desk.getIcon())
        exe = shlex.split(re.sub('%[fFuUdDnNickvm]', '', desk.getExec()))
        launch = partial(QProcess.startDetached, exe[0], exe[1:])
        return super().__new__(cls, name, icon, launch)


apps = []
for d in load_data_paths('applications'):
    for a in Path(d).glob('*.desktop'):
        apps.append(App(a))
예제 #6
0
#!/usr/bin/env python3
# Author: Juho Teperi

from xdg.BaseDirectory import load_data_paths
from xdg.DesktopEntry import DesktopEntry
from glob import glob
from re import sub
from os.path import basename

# To remove duplicates
data = {}

for d in load_data_paths("applications"):
    for app in glob(d + "/*.desktop"):
        desktop = DesktopEntry(app)
        name = desktop.getName()

        if (not desktop.getHidden() and not desktop.getNoDisplay()) and name not in data:
            data[name] = basename(app)

for name, cmd in data.items():
    print('{}\t{}'.format(name, cmd))
예제 #7
0
파일: setup.py 프로젝트: StyXman/pbt
Distribution(dict(setup_requires="pyxdg==0.25"))

from os.path import join
from xdg.BaseDirectory import save_data_path, load_data_paths

# plugins
# according to the Debian Python Policy, they should go in /usr/share/<program>
# NOTE: for the time being, we're gonna install them in the user's xdg.data dir

# first, make sure the dir exists
save_data_path("pbt/")
save_data_path("pbt/plugins/")

# the user's dir comes first
user_xdg_data_dir = next(load_data_paths('pbt/plugins/'))

setup(
    name='pbt',
    version='0.0.1',
    description='python build tool',
    url='https://github.com/pebete/pbt',
    packages=['pbt'],
    scripts=['bin/pbt'],
    license='Apache 2.0',
    install_requires=["PyYAML==3.10", "flake8==2.0", "cookiecutter==0.7.0", "pyxdg==0.25"],
    data_files=[
        (join(user_xdg_data_dir, 'dump'), ['plugins/dump/main.py', ]),
        (join(user_xdg_data_dir, 'help'), ['plugins/help/main.py', ]),
        (join(user_xdg_data_dir, 'try'), ['plugins/try/main.py', ]),
        (join(user_xdg_data_dir, 'install'), ['plugins/install/main.py', ]),
예제 #8
0
def xdg_desktop_files():
    '''Yields .desktop files in the XDG data applications paths.'''
    for directory in load_data_paths('applications'):
        desktop_glob = os.path.join(directory, '**/*.desktop')
        for filepath in iglob(desktop_glob, recursive=True):
            yield filepath
예제 #9
0
from collections import defaultdict
from functools import total_ordering
import os
import os.path

import attr
from twisted.python.failure import Failure
from xdg.BaseDirectory import load_data_paths

from korbenware.logger import create_logger
from korbenware.keys import keys
from korbenware.presentation import representable
from korbenware.presentation.markdown import markdownable
from korbenware.xdg.executable import Executable

XDG_APPLICATIONS_DIRS = list(load_data_paths("applications"))


@total_ordering
@markdownable
@representable
@attr.s(order=False)
class Application:
    fullpath = attr.ib()
    filename = attr.ib()
    executable = attr.ib()
    overrides = attr.ib(default=None)

    @classmethod
    def from_path(cls, fullpath):
        """