Example #1
0
def handle(config, options, args):
	"""@type config: L{zeroinstall.injector.config.Config}
	@type args: [str]"""
	if len(args) < 1:
		raise UsageError()

	prog_args = args[1:]

	def test_callback(sels):
		from zeroinstall.injector import run
		return run.test_selections(sels, prog_args,
					     False,	# dry-run
					     options.main)

	app = config.app_mgr.lookup_app(args[0], missing_ok = True)
	if app is not None:
		sels = app.get_selections(may_update = True, use_gui = options.gui)
		r = app.get_requirements()
		do_select = r.parse_update_options(options)
		iface_uri = sels.interface
	else:
		iface_uri = model.canonical_iface_uri(args[0])
		do_select = True

	if do_select or options.gui:
		sels = select.get_selections(config, options, iface_uri,
					select_only = False, download_only = False,
					test_callback = test_callback)
		if not sels:
			sys.exit(1)	# Aborted by user

	from zeroinstall.injector import run
	run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)
Example #2
0
    def testAbsMain(self):
        with tempfile.NamedTemporaryFile(prefix='test-', delete=False) as tmp:
            tmp.write(("""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <group main='/bin/sh'>
   <implementation id='.' version='1'/>
  </group>
</interface>""" % foo_iface_uri).encode('utf-8'))

        driver = Driver(requirements=Requirements(tmp.name),
                        config=self.config)
        try:
            downloaded = driver.solve_and_download_impls()
            if downloaded:
                tasks.wait_for_blocker(downloaded)
            run.execute_selections(driver.solver.selections, [],
                                   stores=self.config.stores)
            assert False
        except SafeException as ex:
            assert 'Command path must be relative' in str(ex), ex
Example #3
0
def handle(config, options, args):
	"""@type config: L{zeroinstall.injector.config.Config}
	@type args: [str]"""
	if len(args) < 1:
		raise UsageError()

	prog_args = args[1:]

	def test_callback(sels):
		from zeroinstall.injector import run
		return run.test_selections(sels, prog_args,
					     False,	# dry-run
					     options.main)

	app = config.app_mgr.lookup_app(args[0], missing_ok = True)
	if app is not None:
		sels = app.get_selections(may_update = True, use_gui = options.gui)
		r = app.get_requirements()
		do_select = r.parse_update_options(options) or options.refresh
		iface_uri = sels.interface
	else:
		iface_uri = model.canonical_iface_uri(args[0])
		r = None
		do_select = True

	if do_select or options.gui:
		sels = select.get_selections(config, options, iface_uri,
					select_only = False, download_only = False,
					test_callback = test_callback,
					requirements = r)
		if not sels:
			sys.exit(1)	# Aborted by user

	from zeroinstall.injector import run
	run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)
Example #4
0
    def testAbsMain(self):
        p = Driver(requirements=Requirements(command_feed), config=self.config)
        self.config.handler.wait_for_blocker(p.solve_with_downloads())

        old_stdout = sys.stdout
        try:
            sys.stdout = StringIO()
            run.execute_selections(p.solver.selections, [],
                                   main='/runnable/runner',
                                   dry_run=True,
                                   stores=self.config.stores)
        finally:
            sys.stdout = old_stdout

        try:
            old_stdout = sys.stdout
            try:
                sys.stdout = StringIO()
                run.execute_selections(p.solver.selections, [],
                                       main='/runnable/not-there',
                                       dry_run=True,
                                       stores=self.config.stores)
            finally:
                sys.stdout = old_stdout
        except SafeException as ex:
            assert 'not-there' in unicode(ex)
Example #5
0
def download_and_execute(driver, prog_args, main=None, dry_run=False):
    driver_download(driver)
    run.execute_selections(driver.solver.selections,
                           prog_args,
                           stores=driver.config.stores,
                           main=main,
                           dry_run=dry_run)
def download_and_execute(policy, prog_args, main=None):
    downloaded = policy.solve_and_download_impls()
    if downloaded:
        policy.config.handler.wait_for_blocker(downloaded)
    run.execute_selections(policy.solver.selections,
                           prog_args,
                           stores=policy.config.stores,
                           main=main)
Example #7
0
def download_and_execute(driver, prog_args, main=None, dry_run=True):
    downloaded = driver.solve_and_download_impls()
    if downloaded:
        tasks.wait_for_blocker(downloaded)
    run.execute_selections(driver.solver.selections,
                           prog_args,
                           stores=driver.config.stores,
                           main=main,
                           dry_run=dry_run)
Example #8
0
	def testCommandBindings(self):
		p = policy.Policy(command_feed, config = self.config)
		self.config.handler.wait_for_blocker(p.solve_with_downloads())
		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(p.solver.selections, [], main = 'runner', dry_run = True, stores = self.config.stores)
		finally:
			sys.stdout = old_stdout
		assert 'local' in os.environ['LOCAL'], os.environ['LOCAL']
Example #9
0
	def testArgs(self):
		p = policy.Policy(runnable, config = self.config)
		self.config.handler.wait_for_blocker(p.solve_with_downloads())
		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(p.solver.selections, [], dry_run = True, stores = self.config.stores)
			out = sys.stdout.getvalue()
		finally:
			sys.stdout = old_stdout
		assert 'runner-arg' in out, out
Example #10
0
	def testArgs(self):
		p = Driver(requirements = Requirements(runnable), config = self.config)
		self.config.handler.wait_for_blocker(p.solve_with_downloads())
		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(p.solver.selections, [], dry_run = True, stores = self.config.stores)
			out = sys.stdout.getvalue()
		finally:
			sys.stdout = old_stdout
		assert 'runner-arg' in out, out
Example #11
0
	def testArgList(self):
		d = Driver(requirements = Requirements(arglist), config = self.config)
		self.config.handler.wait_for_blocker(d.solve_with_downloads())
		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(d.solver.selections, [], dry_run = True, stores = self.config.stores)
			out = sys.stdout.getvalue()
		finally:
			sys.stdout = old_stdout
		assert 'arg-for-runner -X ra1 -X ra2' in out, out
		assert 'command-arg ca1 ca2' in out, out
Example #12
0
	def testWrapper(self):
		p = policy.Policy(runnable, config = self.config)
		self.config.handler.wait_for_blocker(p.solve_with_downloads())
		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(p.solver.selections, [], wrapper = 'echo', dry_run = True, stores = self.config.stores)
			out = sys.stdout.getvalue()
		finally:
			sys.stdout = old_stdout
		assert '/bin/sh -c echo "$@"' in out, out
		assert 'runner-arg' in out, out
		assert 'script' in out, out
Example #13
0
	def testCommandBindings(self):
		if 'SELF_COMMAND' in os.environ:
			del os.environ['SELF_COMMAND']

		p = Driver(requirements = Requirements(command_feed), config = self.config)
		tasks.wait_for_blocker(p.solve_with_downloads())
		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(p.solver.selections, [], main = 'runnable/go.sh', dry_run = True, stores = self.config.stores)
		finally:
			sys.stdout = old_stdout
		assert 'local' in os.environ['LOCAL'], os.environ['LOCAL']
		assert 'SELF_COMMAND' in os.environ
Example #14
0
 def testArgList(self):
     d = Driver(requirements=Requirements(arglist), config=self.config)
     self.config.handler.wait_for_blocker(d.solve_with_downloads())
     old_stdout = sys.stdout
     try:
         sys.stdout = StringIO()
         run.execute_selections(d.solver.selections, [],
                                dry_run=True,
                                stores=self.config.stores)
         out = sys.stdout.getvalue()
     finally:
         sys.stdout = old_stdout
     assert 'arg-for-runner -X ra1 -X ra2' in out, out
     assert 'command-arg ca1 ca2' in out, out
Example #15
0
 def testWrapper(self):
     p = Driver(requirements=Requirements(runnable), config=self.config)
     self.config.handler.wait_for_blocker(p.solve_with_downloads())
     old_stdout = sys.stdout
     try:
         sys.stdout = StringIO()
         run.execute_selections(p.solver.selections, [],
                                wrapper='echo',
                                dry_run=True,
                                stores=self.config.stores)
         out = sys.stdout.getvalue()
     finally:
         sys.stdout = old_stdout
     assert '/bin/sh -c echo "$@"' in out, out
     assert 'runner-arg' in out, out
     assert 'script' in out, out
Example #16
0
    def testCommandBindings(self):
        if 'SELF_COMMAND' in os.environ:
            del os.environ['SELF_COMMAND']

        p = Driver(requirements=Requirements(command_feed), config=self.config)
        tasks.wait_for_blocker(p.solve_with_downloads())
        old_stdout = sys.stdout
        try:
            sys.stdout = StringIO()
            run.execute_selections(p.solver.selections, [],
                                   main='runnable/go.sh',
                                   dry_run=True,
                                   stores=self.config.stores)
        finally:
            sys.stdout = old_stdout
        assert 'local' in os.environ['LOCAL'], os.environ['LOCAL']
        assert 'SELF_COMMAND' in os.environ
Example #17
0
def handle(config, options, args):
    if len(args) < 1:
        raise UsageError()

    prog_args = args[1:]

    def test_callback(sels):
        from zeroinstall.injector import run
        return run.test_selections(
            sels,
            prog_args,
            False,  # dry-run
            options.main)

    app = config.app_mgr.lookup_app(args[0], missing_ok=True)
    if app is not None:
        sels = app.get_selections(may_update=True)
        r = app.get_requirements()
        do_select = r.parse_update_options(options)
        iface_uri = sels.interface
    else:
        iface_uri = model.canonical_iface_uri(args[0])
        do_select = True

    if do_select or options.gui:
        sels = select.get_selections(config,
                                     options,
                                     iface_uri,
                                     select_only=False,
                                     download_only=False,
                                     test_callback=test_callback)
        if not sels:
            sys.exit(1)  # Aborted by user
    else:
        dl = app.download_selections(sels)
        if dl:
            tasks.wait_for_blocker(dl)
            tasks.check(dl)

    from zeroinstall.injector import run
    run.execute_selections(sels,
                           prog_args,
                           dry_run=options.dry_run,
                           main=options.main,
                           wrapper=options.wrapper,
                           stores=config.stores)
Example #18
0
	def testBadMain(self):
		r = Requirements(command_feed)
		r.command = None
		d = Driver(requirements = r, config = self.config)
		self.config.handler.wait_for_blocker(d.solve_with_downloads())

		try:
			run.execute_selections(d.solver.selections, [], dry_run = True, stores = self.config.stores)
			assert 0
		except SafeException as ex:
			self.assertEqual("Can't run: no command specified!", unicode(ex))

		try:
			run.execute_selections(d.solver.selections, [], main = 'relpath', dry_run = True, stores = self.config.stores)
			assert 0
		except SafeException as ex:
			self.assertEqual("Can't use a relative replacement main when there is no original one!", unicode(ex))
Example #19
0
	def testAbsMain(self):
		p = Driver(requirements = Requirements(command_feed), config = self.config)
		self.config.handler.wait_for_blocker(p.solve_with_downloads())

		old_stdout = sys.stdout
		try:
			sys.stdout = StringIO()
			run.execute_selections(p.solver.selections, [], main = '/runnable/runner', dry_run = True, stores = self.config.stores)
		finally:
			sys.stdout = old_stdout

		try:
			old_stdout = sys.stdout
			try:
				sys.stdout = StringIO()
				run.execute_selections(p.solver.selections, [], main = '/runnable/not-there', dry_run = True, stores = self.config.stores)
			finally:
				sys.stdout = old_stdout
		except SafeException as ex:
			assert 'not-there' in unicode(ex)
Example #20
0
def handle(config, options, args):
	if len(args) < 1:
		raise UsageError()
	iface_uri = model.canonical_iface_uri(args[0])
	prog_args = args[1:]

	def test_callback(sels):
		from zeroinstall.injector import run
		return run.test_selections(sels, prog_args,
					     False,	# dry-run
					     options.main)

	sels = select.get_selections(config, options, iface_uri,
				select_only = False, download_only = False,
				test_callback = test_callback)
	if not sels:
		sys.exit(1)	# Aborted by user

	from zeroinstall.injector import run
	run.execute_selections(sels, prog_args, dry_run = options.dry_run, main = options.main, wrapper = options.wrapper, stores = config.stores)
Example #21
0
	def testAbsMain(self):
		with tempfile.NamedTemporaryFile(prefix = 'test-', delete = False) as tmp:
			tmp.write((
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <group main='/bin/sh'>
   <implementation id='.' version='1'/>
  </group>
</interface>""" % foo_iface_uri).encode('utf-8'))

		driver = Driver(requirements = Requirements(tmp.name), config = self.config)
		try:
			downloaded = driver.solve_and_download_impls()
			if downloaded:
				tasks.wait_for_blocker(downloaded)
			run.execute_selections(driver.solver.selections, [], stores = self.config.stores)
			assert False
		except SafeException as ex:
			assert 'Command path must be relative' in str(ex), ex
Example #22
0
    def testAbsMain(self):
        tmp = tempfile.NamedTemporaryFile(prefix='test-')
        tmp.write("""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <group main='/bin/sh'>
   <implementation id='.' version='1'/>
  </group>
</interface>""" % foo_iface_uri)
        tmp.flush()
        policy = Policy(tmp.name, config=self.config)
        try:
            downloaded = policy.solve_and_download_impls()
            if downloaded:
                policy.handler.wait_for_blocker(downloaded)
            run.execute_selections(policy.solver.selections, [],
                                   stores=policy.config.stores)
            assert False
        except SafeException as ex:
            assert 'Command path must be relative' in str(ex), ex
Example #23
0
	def testAbsMain(self):
		tmp = tempfile.NamedTemporaryFile(prefix = 'test-')
		tmp.write(
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <group main='/bin/sh'>
   <implementation id='.' version='1'/>
  </group>
</interface>""" % foo_iface_uri)
		tmp.flush()
		policy = Policy(tmp.name, config = self.config)
		try:
			downloaded = policy.solve_and_download_impls()
			if downloaded:
				policy.handler.wait_for_blocker(downloaded)
			run.execute_selections(policy.solver.selections, [], stores = policy.config.stores)
			assert False
		except SafeException, ex:
			assert 'Command path must be relative' in str(ex), ex
Example #24
0
    def testBadMain(self):
        r = Requirements(command_feed)
        r.command = None
        d = Driver(requirements=r, config=self.config)
        self.config.handler.wait_for_blocker(d.solve_with_downloads())

        try:
            run.execute_selections(d.solver.selections, [],
                                   dry_run=True,
                                   stores=self.config.stores)
            assert 0
        except SafeException as ex:
            self.assertEqual("Can't run: no command specified!", unicode(ex))

        try:
            run.execute_selections(d.solver.selections, [],
                                   main='relpath',
                                   dry_run=True,
                                   stores=self.config.stores)
            assert 0
        except SafeException as ex:
            self.assertEqual(
                "Can't use a relative replacement main when there is no original one!",
                unicode(ex))
Example #25
0
def _normal_mode(options, args):
	from zeroinstall.injector import handler

	if len(args) < 1:
		if options.gui:
			from zeroinstall import helpers
			return helpers.get_selections_gui(None, [])
		else:
			raise UsageError()

	iface_uri = model.canonical_iface_uri(args[0])
	root_iface = iface_cache.get_interface(iface_uri)

	if os.isatty(1):
		h = handler.ConsoleHandler()
	else:
		h = handler.Handler()
	h.dry_run = bool(options.dry_run)

	policy = autopolicy.AutoPolicy(iface_uri,
				handler = h,
				download_only = bool(options.download_only),
				src = options.source)

	if options.before or options.not_before:
		policy.solver.extra_restrictions[root_iface] = [model.VersionRangeRestriction(model.parse_version(options.before),
									      		      model.parse_version(options.not_before))]

	if options.os or options.cpu:
		from zeroinstall.injector import arch
		policy.target_arch = arch.get_architecture(options.os, options.cpu)

	if options.offline:
		policy.network_use = model.network_offline

	if options.get_selections:
		if len(args) > 1:
			raise SafeException(_("Can't use arguments with --get-selections"))
		if options.main:
			raise SafeException(_("Can't use --main with --get-selections"))

	# 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:
		can_run_immediately = (not policy.need_download()) and policy.ready

		stale_feeds = [feed for feed in policy.solver.feeds_used if policy.is_stale(iface_cache.get_feed(feed))]

		if options.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.
				import background
				background.spawn_background_update(policy, options.verbose > 0)
		if options.get_selections:
			_get_selections(policy)
		else:
			if not options.download_only:
				from zeroinstall.injector import run
				run.execute(policy, args[1:], dry_run = options.dry_run, main = options.main, wrapper = options.wrapper)
			else:
				logging.info(_("Downloads done (download-only mode)"))
			assert options.dry_run or options.download_only
		return

	# 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 interfaces first. Also, this triggers
		# the 'checking for updates' box, which is non-interactive
		# when there are no changes to the selection.
		options.refresh = True
		logging.info(_("Switching to GUI mode... (use --console to disable)"))

	prog_args = args[1:]

	try:
		from zeroinstall.injector import run
		if options.gui:
			gui_args = []
			if options.download_only:
				# Just changes the button's label
				gui_args.append('--download-only')
			if options.refresh:
				gui_args.append('--refresh')
			if options.systray:
				gui_args.append('--systray')
			if options.not_before:
				gui_args.insert(0, options.not_before)
				gui_args.insert(0, '--not-before')
			if options.before:
				gui_args.insert(0, options.before)
				gui_args.insert(0, '--before')
			if options.source:
				gui_args.insert(0, '--source')
			if options.message:
				gui_args.insert(0, options.message)
				gui_args.insert(0, '--message')
			if options.verbose:
				gui_args.insert(0, '--verbose')
				if options.verbose > 1:
					gui_args.insert(0, '--verbose')
			if options.cpu:
				gui_args.insert(0, options.cpu)
				gui_args.insert(0, '--cpu')
			if options.os:
				gui_args.insert(0, options.os)
				gui_args.insert(0, '--os')
			if options.with_store:
				for x in options.with_store:
					gui_args += ['--with-store', x]
			sels = _fork_gui(iface_uri, gui_args, prog_args, options)
			if not sels:
				sys.exit(1)		# Aborted
		else:
			#program_log('download_and_execute ' + iface_uri)
			downloaded = policy.solve_and_download_impls(refresh = bool(options.refresh))
			if downloaded:
				policy.handler.wait_for_blocker(downloaded)
			sels = selections.Selections(policy)

		if options.get_selections:
			doc = sels.toDOM()
			doc.writexml(sys.stdout)
			sys.stdout.write('\n')
		elif not options.download_only:
			run.execute_selections(sels, prog_args, options.dry_run, options.main, options.wrapper)

	except NeedDownload, ex:
		# This only happens for dry runs
		print ex
Example #26
0
def download_and_execute(driver, prog_args, main = None):
	driver_download(driver)
	run.execute_selections(driver.solver.selections, prog_args, stores = driver.config.stores, main = main)
Example #27
0
def download_and_execute(driver, prog_args, main = None, dry_run = True):
	downloaded = driver.solve_and_download_impls()
	if downloaded:
		tasks.wait_for_blocker(downloaded)
	run.execute_selections(driver.solver.selections, prog_args, stores = driver.config.stores, main = main, dry_run = dry_run)
def download_and_execute(policy, prog_args, main = None, dry_run = True):
	downloaded = policy.solve_and_download_impls()
	if downloaded:
		policy.config.handler.wait_for_blocker(downloaded)
	run.execute_selections(policy.solver.selections, prog_args, stores = policy.config.stores, main = main, dry_run = dry_run)
Example #29
0
def main(command_args):
	"""Act as if 0launch was run with the given arguments.
	@arg command_args: array of arguments (e.g. C{sys.argv[1:]})
	@type command_args: [str]
	"""
	# Ensure stdin, stdout and stderr FDs exist, to avoid confusion
	for std in (0, 1, 2):
		try:
			os.fstat(std)
		except OSError:
			fd = os.open('/dev/null', os.O_RDONLY)
			if fd != std:
				os.dup2(fd, std)
				os.close(fd)

	parser = OptionParser(usage=_("usage: %prog [options] interface [args]\n"
				    "       %prog --list [search-term]\n"
				    "       %prog --import [signed-interface-files]\n"
				    "       %prog --feed [interface]"))
	parser.add_option("", "--before", help=_("choose a version before this"), metavar='VERSION')
	parser.add_option("-c", "--console", help=_("never use GUI"), action='store_false', dest='gui')
	parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU')
	parser.add_option("-d", "--download-only", help=_("fetch but don't run"), action='store_true')
	parser.add_option("-D", "--dry-run", help=_("just print actions"), action='store_true')
	parser.add_option("-f", "--feed", help=_("add or remove a feed"), action='store_true')
	parser.add_option("", "--get-selections", help=_("write selected versions as XML"), action='store_true')
	parser.add_option("-g", "--gui", help=_("show graphical policy editor"), action='store_true')
	parser.add_option("-i", "--import", help=_("import from files, not from the network"), action='store_true')
	parser.add_option("-l", "--list", help=_("list all known interfaces"), action='store_true')
	parser.add_option("-m", "--main", help=_("name of the file to execute"))
	parser.add_option("", "--message", help=_("message to display when interacting with user"))
	parser.add_option("", "--not-before", help=_("minimum version to choose"), metavar='VERSION')
	parser.add_option("", "--os", help=_("target operation system type"), metavar='OS')
	parser.add_option("-o", "--offline", help=_("try to avoid using the network"), action='store_true')
	parser.add_option("-r", "--refresh", help=_("refresh all used interfaces"), action='store_true')
	parser.add_option("", "--set-selections", help=_("run versions specified in XML file"), metavar='FILE')
	parser.add_option("-s", "--source", help=_("select source code"), action='store_true')
	parser.add_option("", "--systray", help=_("download in the background"), action='store_true')
	parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count')
	parser.add_option("-V", "--version", help=_("display version information"), action='store_true')
	parser.add_option("", "--with-store", help=_("add an implementation cache"), action='append', metavar='DIR')
	parser.add_option("-w", "--wrapper", help=_("execute program using a debugger, etc"), metavar='COMMAND')
	parser.disable_interspersed_args()

	(options, args) = parser.parse_args(command_args)

	if options.verbose:
		logger = logging.getLogger()
		if options.verbose == 1:
			logger.setLevel(logging.INFO)
		else:
			logger.setLevel(logging.DEBUG)
		import zeroinstall
		logging.info(_("Running 0launch %(version)s %(args)s; Python %(python_version)s"), {'version': zeroinstall.version, 'args': repr(args), 'python_version': sys.version})

	if options.with_store:
		from zeroinstall import zerostore
		for x in options.with_store:
			iface_cache.stores.stores.append(zerostore.Store(os.path.abspath(x)))
		logging.info(_("Stores search path is now %s"), iface_cache.stores.stores)

	try:
		if options.list:
			_list_interfaces(args)
		elif options.version:
			import zeroinstall
			print "0launch (zero-install) " + zeroinstall.version
			print "Copyright (C) 2009 Thomas Leonard"
			print _("This program comes with ABSOLUTELY NO WARRANTY,"
					"\nto the extent permitted by law."
					"\nYou may redistribute copies of this program"
					"\nunder the terms of the GNU Lesser General Public License."
					"\nFor more information about these matters, see the file named COPYING.")
		elif options.set_selections:
			from zeroinstall.injector import qdom, run
			sels = selections.Selections(qdom.parse(file(options.set_selections)))
			_download_missing_selections(options, sels)
			if not options.download_only:
				run.execute_selections(sels, args, options.dry_run, options.main, options.wrapper)
		elif getattr(options, 'import'):
			_import_feed(args)
		elif options.feed:
			_manage_feeds(options, args)
		else:
			_normal_mode(options, args)
	except UsageError:
		parser.print_help()
		sys.exit(1)
	except SafeException, ex:
		if options.verbose: raise
		print >>sys.stderr, ex
		sys.exit(1)
Example #30
0
def run_tests(config, tested_iface, sels, spec):
    def _get_implementation_path(impl):
        return impl.local_path or config.iface_cache.stores.lookup_any(
            impl.digests)

    main_command = sels.commands[0] if sels.commands else None

    root_impl = sels.selections[tested_iface.uri]
    assert root_impl

    if spec.test_wrapper:
        tests_dir = None
        # $1 is the main executable, or the root of the package if there isn't one
        # We have to add the slash because otherwise 0launch interprets the path
        # relative to itself...
        if main_command and main_command.path:
            test_main = "/" + main_command.path
        else:
            test_main = "/"
    else:
        if main_command is None:
            print >> sys.stderr, "No <command> requested and no test command either!"
            return "skipped"

        test_main = None

        if main_command.path is None:
            tests_dir = _get_implementation_path(root_impl)
        else:
            main_abs = os.path.join(_get_implementation_path(root_impl),
                                    main_command.path)
            if not os.path.exists(main_abs):
                print >> sys.stderr, "Test executable does not exist:", main_abs
                return "skipped"

            tests_dir = os.path.dirname(main_abs)

    child = os.fork()
    if child:
        # We are the parent
        pid, status = os.waitpid(child, 0)
        assert pid == child
        print "Status:", hex(status)
        if status == 0:
            return "passed"
        else:
            return "failed"
    else:
        # We are the child
        try:
            try:
                if spec.test_wrapper is None:
                    os.chdir(tests_dir)
                run.execute_selections(sels,
                                       spec.test_args,
                                       main=test_main,
                                       wrapper=spec.test_wrapper)
                os._exit(0)
            except model.SafeException, ex:
                try:
                    print >> sys.stderr, unicode(ex)
                except:
                    print >> sys.stderr, repr(ex)
            except:
                import traceback
                traceback.print_exc()
        finally: