How to use the xdg.BaseDirectory.load_data_paths 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 clinton-hall / nzbToMedia / libs / xdg / Mime.py View on Github external
_cache_uptodate = True

    aliases = {}    # Maps alias Mime types to canonical names
    inheritance = defaultdict(set) # Maps to sets of parent mime types.
    
    # Load aliases
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'aliases')):
        with open(path, 'r') as f:
            for line in f:
                alias, canonical = line.strip().split(None, 1)
                aliases[alias] = canonical
    
    # Load filename patterns (globs)
    globs = GlobDB()
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'globs2')):
        globs.merge_file(path)
    globs.finalise()
    
    # Load magic sniffing data
    magic = MagicDB()    
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'magic')):
        magic.merge_file(path)
    magic.finalise()
    
    # Load subclasses
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'subclasses')):
        with open(path, 'r') as f:
            for line in f:
                sub, parent = line.strip().split(None, 1)
                inheritance[sub].add(parent)
github takluyver / pyxdg / xdg / Mime.py View on Github external
def _cache_database():
    global globs, magic, aliases, inheritance, _cache_uptodate

    _cache_uptodate = True

    aliases = {}    # Maps alias Mime types to canonical names
    inheritance = defaultdict(set) # Maps to sets of parent mime types.
    
    # Load aliases
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'aliases')):
        with open(path, 'r') as f:
            for line in f:
                alias, canonical = line.strip().split(None, 1)
                aliases[alias] = canonical
    
    # Load filename patterns (globs)
    globs = GlobDB()
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'globs2')):
        globs.merge_file(path)
    globs.finalise()
    
    # Load magic sniffing data
    magic = MagicDB()    
    for path in BaseDirectory.load_data_paths(os.path.join('mime', 'magic')):
        magic.merge_file(path)
    magic.finalise()
github kupferlauncher / kupfer / kupfer / config.py View on Github external
def get_data_file(filename, package=PACKAGE_NAME):
    """
    Return path to @filename if it exists
    anywhere in the data paths, else raise ResourceLookupError.
    """
    data_paths = []
    try:
        from . import version_subst
    except ImportError:
        first_datadir = "./data"
    else:
        first_datadir = os.path.join(version_subst.DATADIR, package)

    data_paths.append(first_datadir)
    for data_path in base.load_data_paths(package):
        if not data_path in data_paths:
            data_paths.append(data_path)

    for direc in data_paths:
        file_path = os.path.join(direc, filename)
        if os.path.exists(file_path):
            return file_path
    if package == PACKAGE_NAME:
        raise ResourceLookupError("Resource %s not found" % filename)
    else:
        raise ResourceLookupError("Resource %s in package %s not found" %
            (filename, package))
github clinton-hall / nzbToMedia / libs / xdg / Mime.py View on Github external
def _load(self):
        "Loads comment for current language. Use get_comment() instead."
        resource = os.path.join('mime', self.media, self.subtype + '.xml')
        for path in BaseDirectory.load_data_paths(resource):
            doc = minidom.parse(path)
            if doc is None:
                continue
            for comment in doc.documentElement.getElementsByTagNameNS(FREE_NS, 'comment'):
                lang = comment.getAttributeNS(XML_NAMESPACE, 'lang') or 'en'
                goodness = 1 + (lang in xdg.Locale.langs)
                if goodness > self._comment[0]:
                    self._comment = (goodness, _get_node_data(comment))
                if goodness == 2: return
github pulb / mailnag / Mailnag / common / utils.py View on Github external
def get_data_paths():
	# Add "./data" in workdir for running from builddir
	data_paths = []
	data_paths.append("./data")
	data_paths.extend(base.load_data_paths(PACKAGE_NAME))
	return data_paths
github ptpb / pb / pb / pb.py View on Github external
def xdg_static_folder():
    for path in BaseDirectory.load_data_paths('pbs'):
        return path
    return 'static'
github takluyver / pyxdg / xdg / Mime.py View on Github external
def _load(self):
        "Loads comment for current language. Use get_comment() instead."
        resource = os.path.join('mime', self.media, self.subtype + '.xml')
        for path in BaseDirectory.load_data_paths(resource):
            doc = minidom.parse(path)
            if doc is None:
                continue
            for comment in doc.documentElement.getElementsByTagNameNS(FREE_NS, 'comment'):
                lang = comment.getAttributeNS(XML_NAMESPACE, 'lang') or 'en'
                goodness = 1 + (lang in xdg.Locale.langs)
                if goodness > self._comment[0]:
                    self._comment = (goodness, _get_node_data(comment))
                if goodness == 2: return
github kupferlauncher / kupfer / kupfer / desktop_launch.py View on Github external
def lookup(path):
            """Return location for @path if exists, else none"""
            return next(xdg.BaseDirectory.load_data_paths(*path), None)