예제 #1
0
        def fetch_feed():
            yield dl.downloaded
            tasks.check(dl.downloaded)

            pending = PendingFeed(feed_url, stream)

            if use_mirror:
                # If we got the feed from a mirror, get the key from there too
                key_mirror = self.feed_mirror + '/keys/'
            else:
                key_mirror = None

            keys_downloaded = tasks.Task(
                pending.download_keys(self.handler,
                                      feed_hint=feed_url,
                                      key_mirror=key_mirror),
                _("download keys for %s") % feed_url)
            yield keys_downloaded.finished
            tasks.check(keys_downloaded.finished)

            iface = iface_cache.get_interface(pending.url)
            if not iface_cache.update_interface_if_trusted(
                    iface, pending.sigs, pending.new_xml):
                blocker = self.handler.confirm_keys(pending,
                                                    self.fetch_key_info)
                if blocker:
                    yield blocker
                    tasks.check(blocker)
                if not iface_cache.update_interface_if_trusted(
                        iface, pending.sigs, pending.new_xml):
                    raise NoTrustedKeys(
                        _("No signing keys trusted; not importing"))
예제 #2
0
        def fetch_feed():
            try:
                yield dl.downloaded
                tasks.check(dl.downloaded)

                pending = PendingFeed(feed_url, stream)

                if use_mirror:
                    # If we got the feed from a mirror, get the key from there too
                    key_mirror = self.config.mirror + '/keys/'
                else:
                    key_mirror = None

                keys_downloaded = tasks.Task(
                    pending.download_keys(self,
                                          feed_hint=feed_url,
                                          key_mirror=key_mirror),
                    _("download keys for %s") % feed_url)
                yield keys_downloaded.finished
                tasks.check(keys_downloaded.finished)

                if not self.config.iface_cache.update_feed_if_trusted(
                        pending.url, pending.sigs, pending.new_xml):
                    blocker = self.config.trust_mgr.confirm_keys(pending)
                    if blocker:
                        yield blocker
                        tasks.check(blocker)
                    if not self.config.iface_cache.update_feed_if_trusted(
                            pending.url, pending.sigs, pending.new_xml):
                        raise NoTrustedKeys(
                            _("No signing keys trusted; not importing"))
            finally:
                stream.close()
예제 #3
0
    def start(self):
        """Create a temporary file and begin the download.
		@precondition: L{status} == L{download_starting}"""
        assert self.status == download_starting
        assert self.downloaded is None

        self.tempfile = tempfile.TemporaryFile(prefix='injector-dl-data-')

        task = tasks.Task(self._do_download(), "download " + self.url)
        self.downloaded = task.finished
예제 #4
0
		def run():
			keys_downloaded = tasks.Task(pending.download_keys(handler), "download keys")
			yield keys_downloaded.finished
			tasks.check(keys_downloaded.finished)
			if not iface_cache.update_interface_if_trusted(iface, pending.sigs, pending.new_xml):
				blocker = handler.confirm_trust_keys(iface, pending.sigs, pending.new_xml)
				if blocker:
					yield blocker
					tasks.check(blocker)
				if not iface_cache.update_interface_if_trusted(iface, pending.sigs, pending.new_xml):
					raise SafeException(_("No signing keys trusted; not importing"))
예제 #5
0
 def run():
     keys_downloaded = tasks.Task(
         pending.download_keys(config.fetcher), "download keys")
     yield keys_downloaded.finished
     tasks.check(keys_downloaded.finished)
     if not config.iface_cache.update_feed_if_trusted(
             uri, pending.sigs, pending.new_xml):
         blocker = config.trust_mgr.confirm_keys(pending)
         if blocker:
             yield blocker
             tasks.check(blocker)
         if not config.iface_cache.update_feed_if_trusted(
                 uri, pending.sigs, pending.new_xml):
             raise SafeException(
                 _("No signing keys trusted; not importing"))
예제 #6
0
def handle(config, options, args):
    if not args:
        raise UsageError()

    h = config.handler

    for x in args:
        if not os.path.isfile(x):
            raise SafeException(_("File '%s' does not exist") % x)
        logging.info(_("Importing from file '%s'"), x)
        signed_data = file(x)
        data, sigs = gpg.check_stream(signed_data)
        doc = minidom.parseString(data.read())
        uri = doc.documentElement.getAttribute('uri')
        if not uri:
            raise SafeException(
                _("Missing 'uri' attribute on root element in '%s'") % x)
        logging.info(_("Importing information about interface %s"), uri)
        signed_data.seek(0)

        pending = PendingFeed(uri, signed_data)

        def run():
            keys_downloaded = tasks.Task(pending.download_keys(h),
                                         "download keys")
            yield keys_downloaded.finished
            tasks.check(keys_downloaded.finished)
            if not config.iface_cache.update_feed_if_trusted(
                    uri, pending.sigs, pending.new_xml):
                blocker = config.trust_mgr.confirm_keys(pending)
                if blocker:
                    yield blocker
                    tasks.check(blocker)
                if not config.iface_cache.update_feed_if_trusted(
                        uri, pending.sigs, pending.new_xml):
                    raise SafeException(
                        _("No signing keys trusted; not importing"))

        task = tasks.Task(run(), "import feed")

        errors = tasks.wait_for_blocker(task.finished)
        if errors:
            raise SafeException(
                _("Errors during download: ") + '\n'.join(errors))
예제 #7
0
def _import_feed(args):
	from zeroinstall.support import tasks
	from zeroinstall.injector import gpg, handler
	from zeroinstall.injector.iface_cache import PendingFeed
	from xml.dom import minidom
	handler = handler.Handler()

	for x in args:
		if not os.path.isfile(x):
			raise SafeException(_("File '%s' does not exist") % x)
		logging.info(_("Importing from file '%s'"), x)
		signed_data = file(x)
		data, sigs = gpg.check_stream(signed_data)
		doc = minidom.parseString(data.read())
		uri = doc.documentElement.getAttribute('uri')
		if not uri:
			raise SafeException(_("Missing 'uri' attribute on root element in '%s'") % x)
		iface = iface_cache.get_interface(uri)
		logging.info(_("Importing information about interface %s"), iface)
		signed_data.seek(0)

		pending = PendingFeed(uri, signed_data)

		def run():
			keys_downloaded = tasks.Task(pending.download_keys(handler), "download keys")
			yield keys_downloaded.finished
			tasks.check(keys_downloaded.finished)
			if not iface_cache.update_interface_if_trusted(iface, pending.sigs, pending.new_xml):
				blocker = handler.confirm_trust_keys(iface, pending.sigs, pending.new_xml)
				if blocker:
					yield blocker
					tasks.check(blocker)
				if not iface_cache.update_interface_if_trusted(iface, pending.sigs, pending.new_xml):
					raise SafeException(_("No signing keys trusted; not importing"))

		task = tasks.Task(run(), "import feed")

		errors = handler.wait_for_blocker(task.finished)
		if errors:
			raise SafeException(_("Errors during download: ") + '\n'.join(errors))
예제 #8
0
    def wait_for_blocker(self, blocker):
        """Run a recursive mainloop until blocker is triggered.
		@param blocker: event to wait on
		@type blocker: L{tasks.Blocker}"""
        if not blocker.happened:
            import gobject

            def quitter():
                yield blocker
                self._loop.quit()

            quit = tasks.Task(quitter(), "quitter")

            assert self._loop is None  # Avoid recursion
            self._loop = gobject.MainLoop(gobject.main_context_default())
            try:
                debug(_("Entering mainloop, waiting for %s"), blocker)
                self._loop.run()
            finally:
                self._loop = None

            assert blocker.happened, "Someone quit the main loop!"

        tasks.check(blocker)