How to use the xdg.BaseDirectory.save_config_path 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 jrnl-org / jrnl / jrnl / install.py View on Github external
import yaml
import logging
import sys

if "win32" not in sys.platform:
    # readline is not included in Windows Active Python
    import readline

DEFAULT_CONFIG_NAME = "jrnl.yaml"
DEFAULT_JOURNAL_NAME = "journal.txt"
DEFAULT_JOURNAL_KEY = "default"
XDG_RESOURCE = "jrnl"

USER_HOME = os.path.expanduser("~")

CONFIG_PATH = xdg.BaseDirectory.save_config_path(XDG_RESOURCE) or USER_HOME
CONFIG_FILE_PATH = os.path.join(CONFIG_PATH, DEFAULT_CONFIG_NAME)
CONFIG_FILE_PATH_FALLBACK = os.path.join(USER_HOME, ".jrnl_config")

JOURNAL_PATH = xdg.BaseDirectory.save_data_path(XDG_RESOURCE) or USER_HOME
JOURNAL_FILE_PATH = os.path.join(JOURNAL_PATH, DEFAULT_JOURNAL_NAME)

log = logging.getLogger(__name__)


def module_exists(module_name):
    """Checks if a module exists and can be imported"""
    try:
        __import__(module_name)
    except ImportError:
        return False
    else:
github muflone / gnome-appfolders-manager / gnome_appfolders_manager / constants.py View on Github external
if os.path.isfile(os.path.join('data', 'gnome-appfolders-manager.png')):
    DIR_PREFIX = '.'
    DIR_LOCALE = os.path.join(DIR_PREFIX, 'locale')
    DIR_DOCS = os.path.join(DIR_PREFIX, 'doc')
else:
    DIR_PREFIX = os.path.join(sys.prefix, 'share', 'gnome-appfolders-manager')
    DIR_LOCALE = os.path.join(sys.prefix, 'share', 'locale')
    DIR_DOCS = os.path.join(sys.prefix, 'share', 'doc',
                            'gnome-appfolders-manager')
# Set the paths for the folders
DIR_DATA = os.path.join(DIR_PREFIX, 'data')
DIR_UI = os.path.join(DIR_PREFIX, 'ui')
try:
    # In read-only environments, the settings folder cannot be created
    # (eg in a Debian pbuilder fakeroot)
    DIR_SETTINGS = BaseDirectory.save_config_path(DOMAIN_NAME)
except:
    # Get the settings path without actually creating it
    DIR_SETTINGS = os.path.join(BaseDirectory.xdg_config_home, DOMAIN_NAME)
# Set the paths for the data files
FILE_ICON = os.path.join(DIR_DATA, 'gnome-appfolders-manager.png')
FILE_CONTRIBUTORS = os.path.join(DIR_DOCS, 'contributors')
FILE_TRANSLATORS = os.path.join(DIR_DOCS, 'translators')
FILE_LICENSE = os.path.join(DIR_DOCS, 'license')
FILE_RESOURCES = os.path.join(DIR_DOCS, 'resources')
# Set the paths for configuration files
FILE_SETTINGS = os.path.join(DIR_SETTINGS, 'settings.conf')
FILE_WINDOWS_POSITION = os.path.join(DIR_SETTINGS, 'windows.conf')
# Settings schema and paths
SCHEMA_FOLDERS = 'org.gnome.desktop.app-folders'
SCHEMA_FOLDER = '%s.folder' % SCHEMA_FOLDERS
github CMB / cligh / cligh / config.py View on Github external
def get_config_dir():
    """Return the name of the directory containing the application's config file."""
    config_dir = BaseDirectory.load_first_config('cligh')
    if config_dir is None:
        config_dir = BaseDirectory.save_config_path('cligh')
    return config_dir
github timlau / yumex / src / yumexbase / constants.py View on Github external
MAIN_PATH = '/usr/share/yumex'
else:
    MAIN_PATH = BIN_PATH

BUILDER_FILE = MAIN_PATH + '/yumex.glade'
BUILDER_PKGINST = MAIN_PATH + '/pkginst.glade'

if IS_PROD:
    PIXMAPS_PATH = '/usr/share/pixmaps/yumex'
elif MAIN_PATH.endswith('test'):
    PIXMAPS_PATH = MAIN_PATH + '/../../gfx'
else:
    PIXMAPS_PATH = MAIN_PATH + '/../gfx'

OLD_CONF_FILE = os.environ['HOME'] + "/.yumex.conf"
CONF_DIR = BaseDirectory.save_config_path('yumex')
CONF_FILE = os.path.join(CONF_DIR,'yumex.conf')
TIMESTAMP_FILE = os.path.join(CONF_DIR,'update_timestamp.conf')
MIN_UPDATE_INTERVAL = 5


# icons
ICON_YUMEX = PIXMAPS_PATH + "/yumex-icon.png"
ICON_PACKAGES = PIXMAPS_PATH + '/button-packages.png'
ICON_GROUPS = PIXMAPS_PATH + '/button-group.png'
ICON_QUEUE = PIXMAPS_PATH + '/button-queue.png'
ICON_OUTPUT = PIXMAPS_PATH + '/button-output.png'
ICON_REPOS = PIXMAPS_PATH + '/button-repo.png'
ICON_HISTORY = PIXMAPS_PATH + '/button-history.png'
ICON_SPINNER = PIXMAPS_PATH + '/spinner.gif'
ICON_SMALL_SPINNER = PIXMAPS_PATH + '/spinner-small.gif'
ICON_TRAY_ERROR = PIXMAPS_PATH + '/tray-error.png'
github qsniyg / rssit / rssit / config.py View on Github external
def get_save_path(appname):
    return os.path.join(xdg.BaseDirectory.save_config_path(appname), "config.ini")
github zachtib / lookit / src / lookitconfig.py View on Github external
from ConfigParser import RawConfigParser, NoSectionError, NoOptionError
import gconf
import keyring
import os
import subprocess

from xdg import BaseDirectory

CONFIG_DIR = BaseDirectory.save_config_path('lookit')
CONFIG_FILE = os.path.join(CONFIG_DIR, 'config')

try:
    PICTURE_DIR = subprocess.Popen(['xdg-user-dir', 'PICTURES'], \
                stdout=subprocess.PIPE).communicate()[0] \
                .strip('\n')
except OSError:
    PICTURE_DIR = os.path.expanduser('~')

HOTKEY_NAMES = {'capturearea': 'Lookit: Capture Area',
                'capturescreen': 'Lookit: Capture Screen',
                'capturewindow': 'Lookit: Capture Window'}
HOTKEY_IDENTS = {'capturearea': 'lookit_capture_area',
                'capturescreen': 'lookit_capture_screen',
                'capturewindow': 'lookit_capture_window'}
HOTKEY_ACTIONS = {'capturearea': 'lookit --capture-area',
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:
github jonls / redshift / src / redshift-gtk / utils.py View on Github external
def open_autostart_file():
    autostart_dir = base.save_config_path("autostart")
    autostart_file = os.path.join(autostart_dir, REDSHIFT_DESKTOP)

    if not os.path.exists(autostart_file):
        desktop_files = list(base.load_data_paths("applications",
                                                  REDSHIFT_DESKTOP))

        if not desktop_files:
            raise IOError("Installed redshift desktop file not found!")

        desktop_file_path = desktop_files[0]

        # Read installed file
        dfile = desktop.DesktopEntry(desktop_file_path)
        for key, values in AUTOSTART_KEYS:
            dfile.set(key, values[False])
        dfile.write(filename=autostart_file)
github leinardi / gwe / gwe / util / path.py View on Github external
def get_config_path(file: str) -> str:
    return str(Path(BaseDirectory.save_config_path(APP_PACKAGE_NAME)).joinpath(file))