How to use the xdg.BaseDirectory.load_first_config function in xdg

To help you get started, we’ve selected a few xdg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github takluyver / pyxdg / test / test-basedirectory.py View on Github external
def test_load_first_config(self):
        tmpdir = tempfile.mkdtemp()
        tmpdir2 = tempfile.mkdtemp()
        tmpdir3 = tempfile.mkdtemp()
        path = os.path.join(tmpdir3, "wpokewefketnrhruit")
        os.mkdir(path)
        try:
            environ['XDG_CONFIG_HOME'] = tmpdir
            environ['XDG_CONFIG_DIRS'] = ":".join([tmpdir2, tmpdir3])
            reload(BaseDirectory)
            configdir = BaseDirectory.load_first_config("wpokewefketnrhruit")
            self.assertEqual(configdir, path)
        finally:
            shutil.rmtree(tmpdir)
            shutil.rmtree(tmpdir2)
            shutil.rmtree(tmpdir3)
github denilsonsa / arandr-indicator / arandr-indicator.py View on Github external
def am_i_in_autostart(self):
        try:
            filename= xdg.BaseDirectory.load_first_config(
                'autostart/arandr-indicator.desktop')
            if not filename:
                return False

            entry = xdg.DesktopEntry.DesktopEntry()
            entry.parse(filename)
            return entry.get('Exec') == self.SELF_PATH
        except:
            return False
github SpotlightKid / jack-select / jackselect / jackselect.py View on Github external
def load_presets(self, force=False):
        if self.qjackctl_config in (None, DEFAULT_CONFIG):
            qjackctl_config = xdgbase.load_first_config(*DEFAULT_CONFIG)
        else:
            if os.access(self.qjackctl_config, os.R_OK):
                qjackctl_config = self.qjackctl_config
            else:
                qjackctl_config = None

        if qjackctl_config:
            mtime = os.path.getmtime(qjackctl_config)
            changed = mtime > getattr(self, '_conf_mtime', 0)

            if changed:
                log.debug("JACK configuration file mtime changed or previously unknown.")

            if force or changed or self.presets is None:
                log.debug("(Re-)Reading configuration.")
                (
github languitar / pass-git-helper / passgithelper.py View on Github external
XDG location is used.
    """
    LOGGER.debug("Parsing mapping file. Command line: %s", mapping_file)

    def parse(mapping_file):
        config = configparser.ConfigParser()
        config.read_file(mapping_file)
        return config

    # give precedence to the user-specified file
    if mapping_file is not None:
        LOGGER.debug("Parsing command line mapping file")
        return parse(mapping_file)

    # fall back on XDG config location
    xdg_config_dir = xdg.BaseDirectory.load_first_config("pass-git-helper")
    if xdg_config_dir is None:
        raise RuntimeError(
            "No mapping configured so far at any XDG config location. "
            "Please create {config_file}".format(config_file=DEFAULT_CONFIG_FILE)
        )
    mapping_file = os.path.join(xdg_config_dir, CONFIG_FILE_NAME)
    LOGGER.debug("Parsing mapping file %s", mapping_file)
    with open(mapping_file, "r") as file_handle:
        return parse(file_handle)
github lantw44 / ceiba-dl / ceiba_dl / config.py View on Github external
def load(self):
        # 我們只有個人設定檔,沒有全域設定檔
        conf_path = xdg.BaseDirectory.load_first_config(self.name, self.profile)

        # 檔案不存在就算了
        if not conf_path:
            return True

        self._logger.info('準備讀取設定檔 {}'.format(conf_path))

        try:
            conf_file = open(conf_path, 'r')
        except IOError as err:
            self._logger.error('無法開啟設定檔:{}'.format(err))
            return True

        try:
            self._config.read_file(conf_file)
        except configparser.Error as err:
github xiaq / udevedu / udevedu / __init__.py View on Github external
def main():
    loglevel = logging.WARN
    if len(sys.argv) == 2 and sys.argv[1] == '-d':
        loglevel = logging.INFO
    logging.basicConfig(
        level=loglevel,
        format='%(asctime)s %(levelname)s %(message)s',
        datefmt='%F %T'
    )

    save_config_path('udevedu', 'hooks')
    hooks_dir = load_first_config('udevedu', 'hooks')

    hooks = load_hooks(hooks_dir)

    try:
        context = pyudev.Context()
        monitor = pyudev.Monitor.from_netlink(context)

        while True:
            try:
                for args in monitor:
                    # args is (action, device)
                    for h in hooks:
                        spawn_partial(process_hook, h, args)
            except IOError as e:
                if e.errno == errno.EINTR:
                    continue