Example #1
0
def _check_for_updates(requirements, verbose, app):
    """@type requirements: L{zeroinstall.injector.requirements.Requirements}
	@type verbose: bool
	@type app: L{zeroinstall.apps.App}"""
    if app is not None:
        old_sels = app.get_selections()

    from zeroinstall.injector.driver import Driver
    from zeroinstall.injector.config import load_config

    background_handler = BackgroundHandler(requirements.interface_uri,
                                           requirements.interface_uri)
    background_config = load_config(background_handler)
    root_iface = background_config.iface_cache.get_interface(
        requirements.interface_uri).get_name()
    background_handler.title = root_iface

    driver = Driver(config=background_config, requirements=requirements)

    logger.info(_("Checking for updates to '%s' in a background process"),
                root_iface)
    if verbose:
        background_handler.notify("Zero Install",
                                  _("Checking for updates to '%s'...") %
                                  root_iface,
                                  timeout=1)

    network_state = background_handler.get_network_state()
    if network_state not in (_NetworkState.NM_STATE_CONNECTED_SITE,
                             _NetworkState.NM_STATE_CONNECTED_GLOBAL):
        logger.info(
            _("Not yet connected to network (status = %d). Sleeping for a bit..."
              ), network_state)
        import time
        time.sleep(120)
        if network_state in (_NetworkState.NM_STATE_DISCONNECTED,
                             _NetworkState.NM_STATE_ASLEEP):
            logger.info(_("Still not connected to network. Giving up."))
            sys.exit(1)
    else:
        logger.info(_("NetworkManager says we're on-line. Good!"))

    background_config.freshness = 0  # Don't bother trying to refresh when getting the interface
    refresh = driver.solve_with_downloads(
        force=True)  # (causes confusing log messages)
    tasks.wait_for_blocker(refresh)

    if background_handler.need_gui or not driver.solver.ready or driver.get_uncached_implementations(
    ):
        if verbose:
            background_handler.notify(
                "Zero Install",
                _("Updates ready to download for '%s'.") % root_iface,
                timeout=1)

        # Run the GUI if possible...
        from zeroinstall import helpers
        gui_args = ['--refresh', '--systray', '--download'
                    ] + requirements.get_as_options()
        new_sels = helpers.get_selections_gui(requirements.interface_uri,
                                              gui_args,
                                              use_gui=None)
        if new_sels is None:
            sys.exit(0)  # Cancelled by user
        elif new_sels is helpers.DontUseGUI:
            if not driver.solver.ready:
                background_handler.notify("Zero Install",
                                          _("Can't update '%s'") % root_iface)
                sys.exit(1)

            tasks.wait_for_blocker(driver.download_uncached_implementations())
            new_sels = driver.solver.selections

        if app is None:
            background_handler.notify(
                "Zero Install",
                _("{name} updated.").format(name=root_iface),
                timeout=1)
    else:
        if verbose:
            background_handler.notify("Zero Install",
                                      _("No updates to download."),
                                      timeout=1)
        new_sels = driver.solver.selections

    if app is not None:
        assert driver.solver.ready
        from zeroinstall.support import xmltools
        if not xmltools.nodes_equal(new_sels.toDOM(), old_sels.toDOM()):
            app.set_selections(new_sels)
            background_handler.notify(
                "Zero Install",
                _("{app} updated.").format(app=app.get_name()),
                timeout=1)
        app.set_last_checked()
    sys.exit(0)
Example #2
0
def _check_for_updates(requirements, verbose, app):
	if app is not None:
		old_sels = app.get_selections()

	from zeroinstall.injector.driver import Driver
	from zeroinstall.injector.config import load_config

	background_handler = BackgroundHandler(requirements.interface_uri, requirements.interface_uri)
	background_config = load_config(background_handler)
	root_iface = background_config.iface_cache.get_interface(requirements.interface_uri).get_name()
	background_handler.title = root_iface

	driver = Driver(config = background_config, requirements = requirements)

	logger.info(_("Checking for updates to '%s' in a background process"), root_iface)
	if verbose:
		background_handler.notify("Zero Install", _("Checking for updates to '%s'...") % root_iface, timeout = 1)

	network_state = background_handler.get_network_state()
	if network_state not in (_NetworkState.NM_STATE_CONNECTED_SITE, _NetworkState.NM_STATE_CONNECTED_GLOBAL):
		logger.info(_("Not yet connected to network (status = %d). Sleeping for a bit..."), network_state)
		import time
		time.sleep(120)
		if network_state in (_NetworkState.NM_STATE_DISCONNECTED, _NetworkState.NM_STATE_ASLEEP):
			logger.info(_("Still not connected to network. Giving up."))
			sys.exit(1)
	else:
		logger.info(_("NetworkManager says we're on-line. Good!"))

	background_config.freshness = 0			# Don't bother trying to refresh when getting the interface
	refresh = driver.solve_with_downloads(force = True)	# (causes confusing log messages)
	tasks.wait_for_blocker(refresh)

	if background_handler.need_gui or driver.get_uncached_implementations():
		if verbose:
			background_handler.notify("Zero Install",
					      _("Updates ready to download for '%s'.") % root_iface,
					      timeout = 1)

		# Run the GUI if possible...
		from zeroinstall import helpers
		gui_args = ['--refresh', '--systray', '--download'] + requirements.get_as_options()
		new_sels = helpers.get_selections_gui(requirements.interface_uri, gui_args, use_gui = None)
		if new_sels is None:
			sys.exit(0)	# Cancelled by user
		elif new_sels is helpers.DontUseGUI:
			tasks.wait_for_blocker(driver.download_uncached_implementations())
			new_sels = driver.solver.selections

		if app is None:
			background_handler.notify("Zero Install",
					      _("{name} updated.").format(name = root_iface),
					      timeout = 1)
	else:
		if verbose:
			background_handler.notify("Zero Install", _("No updates to download."), timeout = 1)
		new_sels = driver.solver.selections

	if app is not None:
		assert driver.solver.ready
		from zeroinstall.support import xmltools
		if not xmltools.nodes_equal(new_sels.toDOM(), old_sels.toDOM()):
			app.set_selections(new_sels)
			background_handler.notify("Zero Install",
					      _("{app} updated.").format(app = app.get_name()),
					      timeout = 1)
		app.set_last_checked()
	sys.exit(0)