Beispiel #1
0
def do_optimise(args):
	"""optimise [ CACHE ]"""
	if len(args) == 1:
		cache_dir = args[0]
	else:
		cache_dir = stores.stores[0].dir
	
	cache_dir = os.path.realpath(cache_dir)

	import stat
	info = os.stat(cache_dir)
	if not stat.S_ISDIR(info.st_mode):
		raise UsageError(_("Not a directory: '%s'") % cache_dir)

	impl_name = os.path.basename(cache_dir)
	if impl_name != 'implementations':
		raise UsageError(_("Cache directory should be named 'implementations', not\n"
				"'%(name)s' (in '%(cache_dir)s')") % {'name': impl_name, 'cache_dir': cache_dir})

	print(_("Optimising"), cache_dir)

	from . import optimise
	uniq_size, dup_size, already_linked, man_size = optimise.optimise(cache_dir)
	print(_("Original size  : %(size)s (excluding the %(manifest_size)s of manifests)") % {'size': support.pretty_size(uniq_size + dup_size), 'manifest_size': support.pretty_size(man_size)})
	print(_("Already saved  : %s") % support.pretty_size(already_linked))
	if dup_size == 0:
		print(_("No duplicates found; no changes made."))
	else:
		print(_("Optimised size : %s") % support.pretty_size(uniq_size))
		perc = (100 * float(dup_size)) / (uniq_size + dup_size)
		print(_("Space freed up : %(size)s (%(percentage).2f%%)") % {'size': support.pretty_size(dup_size), 'percentage': perc})
	print(_("Optimisation complete."))
Beispiel #2
0
def do_optimise(args):
	"""optimise [ CACHE ]"""
	if len(args) == 1:
		cache_dir = args[0]
	else:
		cache_dir = stores.stores[0].dir
	
	cache_dir = os.path.realpath(cache_dir)

	import stat
	info = os.stat(cache_dir)
	if not stat.S_ISDIR(info.st_mode):
		raise UsageError(_("Not a directory: '%s'") % cache_dir)

	impl_name = os.path.basename(cache_dir)
	if impl_name != 'implementations':
		raise UsageError(_("Cache directory should be named 'implementations', not\n"
				"'%(name)s' (in '%(cache_dir)s')") % {'name': impl_name, 'cache_dir': cache_dir})

	print(_("Optimising"), cache_dir)

	from . import optimise
	uniq_size, dup_size, already_linked, man_size = optimise.optimise(cache_dir)
	print(_("Original size  : %(size)s (excluding the %(manifest_size)s of manifests)") % {'size': support.pretty_size(uniq_size + dup_size), 'manifest_size': support.pretty_size(man_size)})
	print(_("Already saved  : %s") % support.pretty_size(already_linked))
	if dup_size == 0:
		print(_("No duplicates found; no changes made."))
	else:
		print(_("Optimised size : %s") % support.pretty_size(uniq_size))
		perc = (100 * float(dup_size)) / (uniq_size + dup_size)
		print(_("Space freed up : %(size)s (%(percentage).2f%%)") % {'size': support.pretty_size(dup_size), 'percentage': perc})
	print(_("Optimisation complete."))
	def update_download_status(self):
		"""Called at regular intervals while there are downloads in progress,
		and once at the end. Also called when things are added to the store.
		Update the TreeView with the interfaces."""

		# A download may be for a feed, an interface or an implementation.
		# Create the reverse mapping (item -> download)
		hints = {}
		for dl in self.policy.handler.monitored_downloads.values():
			if dl.hint:
				if dl.hint not in hints:
					hints[dl.hint] = []
				hints[dl.hint].append(dl)

		selections = self.policy.solver.selections

		# Only update currently visible rows
		if self.tree_view.get_visible_range() != None:
			firstVisiblePath, lastVisiblePath = self.tree_view.get_visible_range()
			firstVisibleIter = self.model.get_iter(firstVisiblePath)
			lastVisibleIter = self.model.get_iter(lastVisiblePath)
		else:
			firstVisibleIter = self.model.get_iter_root()
			lastVisibleIter = None

		for row in walk(self.model, firstVisibleIter, lastVisibleIter):
			iface = row[InterfaceBrowser.INTERFACE]

			# Is this interface the download's hint?
			downloads = hints.get(iface, [])	# The interface itself
		     	downloads += hints.get(iface.uri, [])	# The main feed
			for feed in self.policy.usable_feeds(iface):
				downloads += hints.get(feed.uri, []) # Other feeds
			impl = selections.get(iface, None)
			if impl:
				downloads += hints.get(impl, []) # The chosen implementation

			if downloads:
				so_far = 0
				expected = None
				for dl in downloads:
					if dl.expected_size:
						expected = (expected or 0) + dl.expected_size
					so_far += dl.get_bytes_downloaded_so_far()
				if expected:
					summary = ngettext("(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%])",
							   "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%] in %(number)d downloads)",
							   downloads)
					values_dict = {'downloaded': pretty_size(so_far), 'expected': pretty_size(expected), 'percentage': 100 * so_far / float(expected), 'number': len(downloads)}
				else:
					summary = ngettext("(downloading %(downloaded)s/unknown)",
							   "(downloading %(downloaded)s/unknown in %(number)d downloads)",
							   downloads)
					values_dict = {'downloaded': pretty_size(so_far), 'number': len(downloads)}
				row[InterfaceBrowser.SUMMARY] = summary % values_dict
			else:
				row[InterfaceBrowser.DOWNLOAD_SIZE] = utils.get_fetch_info(self.policy, impl)
				row[InterfaceBrowser.SUMMARY] = iface.summary
Beispiel #4
0
	def update_download_status(self, only_update_visible = False):
		"""Called at regular intervals while there are downloads in progress,
		and once at the end. Also called when things are added to the store.
		Update the TreeView with the interfaces."""

		# A download may be for a feed, an interface or an implementation.
		# Create the reverse mapping (item -> download)
		hints = {}
		for dl in self.config.handler.monitored_downloads:
			if dl.hint:
				if dl.hint not in hints:
					hints[dl.hint] = []
				hints[dl.hint].append(dl)

		# Only update currently visible rows
		if only_update_visible and self.tree_view.get_visible_range() != None:
			firstVisiblePath, lastVisiblePath = self.tree_view.get_visible_range()
			firstVisibleIter = self.model.get_iter(firstVisiblePath)
		else:
			# (or should we just wait until the TreeView has settled enough to tell
			# us what is visible?)
			firstVisibleIter = self.model.get_iter_root()
			lastVisiblePath = None

		for it in walk(self.model, firstVisibleIter):
			row = self.model[it]
			details = row[InterfaceBrowser.DETAILS]

			# Is this interface the download's hint?
			downloads = []
			for feed_url in details['all-feeds']:
				downloads += hints.get(feed_url, [])

			if downloads:
				so_far = 0
				expected = None
				for dl in downloads:
					if dl.expected_size:
						expected = (expected or 0) + dl.expected_size
					so_far += dl.get_bytes_downloaded_so_far()
				if expected:
					summary = ngettext("(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%])",
							   "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%] in %(number)d downloads)",
							   downloads)
					values_dict = {'downloaded': pretty_size(so_far), 'expected': pretty_size(expected), 'percentage': 100 * so_far / float(expected), 'number': len(downloads)}
				else:
					summary = ngettext("(downloading %(downloaded)s/unknown)",
							   "(downloading %(downloaded)s/unknown in %(number)d downloads)",
							   downloads)
					values_dict = {'downloaded': pretty_size(so_far), 'number': len(downloads)}
				row[InterfaceBrowser.SUMMARY] = summary % values_dict
			else:
				row[InterfaceBrowser.DOWNLOAD_SIZE] = details.get("fetch", "")
				row[InterfaceBrowser.SUMMARY] = details['summary']

			if self.model.get_path(it) == lastVisiblePath:
				break
Beispiel #5
0
 def update(itr):
     total = m[itr][SELF_SIZE.idx]
     total += sum(map(update, all_children(m, itr)))
     m[itr][PRETTY_SIZE.idx] = support.pretty_size(
         total) if total else '-'
     m[itr][TOTAL_SIZE.idx] = total
     return total
Beispiel #6
0
 def update(itr):
     total = m[itr][SELF_SIZE]
     child = m.iter_children(itr)
     while child:
         total += update(child)
         child = m.iter_next(child)
     m[itr][PRETTY_SIZE] = support.pretty_size(total)
     return total
Beispiel #7
0
 def update(itr):
     total = m[itr][SELF_SIZE]
     child = m.iter_children(itr)
     while child:
         total += update(child)
         child = m.iter_next(child)
     m[itr][PRETTY_SIZE] = support.pretty_size(total)
     return total
Beispiel #8
0
    def update_download_status(self, only_update_visible=False):
        """Called at regular intervals while there are downloads in progress,
		and once at the end. Update the display."""
        if not self.window:
            return  # (being destroyed)
        if not self.window.get_window():
            return  # (being destroyed)
        monitored_downloads = self.driver.config.handler.monitored_downloads

        self.browser.update_download_status(only_update_visible)

        if not monitored_downloads:
            self.progress_area.hide()
            self.window.get_window().set_cursor(None)
            return

        if not self.progress_area.get_property("visible"):
            self.progress_area.show()
            self.window.get_window().set_cursor(gtkutils.get_busy_pointer())

        any_known = False
        done = total = self.driver.config.handler.total_bytes_downloaded  # Completed downloads
        n_downloads = self.driver.config.handler.n_completed_downloads
        # Now add downloads in progress...
        for x in monitored_downloads:
            if x.status != download.download_fetching:
                continue
            n_downloads += 1
            if x.expected_size:
                any_known = True
            so_far = x.get_bytes_downloaded_so_far()
            total += x.expected_size or max(4096, so_far)  # Guess about 4K for feeds/icons
            done += so_far

        progress_text = "%s / %s" % (pretty_size(done), pretty_size(total))
        self.progress.set_text(
            ngettext("Downloading one file (%(progress)s)", "Downloading %(number)d files (%(progress)s)", n_downloads)
            % {"progress": progress_text, "number": n_downloads}
        )

        if total == 0 or (n_downloads < 2 and not any_known):
            self.progress.pulse()
        else:
            self.progress.set_fraction(float(done) / total)
    def update_download_status(self, only_update_visible=False):
        """Called at regular intervals while there are downloads in progress,
		and once at the end. Update the display."""
        monitored_downloads = self.policy.handler.monitored_downloads

        self.browser.update_download_status(only_update_visible)

        if not monitored_downloads:
            self.progress_area.hide()
            self.window.window.set_cursor(None)
            return

        if not self.progress_area.get_property('visible'):
            self.progress_area.show()
            self.window.window.set_cursor(gtkutils.get_busy_pointer())

        any_known = False
        done = total = self.policy.handler.total_bytes_downloaded  # Completed downloads
        n_downloads = self.policy.handler.n_completed_downloads
        # Now add downloads in progress...
        for x in monitored_downloads:
            if x.status != download.download_fetching: continue
            n_downloads += 1
            if x.expected_size:
                any_known = True
            so_far = x.get_bytes_downloaded_so_far()
            total += x.expected_size or max(
                4096, so_far)  # Guess about 4K for feeds/icons
            done += so_far

        progress_text = '%s / %s' % (pretty_size(done), pretty_size(total))
        self.progress.set_text(
            ngettext('Downloading one file (%(progress)s)',
                     'Downloading %(number)d files (%(progress)s)',
                     n_downloads) % {
                         'progress': progress_text,
                         'number': n_downloads
                     })

        if total == 0 or (n_downloads < 2 and not any_known):
            self.progress.pulse()
        else:
            self.progress.set_fraction(float(done) / total)
	def update_download_status(self):
		"""Called at regular intervals while there are downloads in progress,
		and once at the end. Update the display."""
		monitored_downloads = self.policy.handler.monitored_downloads

		self.browser.update_download_status()

		if not monitored_downloads:
			self.progress_area.hide()
			self.window.window.set_cursor(None)
			return

		if not self.progress_area.get_property('visible'):
			self.progress_area.show()
			self.window.window.set_cursor(gtkutils.get_busy_pointer())

		any_known = False
		done = total = self.policy.handler.total_bytes_downloaded	# Completed downloads
		n_downloads = self.policy.handler.n_completed_downloads
		# Now add downloads in progress...
		for x in monitored_downloads.values():
			if x.status != download.download_fetching: continue
			n_downloads += 1
			if x.expected_size:
				any_known = True
			so_far = x.get_bytes_downloaded_so_far()
			total += x.expected_size or max(4096, so_far)	# Guess about 4K for feeds/icons
			done += so_far

		progress_text = '%s / %s' % (pretty_size(done), pretty_size(total))
		self.progress.set_text(
			ngettext('Downloading one file (%(progress)s)',
					 'Downloading %(number)d files (%(progress)s)', n_downloads)
			% {'progress': progress_text, 'number': n_downloads})

		if total == 0 or (n_downloads < 2 and not any_known):
			self.progress.pulse()
		else:
			self.progress.set_fraction(float(done) / total)
def get_tooltip_text(policy, interface, impl):
	if impl.local_path:
		return _("Local: %s") % impl.local_path
	if impl.id.startswith('package:'):
		return _("Native package: %s") % impl.id.split(':', 1)[1]
	if policy.get_cached(impl):
		return _("Cached: %s") % policy.get_implementation_path(impl)

	src = policy.fetcher.get_best_source(impl)
	if src:
		size = support.pretty_size(src.size)
		return _("Not yet downloaded (%s)") % size
	else:
		return _("No downloads available!")
Beispiel #12
0
def get_tooltip_text(config, interface, impl):
    if impl.local_path:
        return _("Local: %s") % impl.local_path
    if impl.id.startswith('package:'):
        return _("Native package: %s") % impl.id.split(':', 1)[1]
    if impl.is_available(config.stores):
        return _("Cached: %s") % config.stores.lookup_any(impl.digests)

    src = config.fetcher.get_best_source(impl)
    if src:
        size = support.pretty_size(src.size)
        return _("Not yet downloaded (%s)") % size
    else:
        return _("No downloads available!")
Beispiel #13
0
def get_tooltip_text(config, interface, impl):
	if impl.local_path:
		return _("Local: %s") % impl.local_path
	if impl.id.startswith('package:'):
		return _("Native package: %s") % impl.id.split(':', 1)[1]
	if impl.is_available(config.stores):
		return _("Cached: %s") % config.stores.lookup_any(impl.digests)

	src = config.fetcher.get_best_source(impl)
	if src:
		size = support.pretty_size(src.size)
		return _("Not yet downloaded (%s)") % size
	else:
		return _("No downloads available!")
Beispiel #14
0
	def get_tooltip_text(self):
		impl = self.item
		if impl.id.startswith('/'):
			return _("Local: %s") % impl.id
		if impl.id.startswith('package:'):
			return _("Native package: %s") % impl.id.split(':', 1)[1]
		if self.policy.get_cached(impl):
			return _("Cached: %s") % self.policy.get_implementation_path(impl)

		src = self.policy.fetcher.get_best_source(impl)
		if src:
			size = support.pretty_size(src.size)
			return _("Not yet downloaded (%s)") % size
		else:
			return _("No downloads available!")
Beispiel #15
0
def get_fetch_info(policy, impl):
    """Get the text for a Fetch column."""
    if impl is None:
        return ""
    elif policy.get_cached(impl):
        if impl.id.startswith('/'):
            return _('(local)')
        elif impl.id.startswith('package:'):
            return _('(package)')
        else:
            return _('(cached)')
    else:
        src = policy.fetcher.get_best_source(impl)
        if src:
            return support.pretty_size(src.size)
        else:
            return _('(unavailable)')
Beispiel #16
0
def get_fetch_info(config, impl):
	"""Get the text for a Fetch column."""
	if impl is None:
		return ""
	elif impl.is_available(config.stores):
		if impl.local_path:
			return _('(local)')
		elif impl.id.startswith('package:'):
			return _('(package)')
		else:
			return _('(cached)')
	else:
		src = config.fetcher.get_best_source(impl)
		if src:
			return support.pretty_size(src.size)
		else:
			return _('(unavailable)')
Beispiel #17
0
def get_fetch_info(policy, impl):
    """Get the text for a Fetch column."""
    if impl is None:
        return ""
    elif policy.get_cached(impl):
        if impl.local_path:
            return _("(local)")
        elif impl.id.startswith("package:"):
            return _("(package)")
        else:
            return _("(cached)")
    else:
        src = policy.fetcher.get_best_source(impl)
        if src:
            return support.pretty_size(src.size)
        else:
            return _("(unavailable)")
Beispiel #18
0
def get_fetch_info(config, impl):
	"""Get the text for a Fetch column."""
	if impl is None:
		return ""
	elif impl.is_available(config.stores):
		if impl.local_path:
			return _('(local)')
		elif impl.id.startswith('package:'):
			return _('(package)')
		else:
			return _('(cached)')
	else:
		src = config.fetcher.get_best_source(impl)
		if src:
			return support.pretty_size(src.size)
		else:
			return _('(unavailable)')
    def get_tooltip_text(self):
        interface, model_column = self.item
        assert interface
        if model_column == InterfaceBrowser.INTERFACE_NAME:
            return _("Full name: %s") % interface.uri
        elif model_column == InterfaceBrowser.SUMMARY:
            if not interface.description:
                return None
            first_para = interface.description.split('\n\n', 1)[0]
            return first_para.replace('\n', ' ')
        elif model_column is None:
            return _("Click here for more options...")

        impl = self.mainwindow.policy.implementation.get(interface, None)
        if not impl:
            return _("No suitable implementation was found. Check the "
                     "interface properties to find out why.")

        if model_column == InterfaceBrowser.VERSION:
            text = _("Currently preferred version: %(version)s (%(stability)s)") % \
              {'version': impl.get_version(), 'stability': _stability(impl)}
            old_impl = self.mainwindow.original_implementation.get(
                interface, None)
            if old_impl is not None and old_impl is not impl:
                text += '\n' + _('Previously preferred version: %(version)s (%(stability)s)') % \
                 {'version': old_impl.get_version(), 'stability': _stability(old_impl)}
            return text

        assert model_column == InterfaceBrowser.DOWNLOAD_SIZE

        if self.mainwindow.policy.get_cached(impl):
            return _("This version is already stored on your computer.")
        else:
            src = self.mainwindow.policy.fetcher.get_best_source(impl)
            if not src:
                return _("No downloads available!")
            return _("Need to download %(pretty_size)s (%(size)s bytes)") % \
              {'pretty_size': support.pretty_size(src.size), 'size': src.size}
Beispiel #20
0
def get_tooltip_text(mainwindow, interface, main_feed, model_column):
	assert interface
	if model_column == InterfaceBrowser.INTERFACE_NAME:
		return _("Full name: %s") % interface.uri
	elif model_column == InterfaceBrowser.SUMMARY:
		if main_feed is None or not main_feed.description:
			return _("(no description available)")
		first_para = main_feed.description.split('\n\n', 1)[0]
		return first_para.replace('\n', ' ')
	elif model_column is None:
		return _("Click here for more options...")

	impl = mainwindow.policy.implementation.get(interface, None)
	if not impl:
		return _("No suitable version was found. Double-click "
			 "here to find out why.")

	if model_column == InterfaceBrowser.VERSION:
		text = _("Currently preferred version: %(version)s (%(stability)s)") % \
				{'version': impl.get_version(), 'stability': _stability(impl)}
		old_impl = mainwindow.original_implementation.get(interface, None)
		if old_impl is not None and old_impl is not impl:
			text += '\n' + _('Previously preferred version: %(version)s (%(stability)s)') % \
				{'version': old_impl.get_version(), 'stability': _stability(old_impl)}
		return text

	assert model_column == InterfaceBrowser.DOWNLOAD_SIZE

	if mainwindow.policy.get_cached(impl):
		return _("This version is already stored on your computer.")
	else:
		src = mainwindow.policy.fetcher.get_best_source(impl)
		if not src:
			return _("No downloads available!")
		return _("Need to download %(pretty_size)s (%(size)s bytes)") % \
				{'pretty_size': support.pretty_size(src.size), 'size': src.size}
Beispiel #21
0
def get_tooltip_text(mainwindow, interface, main_feed, model_column):
	assert interface
	if model_column == InterfaceBrowser.INTERFACE_NAME:
		return _("Full name: %s") % interface.uri
	elif model_column == InterfaceBrowser.SUMMARY:
		if main_feed is None or not main_feed.description:
			return _("(no description available)")
		first_para = main_feed.description.split('\n\n', 1)[0]
		return first_para.replace('\n', ' ')
	elif model_column is None:
		return _("Click here for more options...")

	impl = mainwindow.driver.solver.selections.get(interface, None)
	if not impl:
		return _("No suitable version was found. Double-click "
			 "here to find out why.")

	if model_column == InterfaceBrowser.VERSION:
		text = _("Currently preferred version: %(version)s (%(stability)s)") % \
				{'version': impl.get_version(), 'stability': _stability(impl)}
		old_impl = mainwindow.original_implementation.get(interface, None)
		if old_impl is not None and old_impl is not impl:
			text += '\n' + _('Previously preferred version: %(version)s (%(stability)s)') % \
				{'version': old_impl.get_version(), 'stability': _stability(old_impl)}
		return text

	assert model_column == InterfaceBrowser.DOWNLOAD_SIZE

	if impl.is_available(mainwindow.driver.config.stores):
		return _("This version is already stored on your computer.")
	else:
		src = mainwindow.driver.config.fetcher.get_best_source(impl)
		if not src:
			return _("No downloads available!")
		return _("Need to download %(pretty_size)s (%(size)s bytes)") % \
				{'pretty_size': support.pretty_size(src.size), 'size': src.size}
Beispiel #22
0
	def update_download_status(self, only_update_visible = False):
		"""Called at regular intervals while there are downloads in progress,
		and once at the end. Also called when things are added to the store.
		Update the TreeView with the interfaces."""

		# A download may be for a feed, an interface or an implementation.
		# Create the reverse mapping (item -> download)
		hints = {}
		for dl in self.config.handler.monitored_downloads:
			if dl.hint:
				if dl.hint not in hints:
					hints[dl.hint] = []
				hints[dl.hint].append(dl)

		selections = self.driver.solver.selections

		# Only update currently visible rows
		if only_update_visible and self.tree_view.get_visible_range() != None:
			firstVisiblePath, lastVisiblePath = self.tree_view.get_visible_range()
			firstVisibleIter = self.model.get_iter(firstVisiblePath)
		else:
			# (or should we just wait until the TreeView has settled enough to tell
			# us what is visible?)
			firstVisibleIter = self.model.get_iter_root()
			lastVisiblePath = None

		solver = self.driver.solver
		requirements = self.driver.requirements
		iface_cache = self.config.iface_cache

		for it in walk(self.model, firstVisibleIter):
			row = self.model[it]
			iface = row[InterfaceBrowser.INTERFACE]

			# Is this interface the download's hint?
			downloads = hints.get(iface, [])	# The interface itself
			downloads += hints.get(iface.uri, [])	# The main feed

			arch = solver.get_arch_for(requirements, iface)
			for feed in iface_cache.usable_feeds(iface, arch):
				downloads += hints.get(feed.uri, []) # Other feeds
			impl = selections.get(iface, None)
			if impl:
				downloads += hints.get(impl, []) # The chosen implementation

			if downloads:
				so_far = 0
				expected = None
				for dl in downloads:
					if dl.expected_size:
						expected = (expected or 0) + dl.expected_size
					so_far += dl.get_bytes_downloaded_so_far()
				if expected:
					summary = ngettext("(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%])",
							   "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%] in %(number)d downloads)",
							   downloads)
					values_dict = {'downloaded': pretty_size(so_far), 'expected': pretty_size(expected), 'percentage': 100 * so_far / float(expected), 'number': len(downloads)}
				else:
					summary = ngettext("(downloading %(downloaded)s/unknown)",
							   "(downloading %(downloaded)s/unknown in %(number)d downloads)",
							   downloads)
					values_dict = {'downloaded': pretty_size(so_far), 'number': len(downloads)}
				row[InterfaceBrowser.SUMMARY] = summary % values_dict
			else:
				feed = iface_cache.get_feed(iface.uri)
				row[InterfaceBrowser.DOWNLOAD_SIZE] = utils.get_fetch_info(self.config, impl)
				row[InterfaceBrowser.SUMMARY] = feed.summary if feed else "-"

			if self.model.get_path(it) == lastVisiblePath:
				break
    def update_download_status(self):
        """Called at regular intervals while there are downloads in progress,
		and once at the end. Also called when things are added to the store.
		Update the TreeView with the interfaces."""
        hints = {}
        for dl in self.policy.handler.monitored_downloads.values():
            if dl.hint:
                if dl.hint not in hints:
                    hints[dl.hint] = []
                hints[dl.hint].append(dl)

        selections = self.policy.solver.selections

        def walk(it):
            while it:
                yield self.model[it]
                for x in walk(self.model.iter_children(it)):
                    yield x
                it = self.model.iter_next(it)

        for row in walk(self.model.get_iter_root()):
            iface = row[InterfaceBrowser.INTERFACE]

            # Is this interface the download's hint?
            downloads = hints.get(iface, [])  # The interface itself
            downloads += hints.get(iface.uri, [])  # The main feed
            for feed in iface.feeds:
                downloads += hints.get(feed.uri, [])  # Other feeds
            impl = selections.get(iface, None)
            if impl:
                downloads += hints.get(impl, [])  # The chosen implementation

            if downloads:
                so_far = 0
                expected = None
                for dl in downloads:
                    if dl.expected_size:
                        expected = (expected or 0) + dl.expected_size
                    so_far += dl.get_bytes_downloaded_so_far()
                if expected:
                    summary = ngettext(
                        "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%])",
                        "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%] in %(number)d downloads)",
                        downloads)
                    values_dict = {
                        'downloaded': pretty_size(so_far),
                        'expected': pretty_size(expected),
                        'percentage': 100 * so_far / float(expected),
                        'number': len(downloads)
                    }
                else:
                    summary = ngettext(
                        "(downloading %(downloaded)s/unknown)",
                        "(downloading %(downloaded)s/unknown in %(number)d downloads)",
                        downloads)
                    values_dict = {
                        'downloaded': pretty_size(so_far),
                        'number': len(downloads)
                    }
                row[InterfaceBrowser.SUMMARY] = summary % values_dict
            else:
                row[InterfaceBrowser.DOWNLOAD_SIZE] = utils.get_fetch_info(
                    self.policy, impl)
                row[InterfaceBrowser.SUMMARY] = iface.summary
Beispiel #24
0
		def update(itr):
			total = m[itr][SELF_SIZE.idx]
			total += sum(map(update, all_children(m, itr)))
			m[itr][PRETTY_SIZE.idx] = support.pretty_size(total) if total else '-'
			m[itr][TOTAL_SIZE.idx] = total
			return total
    def update_download_status(self):
        """Called at regular intervals while there are downloads in progress,
		and once at the end. Also called when things are added to the store.
		Update the TreeView with the interfaces."""

        # A download may be for a feed, an interface or an implementation.
        # Create the reverse mapping (item -> download)
        hints = {}
        for dl in self.policy.handler.monitored_downloads.values():
            if dl.hint:
                if dl.hint not in hints:
                    hints[dl.hint] = []
                hints[dl.hint].append(dl)

        selections = self.policy.solver.selections

        # Only update currently visible rows
        if self.tree_view.get_visible_range() != None:
            firstVisiblePath, lastVisiblePath = self.tree_view.get_visible_range(
            )
            firstVisibleIter = self.model.get_iter(firstVisiblePath)
            lastVisibleIter = self.model.get_iter(lastVisiblePath)
        else:
            firstVisibleIter = self.model.get_iter_root()
            lastVisibleIter = None

        for row in walk(self.model, firstVisibleIter, lastVisibleIter):
            iface = row[InterfaceBrowser.INTERFACE]

            # Is this interface the download's hint?
            downloads = hints.get(iface, [])  # The interface itself
            downloads += hints.get(iface.uri, [])  # The main feed
            for feed in self.policy.usable_feeds(iface):
                downloads += hints.get(feed.uri, [])  # Other feeds
            impl = selections.get(iface, None)
            if impl:
                downloads += hints.get(impl, [])  # The chosen implementation

            if downloads:
                so_far = 0
                expected = None
                for dl in downloads:
                    if dl.expected_size:
                        expected = (expected or 0) + dl.expected_size
                    so_far += dl.get_bytes_downloaded_so_far()
                if expected:
                    summary = ngettext(
                        "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%])",
                        "(downloading %(downloaded)s/%(expected)s [%(percentage).2f%%] in %(number)d downloads)",
                        downloads)
                    values_dict = {
                        'downloaded': pretty_size(so_far),
                        'expected': pretty_size(expected),
                        'percentage': 100 * so_far / float(expected),
                        'number': len(downloads)
                    }
                else:
                    summary = ngettext(
                        "(downloading %(downloaded)s/unknown)",
                        "(downloading %(downloaded)s/unknown in %(number)d downloads)",
                        downloads)
                    values_dict = {
                        'downloaded': pretty_size(so_far),
                        'number': len(downloads)
                    }
                row[InterfaceBrowser.SUMMARY] = summary % values_dict
            else:
                row[InterfaceBrowser.DOWNLOAD_SIZE] = utils.get_fetch_info(
                    self.policy, impl)
                row[InterfaceBrowser.SUMMARY] = iface.summary