Пример #1
0
    def testBackground(self, verbose=False):
        p = Policy('http://example.com:8000/Hello.xml', config=self.config)
        self.import_feed(p.root, 'Hello.xml')
        p.freshness = 0
        p.network_use = model.network_minimal
        p.solver.solve(p.root, arch.get_host_architecture())
        assert p.ready, p.solver.get_failure_reason()

        @tasks. async
        def choose_download(registed_cb, nid, actions):
            try:
                assert actions == ['download', 'Download'], actions
                registed_cb(nid, 'download')
            except:
                import traceback
                traceback.print_exc()
            yield None

        global ran_gui
        ran_gui = False
        old_out = sys.stdout
        try:
            sys.stdout = StringIO()
            self.child = server.handle_requests('Hello.xml',
                                                '6FCF121BE2390E0B.gpg')
            my_dbus.system_services = {
                "org.freedesktop.NetworkManager": {
                    "/org/freedesktop/NetworkManager": NetworkManager()
                }
            }
            my_dbus.user_callback = choose_download
            pid = os.getpid()
            old_exit = os._exit

            def my_exit(code):
                # The background handler runs in the same process
                # as the tests, so don't let it abort.
                if os.getpid() == pid:
                    raise SystemExit(code)
                # But, child download processes are OK
                old_exit(code)

            from zeroinstall.injector import config
            key_info = config.DEFAULT_KEY_LOOKUP_SERVER
            config.DEFAULT_KEY_LOOKUP_SERVER = None
            try:
                try:
                    os._exit = my_exit
                    background.spawn_background_update(p, verbose)
                    assert False
                except SystemExit as ex:
                    self.assertEquals(1, ex.code)
            finally:
                os._exit = old_exit
                config.DEFAULT_KEY_LOOKUP_SERVER = key_info
        finally:
            sys.stdout = old_out
        assert ran_gui
Пример #2
0
    def testBackground(self, verbose=False):
        p = Policy("http://example.com:8000/Hello.xml", config=self.config)
        self.import_feed(p.root, "Hello.xml")
        p.freshness = 0
        p.network_use = model.network_minimal
        p.solver.solve(p.root, arch.get_host_architecture())
        assert p.ready, p.solver.get_failure_reason()

        @tasks.async
        def choose_download(registed_cb, nid, actions):
            try:
                assert actions == ["download", "Download"], actions
                registed_cb(nid, "download")
            except:
                import traceback

                traceback.print_exc()
            yield None

        global ran_gui
        ran_gui = False
        old_out = sys.stdout
        try:
            sys.stdout = StringIO()
            self.child = server.handle_requests("Hello.xml", "6FCF121BE2390E0B.gpg")
            my_dbus.system_services = {
                "org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}
            }
            my_dbus.user_callback = choose_download
            pid = os.getpid()
            old_exit = os._exit

            def my_exit(code):
                # The background handler runs in the same process
                # as the tests, so don't let it abort.
                if os.getpid() == pid:
                    raise SystemExit(code)
                    # But, child download processes are OK
                old_exit(code)

            key_info = fetch.DEFAULT_KEY_LOOKUP_SERVER
            fetch.DEFAULT_KEY_LOOKUP_SERVER = None
            try:
                try:
                    os._exit = my_exit
                    background.spawn_background_update(p, verbose)
                    assert False
                except SystemExit, ex:
                    self.assertEquals(1, ex.code)
            finally:
                os._exit = old_exit
                fetch.DEFAULT_KEY_LOOKUP_SERVER = key_info
        finally:
            sys.stdout = old_out
        assert ran_gui
Пример #3
0
	def testBackground(self, verbose = False):
		r = Requirements('http://example.com:8000/Hello.xml')
		d = Driver(requirements = r, config = self.config)
		self.import_feed(r.interface_uri, 'Hello.xml')
		self.config.freshness = 0
		self.config.network_use = model.network_minimal
		d.solver.solve(r.interface_uri, arch.get_host_architecture())
		assert d.solver.ready, d.solver.get_failure_reason()

		@tasks.async
		def choose_download(registed_cb, nid, actions):
			try:
				assert actions == ['download', 'Download'], actions
				registed_cb(nid, 'download')
			except:
				import traceback
				traceback.print_exc()
			yield None

		global ran_gui
		ran_gui = False
		old_out = sys.stdout
		try:
			sys.stdout = StringIO()
			run_server('Hello.xml', '6FCF121BE2390E0B.gpg')
			my_dbus.system_services = {"org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}}
			my_dbus.user_callback = choose_download
			pid = os.getpid()
			old_exit = os._exit
			def my_exit(code):
				# The background handler runs in the same process
				# as the tests, so don't let it abort.
				if os.getpid() == pid:
					raise SystemExit(code)
				# But, child download processes are OK
				old_exit(code)
			from zeroinstall.injector import config
			key_info = config.DEFAULT_KEY_LOOKUP_SERVER
			config.DEFAULT_KEY_LOOKUP_SERVER = None
			try:
				try:
					os._exit = my_exit
					background.spawn_background_update(d, verbose)
					assert False
				except SystemExit as ex:
					self.assertEqual(1, ex.code)
			finally:
				os._exit = old_exit
				config.DEFAULT_KEY_LOOKUP_SERVER = key_info
		finally:
			sys.stdout = old_out
		assert ran_gui
Пример #4
0
    def testBackground(self, verbose=False):
        r = Requirements('http://example.com:8000/Hello.xml')
        d = Driver(requirements=r, config=self.config)
        self.import_feed(r.interface_uri, 'Hello.xml')
        self.config.freshness = 0
        self.config.network_use = model.network_minimal
        d.solver.solve(r.interface_uri, arch.get_host_architecture())
        assert d.solver.ready, d.solver.get_failure_reason()

        @tasks. async
        def choose_download(registed_cb, nid, actions):
            try:
                assert actions == ['download', 'Download'], actions
                registed_cb(nid, 'download')
            except:
                import traceback
                traceback.print_exc()
            yield None

        global ran_gui
        ran_gui = False
        os.environ['DISPLAY'] = 'dummy'
        old_out = sys.stdout
        try:
            sys.stdout = StringIO()
            run_server('Hello.xml', '6FCF121BE2390E0B.gpg')
            my_dbus.system_services = {
                "org.freedesktop.NetworkManager": {
                    "/org/freedesktop/NetworkManager": NetworkManager()
                }
            }
            my_dbus.user_callback = choose_download

            with trapped_exit(1):
                from zeroinstall.injector import config
                key_info = config.DEFAULT_KEY_LOOKUP_SERVER
                config.DEFAULT_KEY_LOOKUP_SERVER = None
                try:
                    background.spawn_background_update(d, verbose)
                finally:
                    config.DEFAULT_KEY_LOOKUP_SERVER = key_info
        finally:
            sys.stdout = old_out
        assert ran_gui
Пример #5
0
	def testBackground(self, verbose = False):
		r = Requirements('http://example.com:8000/Hello.xml')
		d = Driver(requirements = r, config = self.config)
		self.import_feed(r.interface_uri, 'Hello.xml')
		self.config.freshness = 0
		self.config.network_use = model.network_minimal
		d.solver.solve(r.interface_uri, arch.get_host_architecture())
		assert d.solver.ready, d.solver.get_failure_reason()

		@tasks.async
		def choose_download(registed_cb, nid, actions):
			try:
				assert actions == ['download', 'Download'], actions
				registed_cb(nid, 'download')
			except:
				import traceback
				traceback.print_exc()
			yield None

		global ran_gui
		ran_gui = False
		os.environ['DISPLAY'] = 'dummy'
		old_out = sys.stdout
		try:
			sys.stdout = StringIO()
			run_server('Hello.xml', '6FCF121BE2390E0B.gpg')
			my_dbus.system_services = {"org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}}
			my_dbus.user_callback = choose_download

			with trapped_exit(1):
				from zeroinstall.injector import config
				key_info = config.DEFAULT_KEY_LOOKUP_SERVER
				config.DEFAULT_KEY_LOOKUP_SERVER = None
				try:
					background.spawn_background_update(d, verbose)
				finally:
					config.DEFAULT_KEY_LOOKUP_SERVER = key_info
		finally:
			sys.stdout = old_out
		assert ran_gui
Пример #6
0
def get_selections_for(requirements, config, options, select_only, download_only, test_callback):
	"""Get selections for given requirements.
	@since: 1.9"""
	if options.offline:
		config.network_use = model.network_offline

	iface_cache = config.iface_cache

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

	# Note that need_download() triggers a solve
	if options.refresh or options.gui:
		# We could run immediately, but the user asked us not to
		can_run_immediately = False
	else:
		if select_only:
			# --select-only: we only care that we've made a selection, not that we've cached the implementations
			driver.need_download()
			can_run_immediately = driver.solver.ready
		else:
			can_run_immediately = not driver.need_download()

		stale_feeds = [feed for feed in driver.solver.feeds_used if
				not feed.startswith('distribution:') and	# Ignore (memory-only) PackageKit feeds
				iface_cache.is_stale(feed, config.freshness)]

		if download_only and stale_feeds:
			can_run_immediately = False

	if can_run_immediately:
		if stale_feeds:
			if config.network_use == model.network_offline:
				logger.debug(_("No doing background update because we are in off-line mode."))
			else:
				# There are feeds we should update, but we can run without them.
				# Do the update in the background while the program is running.
				from zeroinstall.injector import background
				background.spawn_background_update(driver, options.verbose)
		return driver.solver.selections

	# If we need to download anything, we might as well
	# refresh all the feeds first.
	options.refresh = True

	if options.gui != False:
		# If the user didn't say whether to use the GUI, choose for them.
		gui_args = driver.requirements.get_as_options()
		if download_only:
			# Just changes the button's label
			gui_args.append('--download-only')
		if options.refresh:
			gui_args.append('--refresh')
		if options.verbose:
			gui_args.insert(0, '--verbose')
			if options.verbose > 1:
				gui_args.insert(0, '--verbose')
		if options.with_store:
			for x in options.with_store:
				gui_args += ['--with-store', x]
		if select_only:
			gui_args.append('--select-only')

		from zeroinstall import helpers
		sels = helpers.get_selections_gui(requirements.interface_uri, gui_args, test_callback, use_gui = options.gui)

		if not sels:
			return None		# Aborted
		elif sels is helpers.DontUseGUI:
			sels = None
	else:
		sels = None

	if sels is None:
		# Note: --download-only also makes us stop and download stale feeds first.
		downloaded = driver.solve_and_download_impls(refresh = options.refresh or download_only or False,
							     select_only = select_only)
		if downloaded:
			tasks.wait_for_blocker(downloaded)
		sels = driver.solver.selections

	return sels
Пример #7
0
def get_selections_for(requirements, config, options, select_only,
                       download_only, test_callback):
    """Get selections for given requirements.
	@since: 1.9"""
    if options.offline:
        config.network_use = model.network_offline

    iface_cache = config.iface_cache

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

    # Note that need_download() triggers a solve
    if options.refresh or options.gui:
        # We could run immediately, but the user asked us not to
        can_run_immediately = False
    else:
        if select_only:
            # --select-only: we only care that we've made a selection, not that we've cached the implementations
            driver.need_download()
            can_run_immediately = driver.solver.ready
        else:
            can_run_immediately = not driver.need_download()

        stale_feeds = [
            feed for feed in driver.solver.feeds_used
            if not feed.startswith('distribution:')
            and  # Ignore (memory-only) PackageKit feeds
            iface_cache.is_stale(feed, config.freshness)
        ]

        if download_only and stale_feeds:
            can_run_immediately = False

    if can_run_immediately:
        if stale_feeds:
            if config.network_use == model.network_offline:
                logger.debug(
                    _("No doing background update because we are in off-line mode."
                      ))
            else:
                # There are feeds we should update, but we can run without them.
                # Do the update in the background while the program is running.
                from zeroinstall.injector import background
                background.spawn_background_update(driver, options.verbose)
        return driver.solver.selections

    # If we need to download anything, we might as well
    # refresh all the feeds first.
    options.refresh = True

    if options.gui != False:
        # If the user didn't say whether to use the GUI, choose for them.
        gui_args = driver.requirements.get_as_options()
        if download_only:
            # Just changes the button's label
            gui_args.append('--download-only')
        if options.refresh:
            gui_args.append('--refresh')
        if options.verbose:
            gui_args.insert(0, '--verbose')
            if options.verbose > 1:
                gui_args.insert(0, '--verbose')
        if options.with_store:
            for x in options.with_store:
                gui_args += ['--with-store', x]
        if select_only:
            gui_args.append('--select-only')

        from zeroinstall import helpers
        sels = helpers.get_selections_gui(requirements.interface_uri,
                                          gui_args,
                                          test_callback,
                                          use_gui=options.gui)

        if not sels:
            return None  # Aborted
        elif sels is helpers.DontUseGUI:
            sels = None
    else:
        sels = None

    if sels is None:
        # Note: --download-only also makes us stop and download stale feeds first.
        downloaded = driver.solve_and_download_impls(refresh=options.refresh
                                                     or download_only or False,
                                                     select_only=select_only)
        if downloaded:
            tasks.wait_for_blocker(downloaded)
        sels = driver.solver.selections

    return sels
Пример #8
0
def get_selections(config, options, iface_uri, select_only, download_only, test_callback):
	"""Get selections for iface_uri, according to the options passed.
	Will switch to GUI mode if necessary.
	@param options: options from OptionParser
	@param iface_uri: canonical URI of the interface
	@param select_only: return immediately even if the selected versions aren't cached
	@param download_only: wait for stale feeds, and display GUI button as Download, not Run
	@return: the selected versions, or None if the user cancels
	@rtype: L{selections.Selections} | None
	"""
	if options.offline:
		config.network_use = model.network_offline

	# Try to load it as a feed. If it is a feed, it'll get cached. If not, it's a
	# selections document and we return immediately.
	maybe_selections = config.iface_cache.get_feed(iface_uri, selections_ok = True)
	if isinstance(maybe_selections, selections.Selections):
		if not select_only:
			blocker = maybe_selections.download_missing(config)
			if blocker:
				logging.info(_("Waiting for selected implementations to be downloaded..."))
				config.handler.wait_for_blocker(blocker)
		return maybe_selections

	r = requirements.Requirements(iface_uri)
	r.parse_options(options)

	policy = Policy(config = config, requirements = r)

	# Note that need_download() triggers a solve
	if options.refresh or options.gui:
		# We could run immediately, but the user asked us not to
		can_run_immediately = False
	else:
		if select_only:
			# --select-only: we only care that we've made a selection, not that we've cached the implementations
			policy.need_download()
			can_run_immediately = policy.ready
		else:
			can_run_immediately = not policy.need_download()

		stale_feeds = [feed for feed in policy.solver.feeds_used if
				not feed.startswith('distribution:') and	# Ignore (memory-only) PackageKit feeds
				policy.is_stale(config.iface_cache.get_feed(feed))]

		if download_only and stale_feeds:
			can_run_immediately = False

	if can_run_immediately:
		if stale_feeds:
			if policy.network_use == model.network_offline:
				logging.debug(_("No doing background update because we are in off-line mode."))
			else:
				# There are feeds we should update, but we can run without them.
				# Do the update in the background while the program is running.
				from zeroinstall.injector import background
				background.spawn_background_update(policy, options.verbose > 0)
		return policy.solver.selections

	# If the user didn't say whether to use the GUI, choose for them.
	if options.gui is None and os.environ.get('DISPLAY', None):
		options.gui = True
		# If we need to download anything, we might as well
		# refresh all the feeds first.
		options.refresh = True
		logging.info(_("Switching to GUI mode... (use --console to disable)"))

	if options.gui:
		gui_args = policy.requirements.get_as_options()
		if download_only:
			# Just changes the button's label
			gui_args.append('--download-only')
		if options.refresh:
			gui_args.append('--refresh')
		if options.verbose:
			gui_args.insert(0, '--verbose')
			if options.verbose > 1:
				gui_args.insert(0, '--verbose')
		if options.with_store:
			for x in options.with_store:
				gui_args += ['--with-store', x]
		if select_only:
			gui_args.append('--select-only')

		from zeroinstall import helpers
		sels = helpers.get_selections_gui(iface_uri, gui_args, test_callback)

		if not sels:
			return None		# Aborted
	else:
		# Note: --download-only also makes us stop and download stale feeds first.
		downloaded = policy.solve_and_download_impls(refresh = options.refresh or download_only or False,
							     select_only = select_only)
		if downloaded:
			config.handler.wait_for_blocker(downloaded)
		sels = selections.Selections(policy)

	return sels
Пример #9
0
def get_selections(config, options, iface_uri, select_only, download_only, test_callback):
	"""Get selections for iface_uri, according to the options passed.
	Will switch to GUI mode if necessary.
	@param options: options from OptionParser
	@param iface_uri: canonical URI of the interface
	@param select_only: return immediately even if the selected versions aren't cached
	@param download_only: wait for stale feeds, and display GUI button as Download, not Run
	@return: the selected versions, or None if the user cancels
	@rtype: L{selections.Selections} | None
	"""
	if options.offline:
		config.network_use = model.network_offline

	iface_cache = config.iface_cache

	# Try to load it as a feed. If it is a feed, it'll get cached. If not, it's a
	# selections document and we return immediately.
	maybe_selections = iface_cache.get_feed(iface_uri, selections_ok = True)
	if isinstance(maybe_selections, selections.Selections):
		if not select_only:
			blocker = maybe_selections.download_missing(config)
			if blocker:
				logging.info(_("Waiting for selected implementations to be downloaded..."))
				tasks.wait_for_blocker(blocker)
		return maybe_selections

	r = requirements.Requirements(iface_uri)
	r.parse_options(options)

	policy = Policy(config = config, requirements = r)

	# Note that need_download() triggers a solve
	if options.refresh or options.gui:
		# We could run immediately, but the user asked us not to
		can_run_immediately = False
	else:
		if select_only:
			# --select-only: we only care that we've made a selection, not that we've cached the implementations
			policy.need_download()
			can_run_immediately = policy.ready
		else:
			can_run_immediately = not policy.need_download()

		stale_feeds = [feed for feed in policy.solver.feeds_used if
				not os.path.isabs(feed) and			# Ignore local feeds (note: file might be missing too)
				not feed.startswith('distribution:') and	# Ignore (memory-only) PackageKit feeds
				iface_cache.is_stale(iface_cache.get_feed(feed), config.freshness)]

		if download_only and stale_feeds:
			can_run_immediately = False

	if can_run_immediately:
		if stale_feeds:
			if policy.network_use == model.network_offline:
				logging.debug(_("No doing background update because we are in off-line mode."))
			else:
				# There are feeds we should update, but we can run without them.
				# Do the update in the background while the program is running.
				from zeroinstall.injector import background
				background.spawn_background_update(policy, options.verbose > 0)
		return policy.solver.selections

	# If the user didn't say whether to use the GUI, choose for them.
	if options.gui is None and os.environ.get('DISPLAY', None):
		options.gui = True
		# If we need to download anything, we might as well
		# refresh all the feeds first.
		options.refresh = True
		logging.info(_("Switching to GUI mode... (use --console to disable)"))

	if options.gui:
		gui_args = policy.requirements.get_as_options()
		if download_only:
			# Just changes the button's label
			gui_args.append('--download-only')
		if options.refresh:
			gui_args.append('--refresh')
		if options.verbose:
			gui_args.insert(0, '--verbose')
			if options.verbose > 1:
				gui_args.insert(0, '--verbose')
		if options.with_store:
			for x in options.with_store:
				gui_args += ['--with-store', x]
		if select_only:
			gui_args.append('--select-only')

		from zeroinstall import helpers
		sels = helpers.get_selections_gui(iface_uri, gui_args, test_callback)

		if not sels:
			return None		# Aborted
	else:
		# Note: --download-only also makes us stop and download stale feeds first.
		downloaded = policy.solve_and_download_impls(refresh = options.refresh or download_only or False,
							     select_only = select_only)
		if downloaded:
			tasks.wait_for_blocker(downloaded)
		sels = selections.Selections(policy)

	return sels