コード例 #1
0
ファイル: xdgutils.py プロジェクト: dabrahams/0install
def discover_existing_apps():
	"""Search through the configured XDG datadirs looking for .desktop files created by L{add_to_menu}.
	@return: a map from application URIs to .desktop filenames"""
	already_installed = {}
	for d in basedir.load_data_paths('applications'):
		for desktop_file in os.listdir(d):
			if desktop_file.startswith('zeroinstall-') and desktop_file.endswith('.desktop'):
				full = os.path.join(d, desktop_file)
				try:
					with open(full, 'rt') as stream:
						for line in stream:
							line = line.strip()
							if line.startswith('Exec=0launch '):
								bits = line.split(' -- ', 1)
								if ' ' in bits[0]:
									uri = bits[0].split(' ', 1)[1]		# 0launch URI -- %u
								else:
									uri = bits[1].split(' ', 1)[0].strip()	# 0launch -- URI %u
								already_installed[uri] = full
								break
						else:
							logger.info(_("Failed to find Exec line in %s"), full)
				except Exception as ex:
					logger.warn(_("Failed to load .desktop file %(filename)s: %(exceptions"), {'filename': full, 'exception': ex})
	return already_installed
コード例 #2
0
ファイル: xdgutils.py プロジェクト: timdiels/0install
def discover_existing_apps():
    """Search through the configured XDG datadirs looking for .desktop files created by L{add_to_menu}.
	@return: a map from application URIs to .desktop filenames"""
    already_installed = {}
    for d in basedir.load_data_paths('applications'):
        for desktop_file in os.listdir(d):
            if desktop_file.startswith(
                    'zeroinstall-') and desktop_file.endswith('.desktop'):
                full = os.path.join(d, desktop_file)
                try:
                    with open(full, 'rt') as stream:
                        for line in stream:
                            line = line.strip()
                            if line.startswith('Exec=0launch '):
                                bits = line.split(' -- ', 1)
                                if ' ' in bits[0]:
                                    uri = bits[0].split(
                                        ' ', 1)[1]  # 0launch URI -- %u
                                else:
                                    uri = bits[1].split(
                                        ' ', 1)[0].strip()  # 0launch -- URI %u
                                already_installed[uri] = full
                                break
                        else:
                            logger.info(_("Failed to find Exec line in %s"),
                                        full)
                except Exception as ex:
                    logger.warn(
                        _("Failed to load .desktop file %(filename)s: %(exceptions"
                          ), {
                              'filename': full,
                              'exception': ex
                          })
    return already_installed
コード例 #3
0
ファイル: reader.py プロジェクト: michel-slm/0install
def update_from_cache(interface, iface_cache=None):
    """Read a cached interface and any native feeds or user overrides.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@return: True if cached version and user overrides loaded OK.
	False if upstream not cached. Local interfaces (starting with /) are
	always considered to be cached, although they are not actually stored in the cache.
	Internal: use L{iface_cache.IfaceCache.get_interface} instread.
	@rtype: bool"""
    interface.reset()
    if iface_cache is None:
        import warnings
        warnings.warn("iface_cache should be specified", DeprecationWarning, 2)
        from zeroinstall.injector import policy
        iface_cache = policy.get_deprecated_singleton_config().iface_cache

    # Add the distribution package manager's version, if any
    path = basedir.load_first_data(config_site, 'native_feeds',
                                   model._pretty_escape(interface.uri))
    if path:
        # Resolve any symlinks
        logger.info(_("Adding native packager feed '%s'"), path)
        interface.extra_feeds.append(Feed(os.path.realpath(path), None, False))

    # Add locally-compiled binaries, if any
    escaped_uri = model.escape_interface_uri(interface.uri)
    known_site_feeds = set()
    for path in basedir.load_data_paths(config_site, 'site-packages',
                                        *escaped_uri):
        try:
            _add_site_packages(interface, path, known_site_feeds)
        except Exception as ex:
            logger.warn("Error loading site packages from {path}: {ex}".format(
                path=path, ex=ex))

    update_user_overrides(interface, known_site_feeds)

    main_feed = iface_cache.get_feed(interface.uri, force=True)
    if main_feed:
        update_user_feed_overrides(main_feed)

    return main_feed is not None
コード例 #4
0
ファイル: reader.py プロジェクト: michel-slm/0install
def update_from_cache(interface, iface_cache=None):
    """Read a cached interface and any native feeds or user overrides.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@return: True if cached version and user overrides loaded OK.
	False if upstream not cached. Local interfaces (starting with /) are
	always considered to be cached, although they are not actually stored in the cache.
	Internal: use L{iface_cache.IfaceCache.get_interface} instread.
	@rtype: bool"""
    interface.reset()
    if iface_cache is None:
        import warnings

        warnings.warn("iface_cache should be specified", DeprecationWarning, 2)
        from zeroinstall.injector import policy

        iface_cache = policy.get_deprecated_singleton_config().iface_cache

        # Add the distribution package manager's version, if any
    path = basedir.load_first_data(config_site, "native_feeds", model._pretty_escape(interface.uri))
    if path:
        # Resolve any symlinks
        logger.info(_("Adding native packager feed '%s'"), path)
        interface.extra_feeds.append(Feed(os.path.realpath(path), None, False))

        # Add locally-compiled binaries, if any
    escaped_uri = model.escape_interface_uri(interface.uri)
    known_site_feeds = set()
    for path in basedir.load_data_paths(config_site, "site-packages", *escaped_uri):
        try:
            _add_site_packages(interface, path, known_site_feeds)
        except Exception as ex:
            logger.warn("Error loading site packages from {path}: {ex}".format(path=path, ex=ex))

    update_user_overrides(interface, known_site_feeds)

    main_feed = iface_cache.get_feed(interface.uri, force=True)
    if main_feed:
        update_user_feed_overrides(main_feed)

    return main_feed is not None