How to use the xdg.BaseDirectory.xdg_data_home 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 ubuntu / ubuntu-make / umake / settings.py View on Github external
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import os
import requests
import re
from xdg.BaseDirectory import xdg_data_home

DEFAULT_INSTALL_TOOLS_PATH = os.path.expanduser(os.path.join(xdg_data_home, "umake"))
DEFAULT_BINARY_LINK_PATH = os.path.expanduser(os.path.join(DEFAULT_INSTALL_TOOLS_PATH, "bin"))
OLD_CONFIG_FILENAME = "udtc"
CONFIG_FILENAME = "umake"
OS_RELEASE_FILE = "/etc/os-release"
UMAKE_FRAMEWORKS_ENVIRON_VARIABLE = "UMAKE_FRAMEWORKS"

from_dev = False


def get_version():
    '''Get version depending if on dev or released version'''
    version = open(os.path.join(os.path.dirname(__file__), 'version'), 'r', encoding='utf-8').read().strip()
    if not from_dev:
        snap_appendix = ''
        snap_rev = os.getenv('SNAP_REVISION')
        if snap_rev:
github projecthamster / hamster / src / hamster / lib / configuration.py View on Github external
def __init__(self):
        self.version = hamster.__version__
        if hamster.installed:
            from hamster import defs  # only available when running installed
            self.data_dir = os.path.join(defs.DATA_DIR, "hamster")
        else:
            # running from sources
            module_dir = os.path.dirname(os.path.realpath(__file__))
            self.data_dir = os.path.join(module_dir, '..', '..', '..', 'data')

        self.data_dir = os.path.realpath(self.data_dir)
        self.storage = Storage()
        self.home_data_dir = os.path.realpath(os.path.join(xdg_data_home, "hamster"))
github kupferlauncher / kupfer / kupfer / plugin / notes.py View on Github external
def initialize(self):
        """Set up filesystem monitors to catch changes"""
        # We monitor all directories that exist of a couple of candidates
        dirs = []
        for program in PROGRAM_IDS:
            notedatapaths = (os.path.join(base.xdg_data_home, program),
                    os.path.expanduser("~/.%s" % program))
            dirs.extend(notedatapaths)
        self.monitor_token = self.monitor_directories(*dirs)

        set_prog = __kupfer_settings__["notes_application"]
        if set_prog in PROGRAM_SERIVCES:
            bus_name = PROGRAM_SERIVCES[set_prog][0]
            bus = dbus.SessionBus()
            dbus_signal_connect_weakly(bus, "NameOwnerChanged", self._name_owner_changed,
                                       dbus_interface="org.freedesktop.DBus",
                                       arg0=bus_name)
github lutris / lutris / lutris / constants.py View on Github external
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see .
#
""" Constants module, soon to be deprecated. Replaced by settings module. """

from os.path import join
from xdg import BaseDirectory

PROTOCOL_VERSION = 1
CONFIG_EXTENSION = ".yml"


LUTRIS_CONFIG_PATH = join(BaseDirectory.xdg_config_home, 'lutris')
LUTRIS_DATA_PATH = join(BaseDirectory.xdg_data_home, 'lutris')
LUTRIS_CACHE_PATH = join(BaseDirectory.xdg_cache_home, 'lutris')

RUNNER_CONFIG_PATH = join(LUTRIS_CONFIG_PATH, 'runners')
GAME_CONFIG_PATH = join(LUTRIS_CONFIG_PATH, 'games')
COVER_PATH = join(LUTRIS_CONFIG_PATH, 'covers')
TMP_PATH = join(LUTRIS_CACHE_PATH, 'tmp')
github shashlik / shashlik-runtime-env / scripts / constants.py View on Github external
import xdg.BaseDirectory
SHASHLIK_DIR         = "%s/shashlik" % xdg.BaseDirectory.xdg_data_home

SHASHLIK_INSTALL_DIR = "/opt/shashlik"
SHASHLIK_LIB_DIR     = "%s/lib64" % SHASHLIK_INSTALL_DIR
SHASHLIK_IMAGE_DIR   = "%s/android" % SHASHLIK_INSTALL_DIR
SHASHLIK_DATA_DIR    = "%s/data" % SHASHLIK_INSTALL_DIR
SHASHLIK_BIN_DIR     = "%s/bin" % SHASHLIK_INSTALL_DIR

SHASHLIK_ADB         = "%s/adb" % SHASHLIK_BIN_DIR
SHASHLIK_EMULATOR    = "%s/emulator64-x86" % SHASHLIK_BIN_DIR
SHASHLIK_AAPT        = "%s/aapt" % SHASHLIK_BIN_DIR
SHASHLIK_RUN         = "%s/shashlik_run" % SHASHLIK_BIN_DIR
github getting-things-gnome / gtg / GTG / core / __init__.py View on Github external
def __init__(self):
        if hasattr(self, 'data_dir'):
            # Borg has already been initialized
            return
        self.data_dir = os.path.join(xdg_data_home, 'gtg/')
        self.conf_dir = os.path.join(xdg_config_home, 'gtg/')
        if not os.path.exists(self.conf_dir):
            os.makedirs(self.conf_dir)
        if not os.path.exists(self.data_dir):
            os.makedirs(self.data_dir)
        self.conf_path = os.path.join(self.conf_dir, self.CONF_FILE)
        self.task_conf_path = os.path.join(self.conf_dir, self.TASK_CONF_FILE)
        if not os.path.exists(self.conf_path):
            open(self.conf_path, "w").close()
        if not os.path.exists(self.task_conf_path):
            open(self.task_conf_path, "w").close()
        for conf_file in [self.conf_path, self.task_conf_path]:
            if not os.access(conf_file, os.R_OK | os.W_OK):
                raise Exception("File " + conf_file +
                                " is a configuration file for gtg, but it "
                                "cannot be read or written. Please check it")
github tuhiproject / tuhi / tuhi / gui / application.py View on Github external
from pathlib import Path

import logging
import sys
import xdg.BaseDirectory
import gi
gi.require_version("Gio", "2.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gio, GLib, Gtk, Gdk  # NOQA

logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
                    level=logging.INFO,
                    datefmt='%H:%M:%S')
logger = logging.getLogger('tuhi.gui')

DEFAULT_CONFIG_PATH = Path(xdg.BaseDirectory.xdg_data_home, 'tuhi')


class Application(Gtk.Application):
    def __init__(self):
        super().__init__(application_id='org.freedesktop.Tuhi',
                         flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
        GLib.set_application_name('Tuhi')
        self.add_main_option('config-dir', 0,
                             GLib.OptionFlags.NONE,
                             GLib.OptionArg.STRING,
                             'path to configuration directory',
                             '/path/to/config-dir')
        self.add_main_option('verbose', 0,
                             GLib.OptionFlags.NONE,
                             GLib.OptionArg.NONE,
                             'enable verbose output')
github lantw44 / ceiba-dl / ceiba_dl / helper.py View on Github external
def __init__(self, config, store=True, main_script=None, helpers_dir='helpers'):
        self.config = config
        self.store = store
        self.logger = logging.getLogger(__name__)

        helper_path = list(xdg.BaseDirectory.load_data_paths(
            self.config.name, helpers_dir))

        try:
            import ceiba_dl._version
            personal_helper_path = os.path.join(xdg.BaseDirectory.xdg_data_home,
                self.config.name, helpers_dir)
            if os.path.isdir(ceiba_dl._version.helperdir):
                if personal_helper_path in helper_path:
                    assert helper_path[0] == personal_helper_path
                    helper_path.insert(1, ceiba_dl._version.helperdir)
                else:
                    helper_path.insert(0, ceiba_dl._version.helperdir)
        except ImportError:
            pass

        if main_script:
            main_script_dir = os.path.dirname(os.path.abspath(main_script))
            uninstalled_helpers_dir = os.path.join(main_script_dir, helpers_dir)
            if os.path.isdir(uninstalled_helpers_dir):
                helper_path.append(uninstalled_helpers_dir)
        self.logger.info('輔助程式搜尋路徑是 {}'.format(helper_path))
github CMoH / gnome15 / src / plugins / cairo-clock / cairo-clock.py View on Github external
def get_theme_dirs(model_name, gconf_key, gconf_client):
    dirs = []
    model_dir = "g15"
    if model_name == g15driver.MODEL_G19:
        model_dir = "g19"
    elif model_name == g15driver.MODEL_MX5500:
        model_dir = "mx5500"
    dirs.append(os.path.join(os.path.dirname(__file__), model_dir))
    dirs.append(os.path.join(g15globals.user_data_dir, "cairo-clock", model_dir))
    theme_dir = gconf_client.get(gconf_key + "/theme_dir")
    if theme_dir != None:
        dirs.append(theme_dir.get_string())
    if model_name == g15driver.MODEL_G19:
        dirs.append(os.path.join(xdg.BaseDirectory.xdg_data_home, "cairo-clock"))
        dirs.append("/usr/share/cairo-clock/themes")
    return dirs
github MicahCarrick / desktop-entry-editor / src / dee / application.py View on Github external
def _ensure_user_dir(self):
        """
        Ensures the user's applications directory exists.
        """
        path = os.path.join(xdg_data_home, "applications")
        if not os.path.exists(path):
            os.makedirs(path)