def get_candidates(self, package_name, factory, prefix):
		"""Add any cached candidates.
		The candidates are those discovered by a previous call to L{fetch_candidates}.
		@param package_name: the distribution's name for the package
		@param factory: a function to add a new implementation to the feed
		@param prefix: the prefix for the implementation's ID
		"""
		candidates = self._candidates.get(package_name, None)
		if candidates is None:
			return

		if isinstance(candidates, tasks.Blocker):
			return		# Fetch still in progress

		for candidate in candidates:
			impl_name = '%s:%s:%s:%s' % (prefix, package_name, candidate['version'], candidate['arch'])

			impl = factory(impl_name, only_if_missing = True, installed = candidate['installed'])
			if impl is None:
				# (checking this way because the cached candidate['installed'] may be stale)
				return		# Already installed

			impl.version = model.parse_version(candidate['version'])
			if candidate['arch'] != '*':
				impl.machine = candidate['arch']

			def install(handler):
				packagekit_id = candidate['packagekit_id']
				dl = PackageKitDownload('packagekit:' + packagekit_id, hint = impl, pk = self.pk, packagekit_id = packagekit_id, expected_size = candidate['size'])
				handler.monitor_download(dl)
				return dl.downloaded
			impl.download_sources.append(model.DistributionSource(package_name, candidate['size'], install))
Exemple #2
0
    def get_package_info(self, package, factory):
        # Add any already-installed package...
        installed_cached_info = self._get_dpkg_info(package)

        if installed_cached_info != '-':
            installed_version, machine = installed_cached_info.split('\t')
            impl = factory('package:deb:%s:%s:%s' %
                           (package, installed_version, machine))
            impl.version = model.parse_version(installed_version)
            if machine != '*':
                impl.machine = machine
        else:
            installed_version = None

        # Add any uninstalled candidates (note: only one of these two methods will add anything)

        # From PackageKit...
        self.packagekit.get_candidates(package, factory, 'package:deb')

        # From apt-cache...
        cached = self.apt_cache.get(package, None)
        if cached:
            candidate_version = cached['version']
            candidate_arch = cached['arch']
            if candidate_version and candidate_version != installed_version:
                impl = factory('package:deb:%s:%s:%s' %
                               (package, candidate_version, candidate_arch),
                               installed=False)
                impl.version = model.parse_version(candidate_version)
                if candidate_arch != '*':
                    impl.machine = candidate_arch

                def install(handler):
                    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.") % package)

                impl.download_sources.append(
                    model.DistributionSource(package,
                                             cached['size'],
                                             install,
                                             needs_confirmation=False))