Exemplo n.º 1
0
    def ok(feed):
        from zeroinstall.injector import reader
        try:
            feed_targets = policy.get_feed_targets(feed)
            if interface not in feed_targets:
                raise Exception(
                    _("Not a valid feed for '%(uri)s'; this is a feed for:\n%(feed_for)s"
                      ) % {
                          'uri': interface.uri,
                          'feed_for': '\n'.join([f.uri for f in feed_targets])
                      })
            if interface.get_feed(feed):
                dialog.alert(None, _('This feed is already registered.'))
            else:
                interface.extra_feeds.append(
                    Feed(feed, user_override=True, arch=None))

            writer.save_interface(interface)
            chooser.destroy()
            reader.update_from_cache(interface)
            policy.recalculate()
        except Exception, ex:
            dialog.alert(
                None,
                _("Error in feed file '%(feed)s':\n\n%(exception)s") % {
                    'feed': feed,
                    'exception': str(ex)
                })
Exemplo n.º 2
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
Exemplo n.º 3
0
def update_user_overrides(interface):
	"""Update an interface with user-supplied information.
	Sets preferred stability and updates extra_feeds.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	"""
	user = basedir.load_first_config(config_site, config_prog,
					   'interfaces', model._pretty_escape(interface.uri))
	if user is None:
		# For files saved by 0launch < 0.49
		user = basedir.load_first_config(config_site, config_prog,
						   'user_overrides', escape(interface.uri))
	if not user:
		return

	try:
		root = qdom.parse(file(user))
	except Exception as ex:
		warn(_("Error reading '%(user)s': %(exception)s"), {'user': user, 'exception': ex})
		raise

	stability_policy = root.getAttribute('stability-policy')
	if stability_policy:
		interface.set_stability_policy(stability_levels[str(stability_policy)])

	for item in root.childNodes:
		if item.uri != XMLNS_IFACE: continue
		if item.name == 'feed':
			feed_src = item.getAttribute('src')
			if not feed_src:
				raise InvalidInterface(_('Missing "src" attribute in <feed>'))
			interface.extra_feeds.append(Feed(feed_src, item.getAttribute('arch'), True, langs = item.getAttribute('langs')))
Exemplo n.º 4
0
def update_user_overrides(interface, known_site_feeds=frozenset()):
    """Update an interface with user-supplied information.
	Sets preferred stability and updates extra_feeds.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@param known_site_feeds: feeds to ignore (for backwards compatibility)
	"""
    user = basedir.load_first_config(config_site, config_prog, 'interfaces',
                                     model._pretty_escape(interface.uri))
    if user is None:
        # For files saved by 0launch < 0.49
        user = basedir.load_first_config(config_site,
                                         config_prog, 'user_overrides',
                                         escape(interface.uri))
    if not user:
        return

    try:
        with open(user, 'rb') as stream:
            root = qdom.parse(stream)
    except Exception as ex:
        logger.warn(_("Error reading '%(user)s': %(exception)s"), {
            'user': user,
            'exception': ex
        })
        raise

    stability_policy = root.getAttribute('stability-policy')
    if stability_policy:
        interface.set_stability_policy(stability_levels[str(stability_policy)])

    for item in root.childNodes:
        if item.uri != XMLNS_IFACE: continue
        if item.name == 'feed':
            feed_src = item.getAttribute('src')
            if not feed_src:
                raise InvalidInterface(_('Missing "src" attribute in <feed>'))
            # (note: 0install 1.9..1.12 used a different scheme and the "site-package" attribute;
            # we deliberately use a different attribute name to avoid confusion)
            if item.getAttribute('is-site-package'):
                # Site packages are detected earlier. This test isn't completely reliable,
                # since older versions will remove the attribute when saving the config
                # (hence the next test).
                continue
            if feed_src in known_site_feeds:
                continue
            interface.extra_feeds.append(
                Feed(feed_src,
                     item.getAttribute('arch'),
                     True,
                     langs=item.getAttribute('langs')))
Exemplo n.º 5
0
def _add_site_packages(interface, site_packages, known_site_feeds):
    for impl in os.listdir(site_packages):
        if impl.startswith('.'): continue
        feed = os.path.join(site_packages, impl, '0install', 'feed.xml')
        if not os.path.exists(feed):
            logger.warn(
                _("Site-local feed {path} not found").format(path=feed))
        logger.debug("Adding site-local feed '%s'", feed)

        # (we treat these as user overrides in order to let old versions of 0install
        # find them)
        interface.extra_feeds.append(
            Feed(feed, None, user_override=True, site_package=True))
        known_site_feeds.add(feed)
Exemplo n.º 6
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
Exemplo n.º 7
0
def update_from_cache(interface):
    """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.
	@rtype: bool"""
    interface.reset()
    main_feed = None

    if interface.uri.startswith('/'):
        debug(_("Loading local interface file '%s'"), interface.uri)
        update(interface, interface.uri, local=True)
        cached = True
    else:
        cached = basedir.load_first_cache(config_site, 'interfaces',
                                          escape(interface.uri))
        if cached:
            debug(
                _("Loading cached information for %(interface)s from %(cached)s"
                  ), {
                      'interface': interface,
                      'cached': cached
                  })
            main_feed = update(interface, cached)

    # 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)

    return bool(cached)
Exemplo n.º 8
0
def add_remote_feed(policy, parent, interface):
    try:
        d = gtk.MessageDialog(
            parent, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL,
            _('Enter the URL of the new source of implementations of this interface:'
              ))
        d.add_button(gtk.STOCK_ADD, gtk.RESPONSE_OK)
        d.set_default_response(gtk.RESPONSE_OK)
        entry = gtk.Entry()

        align = gtk.VBox(False, 0)
        align.set_border_width(4)
        align.add(entry)
        d.vbox.pack_start(align)
        entry.set_activates_default(True)

        entry.set_text('')

        d.vbox.show_all()

        error_label = gtk.Label('')
        error_label.set_padding(4, 4)
        align.pack_start(error_label)

        d.show()

        def error(message):
            if message:
                error_label.set_text(message)
                error_label.show()
            else:
                error_label.hide()

        while True:
            got_response = DialogResponse(d)
            yield got_response
            tasks.check(got_response)
            resp = got_response.response

            error(None)
            if resp == gtk.RESPONSE_OK:
                try:
                    url = entry.get_text()
                    if not url:
                        raise zeroinstall.SafeException(_('Enter a URL'))
                    fetch = policy.fetcher.download_and_import_feed(
                        url, iface_cache)
                    if fetch:
                        d.set_sensitive(False)
                        yield fetch
                        d.set_sensitive(True)
                        tasks.check(fetch)

                        iface = iface_cache.get_interface(url)

                        d.set_sensitive(True)
                        if not iface.name:
                            error(_('Failed to read interface'))
                            return
                        if not iface.feed_for:
                            error(
                                _("Feed '%(feed)s' is not a feed for '%(feed_for)s'."
                                  ) % {
                                      'feed': iface.get_name(),
                                      'feed_for': interface.get_name()
                                  })
                        elif interface.uri not in iface.feed_for:
                            error(
                                _("This is not a feed for '%(uri)s'.\nOnly for:\n%(feed_for)s"
                                  ) % {
                                      'uri': interface.uri,
                                      'feed_for': '\n'.join(iface.feed_for)
                                  })
                        elif iface.uri in [f.uri for f in interface.feeds]:
                            error(
                                _("Feed from '%s' has already been added!") %
                                iface.uri)
                        else:
                            interface.extra_feeds.append(
                                Feed(iface.uri, arch=None, user_override=True))
                            writer.save_interface(interface)
                            d.destroy()
                            policy.recalculate()
                except zeroinstall.SafeException, ex:
                    error(str(ex))
            else:
                d.destroy()
                return
    except Exception, ex:
        import traceback
        traceback.print_exc()
        policy.handler.report_error(ex)
Exemplo n.º 9
0
                      ), {
                          'id': id,
                          'interface': interface
                      })
                continue

            user_stability = item.getAttribute('user-stability')
            if user_stability:
                impl.user_stability = stability_levels[str(user_stability)]
        elif item.name == 'feed':
            feed_src = item.getAttribute('src')
            if not feed_src:
                raise InvalidInterface(_('Missing "src" attribute in <feed>'))
            interface.extra_feeds.append(
                Feed(feed_src,
                     item.getAttribute('arch'),
                     True,
                     langs=item.getAttribute('langs')))


def check_readable(interface_uri, source):
    """Test whether an interface file is valid.
	@param interface_uri: the interface's URI
	@type interface_uri: str
	@param source: the name of the file to test
	@type source: str
	@return: the modification time in src (usually just the mtime of the file)
	@rtype: int
	@raise InvalidInterface: If the source's syntax is incorrect,
	"""
    tmp = Interface(interface_uri)
    try: