Example #1
0
        def download_impls():
            if unsafe_impls:
                confirm = self.handler.confirm_install(
                    _('The following components need to be installed using native packages. '
                      'These come from your distribution, and should therefore be trustworthy, but they also '
                      'run with extra privileges. In particular, installing them may run extra services on your '
                      'computer or affect other users. You may be asked to enter a password to confirm. The '
                      'packages are:\n\n') +
                    ('\n'.join('- ' + x for x in unsafe_impls)))
                yield confirm
                tasks.check(confirm)

            blockers = []

            for impl, source in to_download:
                blockers.append(self.download_impl(impl, source, stores))

            # Record the first error log the rest
            error = []

            def dl_error(ex, tb=None):
                if error:
                    self.handler.report_error(ex)
                else:
                    error.append((ex, tb))

            while blockers:
                yield blockers
                tasks.check(blockers, dl_error)

                blockers = [b for b in blockers if not b.happened]
            if error:
                from zeroinstall import support
                support.raise_with_traceback(*error[0])
Example #2
0
		def download_impls():
			if unsafe_impls:
				confirm = self.handler.confirm_install(_('The following components need to be installed using native packages. '
					'These come from your distribution, and should therefore be trustworthy, but they also '
					'run with extra privileges. In particular, installing them may run extra services on your '
					'computer or affect other users. You may be asked to enter a password to confirm. The '
					'packages are:\n\n') + ('\n'.join('- ' + x for x in unsafe_impls)))
				yield confirm
				tasks.check(confirm)

			blockers = []

			for impl, source in to_download:
				blockers.append(self.download_impl(impl, source, stores))

			# Record the first error log the rest
			error = []
			def dl_error(ex, tb = None):
				if error:
					self.handler.report_error(ex)
				else:
					error.append((ex, tb))
			while blockers:
				yield blockers
				tasks.check(blockers, dl_error)

				blockers = [b for b in blockers if not b.happened]
			if error:
				from zeroinstall import support
				support.raise_with_traceback(*error[0])
Example #3
0
def check(blockers, reporter=None):
    """See if any of the blockers have pending exceptions.
	If reporter is None, raise the first and log the rest.
	@type blockers: [L{Blocker}]
	@param reporter: invoke this function on each error"""
    ex = None
    if isinstance(blockers, Blocker):
        blockers = (blockers, )
    for b in blockers:
        if b.exception:
            b.exception_read = True
            if reporter:
                try:
                    reporter(*b.exception)
                except:
                    logger.warning("Failure reporting error! Error was: %s",
                                   repr(b.exception[0]))
                    raise
            elif ex is None:
                ex = b.exception
            else:
                logger.warning(_("Multiple exceptions waiting; skipping %s"),
                               b.exception[0])
    if ex:
        support.raise_with_traceback(ex[0], ex[1])
Example #4
0
    def download_keys(self, fetcher, feed_hint=None, key_mirror=None):
        """Download any required GPG keys not already on our keyring.
		When all downloads are done (successful or otherwise), add any new keys
		to the keyring, L{recheck}.
		@param fetcher: fetcher to manage the download (was Handler before version 1.5)
		@type fetcher: L{fetch.Fetcher}
		@param key_mirror: URL of directory containing keys, or None to use feed's directory
		@type key_mirror: str
		@rtype: [L{zeroinstall.support.tasks.Blocker}]"""
        downloads = {}
        blockers = []
        for x in self.sigs:
            key_id = x.need_key()
            if key_id:
                try:
                    import urlparse
                except ImportError:
                    from urllib import parse as urlparse  # Python 3
                key_url = urlparse.urljoin(key_mirror or self.url, "%s.gpg" % key_id)
                logger.info(_("Fetching key from %s"), key_url)
                dl = fetcher.download_url(key_url, hint=feed_hint)
                downloads[dl.downloaded] = (dl, dl.tempfile)
                blockers.append(dl.downloaded)

        exception = None
        any_success = False

        from zeroinstall.support import tasks

        while blockers:
            yield blockers

            old_blockers = blockers
            blockers = []

            for b in old_blockers:
                dl, stream = downloads[b]
                try:
                    tasks.check(b)
                    if b.happened:
                        stream.seek(0)
                        self._downloaded_key(stream)
                        any_success = True
                        stream.close()
                    else:
                        blockers.append(b)
                except Exception:
                    _type, exception, tb = sys.exc_info()
                    logger.warning(
                        _("Failed to import key for '%(url)s': %(exception)s"),
                        {"url": self.url, "exception": str(exception)},
                    )
                    stream.close()

        if exception and not any_success:
            raise_with_traceback(exception, tb)

        self.recheck()
Example #5
0
    def tearDown(self):
        if self.config.handler.ex:
            support.raise_with_traceback(self.config.handler.ex, self.config.handler.tb)

        shutil.rmtree(self.config_home)
        support.ro_rmtree(self.cache_home)
        shutil.rmtree(self.cache_system)
        shutil.rmtree(self.gnupg_home)

        os.environ["PATH"] = self.old_path
Example #6
0
	def tearDown(self):
		if self.config.handler.ex:
			support.raise_with_traceback(self.config.handler.ex, self.config.handler.tb)

		shutil.rmtree(self.config_home)
		support.ro_rmtree(self.cache_home)
		shutil.rmtree(self.cache_system)
		shutil.rmtree(self.gnupg_home)

		os.environ['PATH'] = self.old_path
Example #7
0
def do_confirm_distro_install(config, ticket, options, impls):
	if gui_driver is not None: config = gui_driver.config
	try:
		manual_impls = [impl['id'] for impl in impls if not impl['needs-confirmation']]
		unsafe_impls = [impl for impl in impls if impl['needs-confirmation']]

		if unsafe_impls:
			confirm = config.handler.confirm_install(_('The following components need to be installed using native packages. '
				'These come from your distribution, and should therefore be trustworthy, but they also '
				'run with extra privileges. In particular, installing them may run extra services on your '
				'computer or affect other users. You may be asked to enter a password to confirm. The '
				'packages are:\n\n') + ('\n'.join('- ' + x['id'] for x in unsafe_impls)))
			yield confirm
			tasks.check(confirm)

		if manual_impls:
			raise model.SafeException(_("This program depends on '%s', which is a package that is available through your distribution. "
					"Please install it manually using your distribution's tools and try again. Or, install 'packagekit' and I can "
					"use that to install it.") % manual_impls[0])

		blockers = []
		for impl in unsafe_impls:
			from zeroinstall.injector import packagekit
			packagekit_id = impl['packagekit-id']
			pk = get_distro().packagekit.pk
			dl = packagekit.PackageKitDownload('packagekit:' + packagekit_id, hint = impl['master-feed'],
					pk = pk, packagekit_id = packagekit_id, expected_size = int(impl['size']))
			config.handler.monitor_download(dl)
			blockers.append(dl.downloaded)

		# Record the first error log the rest
		error = []
		def dl_error(ex, tb = None):
			if error:
				config.handler.report_error(ex)
			else:
				error.append((ex, tb))
		while blockers:
			yield blockers
			tasks.check(blockers, dl_error)
			blockers = [b for b in blockers if not b.happened]
		if error:
			from zeroinstall import support
			support.raise_with_traceback(*error[0])

		send_json(["return", ticket, ["ok", "ok"]])
	except download.DownloadAborted as ex:
		send_json(["return", ticket, ["ok", "aborted-by-user"]])
	except Exception as ex:
		logger.warning("Returning error", exc_info = True)
		send_json(["return", ticket, ["error", str(ex)]])
Example #8
0
 def wait_for_blocker(self, blocker):
     self.ex = None
     handler.Handler.wait_for_blocker(self, blocker)
     if self.ex:
         support.raise_with_traceback(self.ex, self.tb)
Example #9
0
	def wait_for_blocker(self, blocker):
		self.ex = None
		handler.Handler.wait_for_blocker(self, blocker)
		if self.ex:
			support.raise_with_traceback(self.ex, self.tb)
Example #10
0
    def download_keys(self, fetcher, feed_hint=None, key_mirror=None):
        """Download any required GPG keys not already on our keyring.
		When all downloads are done (successful or otherwise), add any new keys
		to the keyring, L{recheck}.
		@param fetcher: fetcher to manage the download (was Handler before version 1.5)
		@type fetcher: L{fetch.Fetcher}
		@param key_mirror: URL of directory containing keys, or None to use feed's directory
		@type key_mirror: str
		@rtype: [L{zeroinstall.support.tasks.Blocker}]"""
        downloads = {}
        blockers = []
        for x in self.sigs:
            key_id = x.need_key()
            if key_id:
                try:
                    import urlparse
                except ImportError:
                    from urllib import parse as urlparse  # Python 3
                key_url = urlparse.urljoin(key_mirror or self.url,
                                           '%s.gpg' % key_id)
                logger.info(_("Fetching key from %s"), key_url)
                dl = fetcher.download_url(key_url, hint=feed_hint)
                downloads[dl.downloaded] = (dl, dl.tempfile)
                blockers.append(dl.downloaded)

        exception = None
        any_success = False

        from zeroinstall.support import tasks

        while blockers:
            yield blockers

            old_blockers = blockers
            blockers = []

            for b in old_blockers:
                dl, stream = downloads[b]
                try:
                    tasks.check(b)
                    if b.happened:
                        stream.seek(0)
                        self._downloaded_key(stream)
                        any_success = True
                        stream.close()
                    else:
                        blockers.append(b)
                except Exception:
                    _type, exception, tb = sys.exc_info()
                    logger.warning(
                        _("Failed to import key for '%(url)s': %(exception)s"),
                        {
                            'url': self.url,
                            'exception': str(exception)
                        })
                    stream.close()

        if exception and not any_success:
            raise_with_traceback(exception, tb)

        self.recheck()