How to use the xdg.BaseDirectory.save_data_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 snapcore / snapcraft / tests / integration / general / test_parts.py View on Github external
def _parts_dir(self):
        parts_uri = "https://parts.snapcraft.io/v1/parts.yaml"
        return os.path.join(
            xdg.BaseDirectory.save_data_path("snapcraft"),
            hashlib.sha384(parts_uri.encode(sys.getfilesystemencoding())).hexdigest(),
        )
github Jolicloud / jolicloud-daemon / jolicloud_daemon / main.py View on Github external
root.processors = { '.rpy': script.ResourceScript }
    root = rewrite.RewriterResource(root, rewrite.alias('cgi-bin/get_icon.py', 'get_icon.rpy'))
    
    site = JolicloudWSSite(root)
    site.addHandler('/jolicloud/', JolicloudWSHandler)
    
    # Setting up the log file path
    if os.environ.get('JPD_SYSTEM', '0') == '1':
        if os.getuid():
            log.err('You must be root to run this daemon in system mode.')
            exit()
        log_path = '/var/log'
    else:
        try:
            import xdg.BaseDirectory
            log_path = xdg.BaseDirectory.save_data_path('Jolicloud', 'jolicloud-daemon')
        except ImportError:
            log_path = os.path.join(os.getenv('HOME'), '.local', 'share', 'Jolicloud', 'jolicloud-daemon')
    
    port = int(os.environ.get('JPD_PORT', 804 if os.environ.get('JPD_SYSTEM', None) else 8004))
    
    # http://twistedmatrix.com/documents/9.0.0/web/howto/using-twistedweb.html#auto5
    if os.environ.get('JPD_DEBUG', '0') == '1':
        log.startLogging(sys.stdout)
        log.startLogging(LogFile('jolicloud-daemon.log', log_path, maxRotatedFiles=2))
        reactor.listenTCP(port, site)
    else:
        log.startLogging(LogFile('jolicloud-daemon.log', log_path, maxRotatedFiles=2))
        reactor.listenTCP(port, site, interface='127.0.0.1')
    # TODO, use random port for session daemon
    
    # We load the plugins:
github mozilla / DeepSpeech / util / config.py View on Github external
FLAGS.dropout_rate2 = FLAGS.dropout_rate
    if FLAGS.dropout_rate3 < 0:
        FLAGS.dropout_rate3 = FLAGS.dropout_rate
    if FLAGS.dropout_rate6 < 0:
        FLAGS.dropout_rate6 = FLAGS.dropout_rate

    # Set default checkpoint dir
    if not FLAGS.checkpoint_dir:
        FLAGS.checkpoint_dir = xdg.save_data_path(os.path.join('deepspeech', 'checkpoints'))

    if FLAGS.load not in ['last', 'best', 'init', 'auto']:
        FLAGS.load = 'auto'

    # Set default summary dir
    if not FLAGS.summary_dir:
        FLAGS.summary_dir = xdg.save_data_path(os.path.join('deepspeech', 'summaries'))

    # Standard session configuration that'll be used for all new sessions.
    c.session_config = tfv1.ConfigProto(allow_soft_placement=True, log_device_placement=FLAGS.log_placement,
                                        inter_op_parallelism_threads=FLAGS.inter_op_parallelism_threads,
                                        intra_op_parallelism_threads=FLAGS.intra_op_parallelism_threads,
                                        gpu_options=tfv1.GPUOptions(allow_growth=FLAGS.use_allow_growth))

    # CPU device
    c.cpu_device = '/cpu:0'

    # Available GPU devices
    c.available_devices = get_available_gpus(c.session_config)

    # If there is no GPU available, we fall back to CPU based operation
    if not c.available_devices:
        c.available_devices = [c.cpu_device]
github ufo-kit / concert / concert / session / management.py View on Github external
def path(session=None):
    """
    Get absolute path of *session* module or base path if *session* is None.
    """
    global _CACHED_PATH

    if _CACHED_PATH is None:
        env = os.environ
        if "VIRTUAL_ENV" in env:
            env["XDG_DATA_HOME"] = os.path.join(env["VIRTUAL_ENV"], "share")

        import xdg.BaseDirectory
        _CACHED_PATH = xdg.BaseDirectory.save_data_path('concert')

    if session is None:
        return _CACHED_PATH

    return os.path.join(_CACHED_PATH, session + '.py')
github seamus-45 / roficlip / roficlip.py View on Github external
def __init__(self):
        # Init databases and fifo
        name = 'roficlip'
        self.ring_db = '{0}/{1}'.format(BaseDirectory.save_data_path(name), 'ring.db')
        self.persist_db = '{0}/{1}'.format(BaseDirectory.save_data_path(name), 'persistent.db')
        self.fifo_path = '{0}/{1}.fifo'.format(BaseDirectory.get_runtime_dir(strict=False), name)
        self.config_path = '{0}/settings'.format(BaseDirectory.save_config_path(name))
        if not os.path.isfile(self.ring_db):
            open(self.ring_db, "a+").close()
        if not os.path.isfile(self.persist_db):
            open(self.persist_db, "a+").close()
        if (
            not os.path.exists(self.fifo_path) or
            not stat.S_ISFIFO(os.stat(self.fifo_path).st_mode)
        ):
            os.mkfifo(self.fifo_path)
        self.fifo = os.open(self.fifo_path, os.O_RDONLY | os.O_NONBLOCK)

        # Init clipboard and read databases
        self.cb = gtk.Clipboard()
github labyrinth-team / labyrinth / labyrinth_lib / utils.py View on Github external
def get_save_dir ():
    ''' Returns the path to the directory to save the maps to '''
    if os.name == 'nt':
        savedir = os.path.join(os.path.expanduser('~'), '.labyrinth')
        if not os.access (savedir, os.W_OK):
            os.makedirs (savedir)
        return savedir
    
    old_savedir = os.path.join (os.path.expanduser('~'), ".gnome2", "labyrinth")
    savedir = BaseDirectory.save_data_path("labyrinth")
    
    # Migrate maps to the new save directory.   
    if os.path.exists(old_savedir) and os.path.isdir(old_savedir):
        
        for m in os.listdir(old_savedir):
            try:
                os.rename(os.path.join(old_savedir, m),
                        os.path.join(savedir, m))
            except Exception as e:
                warnings.warn("Failed to migrate %s: %s" % (m, e))
        
        # remove old dir
        try:
            os.rmdir(old_savedir)
        except Exception as e:
            warnings.warn("Could not remove old map dir (%s): %s" % (old_savedir, e))
github snapcore / snapcraft / snapcraft / internal / remote_build / _launchpad.py View on Github external
def _create_data_directory(self) -> str:
        data_dir = BaseDirectory.save_data_path("snapcraft", "provider", "launchpad")
        os.makedirs(data_dir, mode=0o700, exist_ok=True)
        return data_dir
github spanezz / egt / egtlib / state.py View on Github external
def get_state_dir(cls) -> str:
        return BaseDirectory.save_data_path('egt')
github jrnl-org / jrnl / jrnl / install.py View on Github external
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:
        return True


default_config = {
github pandeydivesh15 / AVSR-Deep-Speech / DeepSpeech_RHL.py View on Github external
FLAGS.dropout_rate6 = FLAGS.dropout_rate

    global dropout_rates
    dropout_rates = [ FLAGS.dropout_rate,
                      FLAGS.dropout_rate2,
                      FLAGS.dropout_rate3,
                      FLAGS.dropout_rate4,
                      FLAGS.dropout_rate5,
                      FLAGS.dropout_rate6 ]

    global no_dropout
    no_dropout = [ 0.0 ] * 6

    # Set default checkpoint dir
    if len(FLAGS.checkpoint_dir) == 0:
        FLAGS.checkpoint_dir = xdg.save_data_path(os.path.join('deepspeech','checkpoints'))

    # Set default summary dir
    if len(FLAGS.summary_dir) == 0:
        FLAGS.summary_dir = xdg.save_data_path(os.path.join('deepspeech','summaries'))

    # Standard session configuration that'll be used for all new sessions.
    global session_config
    session_config = tf.ConfigProto(allow_soft_placement=True, log_device_placement=FLAGS.log_placement)

    # Geometric Constants
    # ===================

    # For an explanation of the meaning of the geometric constants, please refer to
    # doc/Geometry.md

    # Number of MFCC features