Ejemplo n.º 1
0
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:
		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
		info(_("Adding native packager feed '%s'"), path)
		interface.extra_feeds.append(Feed(os.path.realpath(path), None, False))

	update_user_overrides(interface)

	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
Ejemplo n.º 2
0
def update(interface, source, local=False, iface_cache=None):
    """Read in information about an interface.
	Deprecated.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@param source: the name of the file to read
	@type source: str
	@param local: use file's mtime for last-modified, and uri attribute is ignored
	@raise InvalidInterface: if the source's syntax is incorrect
	@return: the new feed (since 0.32)
	@see: L{update_from_cache}, which calls this"""
    assert isinstance(interface, Interface)

    feed = load_feed(source, local)

    if not local:
        if feed.url != interface.uri:
            raise InvalidInterface(
                _("Incorrect URL used for feed.\n\n"
                  "%(feed_url)s is given in the feed, but\n"
                  "%(interface_uri)s was requested") % {
                      'feed_url': feed.url,
                      'interface_uri': interface.uri
                  })

    if iface_cache is None:
        from zeroinstall.injector import policy
        iface_cache = policy.get_deprecated_singleton_config().iface_cache
    iface_cache._feeds[unicode(interface.uri)] = feed

    return feed
Ejemplo n.º 3
0
def update(interface, source, local = False, iface_cache = None):
	"""Read in information about an interface.
	Deprecated.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@param source: the name of the file to read
	@type source: str
	@param local: use file's mtime for last-modified, and uri attribute is ignored
	@raise InvalidInterface: if the source's syntax is incorrect
	@return: the new feed (since 0.32)
	@see: L{update_from_cache}, which calls this"""
	assert isinstance(interface, Interface)

	feed = load_feed(source, local)

	if not local:
		if feed.url != interface.uri:
			raise InvalidInterface(_("Incorrect URL used for feed.\n\n"
						"%(feed_url)s is given in the feed, but\n"
						"%(interface_uri)s was requested") %
						{'feed_url': feed.url, 'interface_uri': interface.uri})

	if iface_cache is None:
		from zeroinstall.injector import policy
		iface_cache = policy.get_deprecated_singleton_config().iface_cache
	iface_cache._feeds[unicode(interface.uri)] = feed

	return feed
Ejemplo n.º 4
0
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:
        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
        info(_("Adding native packager feed '%s'"), path)
        interface.extra_feeds.append(Feed(os.path.realpath(path), None, False))

    update_user_overrides(interface)

    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
Ejemplo n.º 5
0
	def download_missing(self, config, _old = None, include_packages = False):
		"""Check all selected implementations are available.
		Download any that are not present.
		Note: package implementations (distribution packages) are ignored unless include_packages is True.
		@param config: used to get iface_cache, stores and fetcher
		@param include_packages: also install native distribution packages
		@return: a L{tasks.Blocker} or None"""
		from zeroinstall.zerostore import NotStored

		if _old:
			config = get_deprecated_singleton_config()

		iface_cache = config.iface_cache
		stores = config.stores

		# Check that every required selection is cached
		def needs_download(sel):
			if sel.id.startswith('package:'):
				return include_packages
			elif not sel.local_path:
				try:
					stores.lookup_any(sel.digests)
				except NotStored:
					return True
			return False

		needed_downloads = list(filter(needs_download, self.selections.values()))
		if not needed_downloads:
			return

		if config.network_use == model.network_offline:
			from zeroinstall import NeedDownload
			raise NeedDownload(', '.join([str(x) for x in needed_downloads]))

		@tasks.async
		def download():
			# We're missing some. For each one, get the feed it came from
			# and find the corresponding <implementation> in that. This will
			# tell us where to get it from.
			# Note: we look for an implementation with the same ID. Maybe we
			# should check it has the same digest(s) too?
			needed_impls = []
			for sel in needed_downloads:
				feed_url = sel.attrs.get('from-feed', None) or sel.attrs['interface']
				feed = iface_cache.get_feed(feed_url)
				if feed is None or sel.id not in feed.implementations:
					fetch_feed = config.fetcher.download_and_import_feed(feed_url, iface_cache)
					yield fetch_feed
					tasks.check(fetch_feed)

					feed = iface_cache.get_feed(feed_url)
					assert feed, "Failed to get feed for %s" % feed_url
				impl = feed.implementations[sel.id]
				needed_impls.append(impl)

			fetch_impls = config.fetcher.download_impls(needed_impls, stores)
			yield fetch_impls
			tasks.check(fetch_impls)
		return download()
Ejemplo n.º 6
0
	def _main_feed(self):
		import warnings
		warnings.warn("use the feed instead", DeprecationWarning, 3)
		from zeroinstall.injector import policy
		iface_cache = policy.get_deprecated_singleton_config().iface_cache
		feed = iface_cache.get_feed(self.uri)
		if feed is None:
			return _dummy_feed
		return feed
Ejemplo n.º 7
0
    def download_missing(self, config, _old=None, include_packages=False):
        """Check all selected implementations are available.
		Download any that are not present. Since native distribution packages are usually
		only available in a single version, which is unlikely to be the one in the
		selections document, we ignore them by default.
		Note: package implementations (distribution packages) are ignored.
		@param config: used to get iface_cache, stores and fetcher
		@param include_packages: also try to install native packages (since 1.5)
		@type include_packages: bool
		@rtype: L{zeroinstall.support.tasks.Blocker} | None"""
        if _old:
            config = get_deprecated_singleton_config()

        iface_cache = config.iface_cache
        stores = config.stores

        needed_downloads = self.get_unavailable_selections(
            config, include_packages)
        if not needed_downloads:
            return

        if config.network_use == model.network_offline:
            from zeroinstall import NeedDownload
            raise NeedDownload(', '.join([str(x) for x in needed_downloads]))

        @tasks. async
        def download():
            # We're missing some. For each one, get the feed it came from
            # and find the corresponding <implementation> in that. This will
            # tell us where to get it from.
            # Note: we look for an implementation with the same ID. Maybe we
            # should check it has the same digest(s) too?
            needed_impls = []
            for sel in needed_downloads:
                feed_url = sel.attrs.get('from-feed',
                                         None) or sel.attrs['interface']
                feed = iface_cache.get_feed(feed_url)
                if feed is None or sel.id not in feed.implementations:
                    fetch_feed = config.fetcher.download_and_import_feed(
                        feed_url, iface_cache)
                    yield fetch_feed
                    tasks.check(fetch_feed)

                    feed = iface_cache.get_feed(feed_url)
                    assert feed, "Failed to get feed for %s" % feed_url
                impl = feed.implementations[sel.id]
                needed_impls.append(impl)

            fetch_impls = config.fetcher.download_impls(needed_impls, stores)
            yield fetch_impls
            tasks.check(fetch_impls)

        return download()
Ejemplo n.º 8
0
	def download_missing(self, config, _old = None, include_packages = False):
		"""Check all selected implementations are available.
		Download any that are not present. Since native distribution packages are usually
		only available in a single version, which is unlikely to be the one in the
		selections document, we ignore them by default.
		Note: package implementations (distribution packages) are ignored.
		@param config: used to get iface_cache, stores and fetcher
		@param include_packages: also try to install native packages (since 1.5)
		@type include_packages: bool
		@rtype: L{zeroinstall.support.tasks.Blocker} | None"""
		if _old:
			config = get_deprecated_singleton_config()

		iface_cache = config.iface_cache
		stores = config.stores

		needed_downloads = self.get_unavailable_selections(config, include_packages)
		if not needed_downloads:
			return

		if config.network_use == model.network_offline:
			from zeroinstall import NeedDownload
			raise NeedDownload(', '.join([str(x) for x in needed_downloads]))

		@tasks.async
		def download():
			# We're missing some. For each one, get the feed it came from
			# and find the corresponding <implementation> in that. This will
			# tell us where to get it from.
			# Note: we look for an implementation with the same ID. Maybe we
			# should check it has the same digest(s) too?
			needed_impls = []
			for sel in needed_downloads:
				feed_url = sel.attrs.get('from-feed', None) or sel.attrs['interface']
				feed = iface_cache.get_feed(feed_url)
				if feed is None or sel.id not in feed.implementations:
					fetch_feed = config.fetcher.download_and_import_feed(feed_url, iface_cache)
					yield fetch_feed
					tasks.check(fetch_feed)

					feed = iface_cache.get_feed(feed_url)
					assert feed, "Failed to get feed for %s" % feed_url
				impl = feed.implementations[sel.id]
				needed_impls.append(impl)

			fetch_impls = config.fetcher.download_impls(needed_impls, stores)
			yield fetch_impls
			tasks.check(fetch_impls)
		return download()
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
	def download_missing(self, config, _old = None, include_packages = False):
		"""Check all selected implementations are available.
		Download any that are not present. Since native distribution packages are usually
		only available in a single version, which is unlikely to be the one in the
		selections document, we ignore them by default.
		Note: package implementations (distribution packages) are ignored.
		@param config: used to get iface_cache, stores and fetcher
		@param include_packages: also try to install native packages (since 1.5)
		@return: a L{tasks.Blocker} or None"""
		from zeroinstall.zerostore import NotStored

		if _old:
			config = get_deprecated_singleton_config()

		iface_cache = config.iface_cache
		stores = config.stores

		# Check that every required selection is cached
		def needs_download(sel):
			if sel.id.startswith('package:'):
				if not include_packages: return False
				feed = iface_cache.get_feed(sel.feed)
				if not feed: return False
				impl = feed.implementations.get(sel.id, None)
				return impl is None or not impl.installed
			elif sel.local_path:
				return False
			else:
				try:
					stores.lookup_any(sel.digests)
				except NotStored:
					return True

		needed_downloads = list(filter(needs_download, self.selections.values()))
		if not needed_downloads:
			return

		if config.network_use == model.network_offline:
			from zeroinstall import NeedDownload
			raise NeedDownload(', '.join([str(x) for x in needed_downloads]))

		@tasks.async
		def download():
			# We're missing some. For each one, get the feed it came from
			# and find the corresponding <implementation> in that. This will
			# tell us where to get it from.
			# Note: we look for an implementation with the same ID. Maybe we
			# should check it has the same digest(s) too?
			needed_impls = []
			for sel in needed_downloads:
				feed_url = sel.attrs.get('from-feed', None) or sel.attrs['interface']
				feed = iface_cache.get_feed(feed_url)
				if feed is None or sel.id not in feed.implementations:
					fetch_feed = config.fetcher.download_and_import_feed(feed_url, iface_cache)
					yield fetch_feed
					tasks.check(fetch_feed)

					feed = iface_cache.get_feed(feed_url)
					assert feed, "Failed to get feed for %s" % feed_url
				impl = feed.implementations[sel.id]
				needed_impls.append(impl)

			fetch_impls = config.fetcher.download_impls(needed_impls, stores)
			yield fetch_impls
			tasks.check(fetch_impls)
		return download()
Ejemplo n.º 12
0
	def stores(self):
		from zeroinstall.injector import policy
		return policy.get_deprecated_singleton_config().stores
Ejemplo n.º 13
0
	def iteritems(self):
		# Deprecated
		iface_cache = get_deprecated_singleton_config().iface_cache
		for (uri, sel) in self.selections.items():
			yield (iface_cache.get_interface(uri), sel and sel.impl)
Ejemplo n.º 14
0
	def __iter__(self):
		# Deprecated
		iface_cache = get_deprecated_singleton_config().iface_cache
		for (uri, sel) in self.selections.items():
			yield iface_cache.get_interface(uri)
Ejemplo n.º 15
0
 def __iter__(self):
     # Deprecated
     iface_cache = get_deprecated_singleton_config().iface_cache
     for (uri, sel) in self.selections.items():
         yield iface_cache.get_interface(uri)
Ejemplo n.º 16
0
 def iteritems(self):
     # Deprecated
     iface_cache = get_deprecated_singleton_config().iface_cache
     for (uri, sel) in self.selections.items():
         yield (iface_cache.get_interface(uri), sel and sel.impl)
Ejemplo n.º 17
0
 def stores(self):
     from zeroinstall.injector import policy
     return policy.get_deprecated_singleton_config().stores