Beispiel #1
0
	def testMan(self):
		out, err = self.run_0install(['man', '--help'])
		assert out.lower().startswith("usage:")

		# Wrong number of args: pass-through
		self.check_man(['git', 'config'], ('man', 'git', 'config'))
		self.check_man([], ('man',))

		alias_path = os.path.join(mydir, '..', '0alias')
		local_feed = os.path.join(mydir, 'Local.xml')
		launcher_script = os.path.join(apps.find_bin_dir(), 'my-test-alias')
		with open(launcher_script, 'w') as stream:
			alias.write_script(stream, model.canonical_iface_uri(local_feed), None)
		self.check_man(['my-test-alias'], 'tests/test-echo.1')

		self.check_man(['__i_dont_exist'], '__i_dont_exist')
		self.check_man(['ls'], 'ls')

		# No man-page
		binary_feed = os.path.join(mydir, 'Command.xml')
		launcher_script = os.path.join(apps.find_bin_dir(), 'my-binary-alias')
		with open(launcher_script, 'w') as stream:
			alias.write_script(stream, model.canonical_iface_uri(binary_feed), None)

		out, err = self.run_0install(['man', 'my-binary-alias'])
		assert not err, err
		assert "No matching manpage was found for 'my-binary-alias'" in out, out

		with open(os.path.join(self.config_home, 'bad-unicode'), 'wb') as stream:
			stream.write(bytes([198, 65]))
		self.check_man(['bad-unicode'], 'bad-unicode')
Beispiel #2
0
    def testMan(self):
        out, err = self.run_0install(['man', '--help'])
        assert out.lower().startswith("usage:")

        # Wrong number of args: pass-through
        self.check_man(['git', 'config'], ('man', 'git', 'config'))
        self.check_man([], ('man', ))

        local_feed = os.path.join(mydir, 'Local.xml')
        launcher_script = os.path.join(apps.find_bin_dir(), 'my-test-alias')
        with open(launcher_script, 'w') as stream:
            alias.write_script(stream, model.canonical_iface_uri(local_feed),
                               None)
        self.check_man(['my-test-alias'], 'tests/test-echo.1')

        self.check_man(['__i_dont_exist'], '__i_dont_exist')
        self.check_man(['ls'], 'ls')

        # No man-page
        binary_feed = os.path.join(mydir, 'Command.xml')
        launcher_script = os.path.join(apps.find_bin_dir(), 'my-binary-alias')
        with open(launcher_script, 'w') as stream:
            alias.write_script(stream, model.canonical_iface_uri(binary_feed),
                               None)

        out, err = self.run_0install(['man', 'my-binary-alias'])
        assert not err, err
        assert "No matching manpage was found for 'my-binary-alias'" in out, out

        with open(os.path.join(self.config_home, 'bad-unicode'),
                  'wb') as stream:
            stream.write(bytes([198, 65]))
        self.check_man(['bad-unicode'], 'bad-unicode')
Beispiel #3
0
    def testReplacedConflicts(self):
        self.import_feed('http://localhost:8000/Hello', 'Hello')
        s = solver.DefaultSolver(self.config)
        replaced_path = model.canonical_iface_uri(
            os.path.join(mydir, 'Replaced.xml'))
        replaced_conflicts_path = model.canonical_iface_uri(
            os.path.join(mydir, 'ReplacedConflicts.xml'))
        r = Requirements(replaced_conflicts_path)
        s.solve_for(r)
        assert s.ready, s.get_failure_reason()
        assert s.selections
        self.assertEqual("b",
                         s.selections.selections[replaced_conflicts_path].id)
        self.assertEqual(
            "2", s.selections.selections[replaced_conflicts_path].version)
        self.assertEqual(
            "sha1=3ce644dc725f1d21cfcf02562c76f375944b266a",
            s.selections.selections["http://localhost:8000/Hello"].id)
        self.assertEqual(2, len(s.selections.selections))

        s.extra_restrictions[self.config.iface_cache.get_interface(
            r.interface_uri)] = [
                model.VersionRangeRestriction(model.parse_version('2'), None)
            ]

        s.solve_for(r)
        assert s.ready, s.get_failure_reason()
        assert s.selections
        self.assertEqual(
            "1", s.selections.selections[replaced_conflicts_path].version)
        self.assertEqual("0", s.selections.selections[replaced_path].version)
        self.assertEqual(2, len(s.selections.selections))
	def testCanonical(self):
		try:
			model.canonical_iface_uri('http://foo')
			assert False
		except model.SafeException as ex:
			assert 'Missing /' in str(ex)

		self.assertEquals('http://foo/',
				model.canonical_iface_uri('http://foo/'))
		try:
			model.canonical_iface_uri('bad-name')
			assert False
		except model.SafeException as ex:
			assert 'Bad interface name' in str(ex)
Beispiel #5
0
def handle(config, options, args):
	if len(args) != 1:
		raise UsageError()

	app = config.app_mgr.lookup_app(args[0], missing_ok = True)
	if app is not None:
		sels = app.get_selections()

		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 = get_selections(config, options, iface_uri,
					select_only = True, download_only = False, test_callback = None)
		if not sels:
			sys.exit(1)	# Aborted by user

	if options.xml:
		show_xml(sels)
	else:
		show_human(sels, config.stores)
		if app is not None and do_select:
			print(_("(use '0install update' to save the new parameters)"))
Beispiel #6
0
def do_autocompile(args):
	"""autocompile [--gui] URI"""

	parser = OptionParser(usage="usage: %prog autocompile [options]")

	parser.add_option('', "--gui", help="graphical interface", action='store_true')
	(options, args2) = parser.parse_args(args)
	if len(args2) != 1:
		raise __main__.UsageError()

	if options.gui:
		h = GUIHandler()
	elif os.isatty(1):
		h = handler.ConsoleHandler()
	else:
		h = handler.Handler()
	config = load_config(handler = h)
	config._iface_cache = AutocompileCache()

	iface_uri = model.canonical_iface_uri(args2[0])
	if options.gui:
		compiler = GTKAutoCompiler(config, iface_uri, options)
	else:
		compiler = AutoCompiler(config, iface_uri, options)

	compiler.build()
Beispiel #7
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)
Beispiel #8
0
    def testSelect(self):
        out, err = self.run_0install(["select"])
        assert out.lower().startswith("usage:")
        assert "--xml" in out

        out, err = self.run_0install(["select", "Local.xml"])
        assert not err, err
        assert "Version: 0.1" in out

        out, err = self.run_0install(["select", "Local.xml", "--command="])
        assert not err, err
        assert "Version: 0.1" in out

        local_uri = model.canonical_iface_uri("Local.xml")
        out, err = self.run_0install(["select", "Local.xml"])
        assert not err, err
        assert "Version: 0.1" in out

        out, err = self.run_0install(["select", "Local.xml", "--xml"])
        sels = selections.Selections(qdom.parse(StringIO(str(out))))
        assert sels.selections[local_uri].version == "0.1"

        out, err = self.run_0install(["select", "selections.xml"])
        assert not err, err
        assert "Version: 1\n" in out
        assert "(not cached)" in out

        out, err = self.run_0install(["select", "runnable/RunExec.xml"])
        assert not err, err
        assert "Runner" in out, out
Beispiel #9
0
    def testDownload(self):
        out, err = self.run_0install(["download"])
        assert out.lower().startswith("usage:")
        assert "--show" in out

        out, err = self.run_0install(["download", "Local.xml", "--show"])
        assert not err, err
        assert "Version: 0.1" in out

        local_uri = model.canonical_iface_uri("Local.xml")
        out, err = self.run_0install(["download", "Local.xml", "--xml"])
        assert not err, err
        sels = selections.Selections(qdom.parse(StringIO(str(out))))
        assert sels.selections[local_uri].version == "0.1"

        out, err = self.run_0install(["download", "Local.xml", "--show", "--with-store=/foo"])
        assert not err, err
        assert self.config.stores.stores[-1].dir == "/foo"

        out, err = self.run_0install(["download", "--offline", "selections.xml"])
        assert "Would download" in err
        self.config.network_use = model.network_full

        self.config.stores = TestStores()
        digest = "sha1=3ce644dc725f1d21cfcf02562c76f375944b266a"
        self.config.fetcher.allow_download(digest)
        out, err = self.run_0install(["download", "Hello.xml", "--show"])
        assert not err, err
        assert self.config.stores.lookup_any([digest]).startswith("/fake")
        assert "Version: 1\n" in out

        out, err = self.run_0install(["download", "--offline", "selections.xml", "--show"])
        assert "/fake_store" in out
        self.config.network_use = model.network_full
Beispiel #10
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)
Beispiel #11
0
def do_autocompile(args):
    """autocompile [--gui] URI"""

    parser = OptionParser(usage="usage: %prog autocompile [options]")

    parser.add_option('',
                      "--gui",
                      help="graphical interface",
                      action='store_true')
    (options, args2) = parser.parse_args(args)
    if len(args2) != 1:
        raise __main__.UsageError()

    if options.gui:
        h = GUIHandler()
    elif os.isatty(1):
        h = handler.ConsoleHandler()
    else:
        h = handler.Handler()
    config = load_config(handler=h)
    config._iface_cache = AutocompileCache()

    iface_uri = model.canonical_iface_uri(args2[0])
    if options.gui:
        compiler = GTKAutoCompiler(config, iface_uri, options)
    else:
        compiler = AutoCompiler(config, iface_uri, options)

    compiler.build()
Beispiel #12
0
def handle(config, options, args):
	"""@type config: L{zeroinstall.injector.config.Config}
	@type args: [str]"""
	if len(args) != 1:
		raise UsageError()

	app = config.app_mgr.lookup_app(args[0], missing_ok = True)
	if app is not None:
		sels = app.get_selections()

		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 = True, test_callback = None, requirements = r)
		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)

	if options.xml:
		select.show_xml(sels)
	if options.show:
		select.show_human(sels, config.stores)
		if app is not None and do_select:
			print(_("(use '0install update' to save the new parameters)"))
Beispiel #13
0
	def testDownload(self):
		out, err = self.run_0install(['download'])
		assert out.lower().startswith("usage:")
		assert '--show' in out

		out, err = self.run_0install(['download', 'Local.xml', '--show'])
		assert not err, err
		assert 'Version: 0.1' in out

		local_uri = model.canonical_iface_uri('Local.xml')
		out, err = self.run_0install(['download', 'Local.xml', '--xml'])
		assert not err, err
		sels = selections.Selections(qdom.parse(BytesIO(str(out).encode('utf-8'))))
		assert sels.selections[local_uri].version == '0.1'

		out, err = self.run_0install(['download', 'Local.xml', '--show', '--with-store=/foo'])
		assert not err, err
		assert self.config.stores.stores[-1].dir == '/foo'

		out, err = self.run_0install(['download', '--offline', 'selections.xml'])
		assert 'Would download' in err
		self.config.network_use = model.network_full

		self.config.stores = TestStores()
		digest = 'sha1=3ce644dc725f1d21cfcf02562c76f375944b266a'
		self.config.fetcher.allow_download(digest)
		out, err = self.run_0install(['download', 'Hello.xml', '--show'])
		assert not err, err
		assert self.config.stores.lookup_any([digest]).startswith('/fake')
		assert 'Version: 1\n' in out

		out, err = self.run_0install(['download', '--offline', 'selections.xml', '--show'])
		assert '/fake_store' in out
		self.config.network_use = model.network_full
Beispiel #14
0
    def _pull(self, feeds, link_new):
        if not self.active:
            self._root_link = None

        if not isinstance(feeds, list):
            feeds = [feeds]

        msg = _('Pull %s.') % ', '.join([_name(i) for i in feeds])
        self.emit('verbose', msg)

        self._stat_all = len(feeds)
        self._stat_processed = 0

        for uri in feeds:
            try:
                uri = model.canonical_iface_uri(uri)
                root, links = link_new(uri)
            except Exception, e:
                logger.exception('Fail to pull %s into queue.', uri)
                self.emit('verbose', str(e))
                self._cancel()
                return

            if self._root_link is None:
                self._root_link = root

            if links:
                self._queue.extend(links)
                self._stat_processed += 1
Beispiel #15
0
def handle(config, options, args):
    if len(args) == 2:
        iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0]))
        feed_url = model.canonical_iface_uri(args[1])

        feed_import = add_feed.find_feed_import(iface, feed_url)
        if not feed_import:
            raise SafeException(
                _("Interface %(interface)s has no feed %(feed)s") % {"interface": iface.uri, "feed": feed_url}
            )
        iface.extra_feeds.remove(feed_import)
        writer.save_interface(iface)
    elif len(args) == 1:
        add_feed.handle(config, options, args, add_ok=False, remove_ok=True)
    else:
        raise UsageError()
Beispiel #16
0
	def testSelect(self):
		out, err = self.run_0install(['select'])
		assert out.lower().startswith("usage:")
		assert '--xml' in out

		out, err = self.run_0install(['select', 'Local.xml'])
		assert not err, err
		assert 'Version: 0.1' in out

		out, err = self.run_0install(['select', 'Local.xml', '--command='])
		assert not err, err
		assert 'Version: 0.1' in out

		local_uri = model.canonical_iface_uri('Local.xml')
		out, err = self.run_0install(['select', 'Local.xml'])
		assert not err, err
		assert 'Version: 0.1' in out

		out, err = self.run_0install(['select', 'Local.xml', '--xml'])
		sels = selections.Selections(qdom.parse(BytesIO(str(out).encode('utf-8'))))
		assert sels.selections[local_uri].version == '0.1'

		out, err = self.run_0install(['select', 'selections.xml'])
		assert not err, err
		assert 'Version: 1\n' in out
		assert '(not cached)' in out

		out, err = self.run_0install(['select', 'runnable/RunExec.xml'])
		assert not err, err
		assert 'Runner' in out, out
Beispiel #17
0
    def testSelect(self):
        out, err = self.run_0install(['select'])
        assert out.lower().startswith("usage:")
        assert '--xml' in out

        out, err = self.run_0install(['select', 'Local.xml'])
        assert not err, err
        assert 'Version: 0.1' in out

        out, err = self.run_0install(['select', 'Local.xml', '--command='])
        assert not err, err
        assert 'Version: 0.1' in out

        local_uri = model.canonical_iface_uri('Local.xml')
        out, err = self.run_0install(['select', 'Local.xml'])
        assert not err, err
        assert 'Version: 0.1' in out

        out, err = self.run_0install(['select', 'Local.xml', '--xml'])
        sels = selections.Selections(
            qdom.parse(BytesIO(str(out).encode('utf-8'))))
        assert sels.selections[local_uri].version == '0.1'

        out, err = self.run_0install(['select', 'selections.xml'])
        assert not err, err
        assert 'Version: 1\n' in out
        assert '(not cached)' in out

        out, err = self.run_0install(['select', 'runnable/RunExec.xml'])
        assert not err, err
        assert 'Runner' in out, out
Beispiel #18
0
def handle(config, options, args):
    if len(args) != 1:
        raise UsageError()

    app = config.app_mgr.lookup_app(args[0], missing_ok=True)
    if app is not None:
        sels = app.get_selections()

        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 = get_selections(config,
                              options,
                              iface_uri,
                              select_only=True,
                              download_only=False,
                              test_callback=None)
        if not sels:
            sys.exit(1)  # Aborted by user

    if options.xml:
        show_xml(sels)
    else:
        show_human(sels, config.stores)
        if app is not None and do_select:
            print(_("(use '0install update' to save the new parameters)"))
Beispiel #19
0
	def testAlias(self):
		local_feed = model.canonical_iface_uri(os.path.join(mydir, 'Local.xml'))
		alias_path = os.path.join(mydir, '..', '0alias')
		child = subprocess.Popen([alias_path, 'local-app', local_feed], stdout = subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines = True)
		out, err = child.communicate()
		assert 'ERROR: "0alias" has been removed; use "0install add" instead' in err, err
		assert not out, out
Beispiel #20
0
def handle(config, options, args):
	if len(args) == 2:
		iface = config.iface_cache.get_interface(model.canonical_iface_uri(args[0]))
		try:
			feed_url = model.canonical_iface_uri(args[1])
		except SafeException:
			feed_url = args[1]		# File might not exist any longer

		feed_import = add_feed.find_feed_import(iface, feed_url)
		if not feed_import:
			raise SafeException(_('Interface %(interface)s has no feed %(feed)s') %
						{'interface': iface.uri, 'feed': feed_url})
		iface.extra_feeds.remove(feed_import)
		writer.save_interface(iface)
	elif len(args) == 1:
		add_feed.handle(config, options, args, add_ok = False, remove_ok = True)
	else:
		raise UsageError()
Beispiel #21
0
def _manage_feeds(options, args):
	from zeroinstall.injector import writer
	from zeroinstall.injector.handler import Handler
	from zeroinstall.injector.policy import Policy
	handler = Handler(dry_run = options.dry_run)
	if not args: raise UsageError()
	for x in args:
		print _("Feed '%s':") % x + '\n'
		x = model.canonical_iface_uri(x)
		policy = Policy(x, handler)
		if options.offline:
			policy.network_use = model.network_offline

		feed = iface_cache.get_feed(x)
		if policy.network_use != model.network_offline and policy.is_stale(feed):
			blocker = policy.fetcher.download_and_import_feed(x, iface_cache.iface_cache)
			print _("Downloading feed; please wait...")
			handler.wait_for_blocker(blocker)
			print _("Done")

		interfaces = policy.get_feed_targets(x)
		for i in range(len(interfaces)):
			feed = interfaces[i].get_feed(x)
			if feed:
				print _("%(index)d) Remove as feed for '%(uri)s'") % {'index': i + 1, 'uri': interfaces[i].uri}
			else:
				print _("%(index)d) Add as feed for '%(uri)s'") % {'index': i + 1, 'uri': interfaces[i].uri}
		print
		while True:
			try:
				i = raw_input(_('Enter a number, or CTRL-C to cancel [1]: ')).strip()
			except KeyboardInterrupt:
				print
				raise SafeException(_("Aborted at user request."))
			if i == '':
				i = 1
			else:
				try:
					i = int(i)
				except ValueError:
					i = 0
			if i > 0 and i <= len(interfaces):
				break
			print _("Invalid number. Try again. (1 to %d)") % len(interfaces)
		iface = interfaces[i - 1]
		feed = iface.get_feed(x)
		if feed:
			iface.extra_feeds.remove(feed)
		else:
			iface.extra_feeds.append(model.Feed(x, arch = None, user_override = True))
		writer.save_interface(iface)
		print '\n' + _("Feed list for interface '%s' is now:") % iface.get_name()
		if iface.feeds:
			for f in iface.feeds:
				print "- " + f.uri
		else:
			print _("(no feeds)")
Beispiel #22
0
	def testDownloadIconFails(self):
		path = model.canonical_iface_uri(os.path.join(mydir, 'Binary.xml'))
		iface = self.config.iface_cache.get_interface(path)
		blocker = self.config.fetcher.download_icon(iface)
		try:
			tasks.wait_for_blocker(blocker)
			assert False
		except download.DownloadError as ex:
			assert "Error downloading http://localhost/missing.png" in str(ex), ex
Beispiel #23
0
	def testAlias(self):
		local_feed = model.canonical_iface_uri(os.path.join(mydir, 'Local.xml'))
		alias_path = os.path.join(mydir, '..', '0alias')
		child = subprocess.Popen([alias_path, 'local-app', local_feed], stdout = subprocess.PIPE, stderr = subprocess.STDOUT, universal_newlines = True)
		out, err = child.communicate()
		assert '("0alias" is deprecated; using "0install add" instead)' in out, out
		assert not err, err

		app = self.config.app_mgr.lookup_app('local-app')
		assert app.get_requirements().interface_uri == local_feed
Beispiel #24
0
def handle(config, options, args):
	if len(args) != 1: raise UsageError()
	uri = model.canonical_iface_uri(args[0])
	iface = config.iface_cache.get_interface(uri)

	if iface.extra_feeds:
		for f in iface.extra_feeds:
			print f.uri
	else:
		print _("(no feeds)")
Beispiel #25
0
def handle(config, options, args):
	if len(args) != 1: raise UsageError()
	uri = model.canonical_iface_uri(args[0])
	iface = config.iface_cache.get_interface(uri)

	if iface.extra_feeds:
		for f in iface.extra_feeds:
			print(f.uri)
	else:
		print(_("(no feeds)"))
Beispiel #26
0
def handle(config, options, args):
	if len(args) != 1:
		raise UsageError()

	assert not options.offline

	iface_uri = model.canonical_iface_uri(args[0])

	old_gui = options.gui

	# Select once in offline console mode to get the old values
	options.offline = True
	options.gui = False
	options.refresh = False

	try:
		old_sels = select.get_selections(config, options, iface_uri,
					select_only = True, download_only = False, test_callback = None)
	except SafeException:
		old_selections = {}
	else:
		if old_sels is None:
			old_selections = {}
		else:
			old_selections = old_sels.selections

	# Download in online mode to get the new values
	config.network_use = model.network_full
	options.offline = False
	options.gui = old_gui
	options.refresh = True

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

	changes = False

	for iface, old_sel in old_selections.iteritems():
		new_sel = sels.selections.get(iface, None)
		if new_sel is None:
			print _("No longer used: %s") % iface
			changes = True
		elif old_sel.version != new_sel.version:
			print _("%s: %s -> %s") % (iface, old_sel.version, new_sel.version)
			changes = True

	for iface, new_sel in sels.selections.iteritems():
		if iface not in old_selections:
			print _("%s: new -> %s") % (iface, new_sel.version)
			changes = True

	if not changes:
		print _("No updates found.")
Beispiel #27
0
		def finish():
			import xdgutils
			iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text()))

			try:
				icon_path = iface_cache.get_icon_path(iface)
				xdgutils.add_to_menu(iface, icon_path, category.get_active_text())
			except SafeException, ex:
				box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(ex))
				box.run()
				box.destroy()
Beispiel #28
0
 def testAlias(self):
     local_feed = model.canonical_iface_uri(os.path.join(
         mydir, 'Local.xml'))
     alias_path = os.path.join(mydir, '..', '0alias')
     child = subprocess.Popen([alias_path, 'local-app', local_feed],
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              universal_newlines=True)
     out, err = child.communicate()
     assert 'ERROR: "0alias" has been removed; use "0install add" instead' in err, err
     assert not out, out
Beispiel #29
0
def do_setup(args, get_dir_callback = None):
	"setup [ SOURCE-URI [ DIR ] ]"
	if len(args) == 0:
		assert get_dir_callback is None
		buildenv = BuildEnv()
		interface = buildenv.interface
		assert interface
		create_dir = None
		buildenv.get_selections(prompt = True)
	else:
		buildenv = BuildEnv(need_config = False)
		interface = args[0]
		if get_dir_callback:
			assert len(args) == 1
		if len(args) == 1:
			create_dir = os.path.basename(interface)
			if create_dir.endswith('.xml'):
				create_dir = create_dir[:-4]
			if create_dir.startswith('alias:'):
				create_dir = create_dir.split(':', 1)[1]
			assert os.path.dirname(create_dir) == ''
			assert create_dir != os.path.curdir
			if get_dir_callback:
				create_dir = get_dir_callback(create_dir)
		elif len(args) == 2:
			create_dir = args[1]
			if create_dir == '.':
				create_dir = None
		else:
			raise __main__.UsageError()

		iface_uri = model.canonical_iface_uri(args[0])
		if os.path.isabs(iface_uri):
			root = qdom.parse(file(iface_uri))
			if root.uri == namespaces.XMLNS_IFACE and root.name == 'selections':
				# Looks like this is a selections file, not an interface.
				buildenv.config.set('compile', 'selections', iface_uri)
				iface_uri = root.getAttribute('interface')
		buildenv.config.set('compile', 'interface', iface_uri)

		if create_dir and os.path.exists(create_dir):
			raise SafeException("Directory '%s' already exists." % create_dir)
		buildenv.get_selections()

	if create_dir:
		try:
			os.mkdir(create_dir)
		except:
			print >>sys.stderr, "Failed to create new directory '%s'" % os.path.abspath(create_dir)
			raise
		os.chdir(create_dir)
		print "Created directory %s" % create_dir

	buildenv.save()
Beispiel #30
0
		def finish():
			import xdgutils
			iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text()))

			try:
				icon_path = iface_cache.get_icon_path(iface)
				xdgutils.add_to_menu(iface, icon_path, categories[category.get_active()])
			except SafeException, ex:
				box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(ex))
				box.run()
				box.destroy()
Beispiel #31
0
def handle(config, options, args):
    if len(args) == 2:
        iface = config.iface_cache.get_interface(
            model.canonical_iface_uri(args[0]))
        try:
            feed_url = model.canonical_iface_uri(args[1])
        except SafeException:
            feed_url = args[1]  # File might not exist any longer

        feed_import = add_feed.find_feed_import(iface, feed_url)
        if not feed_import:
            raise SafeException(
                _('Interface %(interface)s has no feed %(feed)s') % {
                    'interface': iface.uri,
                    'feed': feed_url
                })
        iface.extra_feeds.remove(feed_import)
        writer.save_interface(iface)
    elif len(args) == 1:
        add_feed.handle(config, options, args, add_ok=False, remove_ok=True)
    else:
        raise UsageError()
Beispiel #32
0
    def __init__(self, feed, seed=None):
        _Link.__init__(self)

        self.force = False

        iface_uri = model.canonical_iface_uri(feed)
        self.policy = Policy(iface_uri)
        self.policy.solver.record_details = True

        if seed is not None:
            self.policy.network_use = seed.policy.network_use
            self.policy.handler = seed.policy.handler
            self.force = seed.force
Beispiel #33
0
def handle(config, options, args):
	if len(args) != 1:
		raise UsageError()
	iface_uri = model.canonical_iface_uri(args[0])

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

	if options.xml:
		show_xml(sels)
	else:
		show_human(sels, config.stores)
Beispiel #34
0
	def testReplacedConflicts(self):
		self.import_feed('http://localhost:8000/Hello', 'Hello')
		s = solver.DefaultSolver(self.config)
		replaced_path = model.canonical_iface_uri(os.path.join(mydir, 'Replaced.xml'))
		replaced_conflicts_path = model.canonical_iface_uri(os.path.join(mydir, 'ReplacedConflicts.xml'))
		r = Requirements(replaced_conflicts_path)
		s.solve_for(r)
		assert s.ready, s.get_failure_reason()
		assert s.selections
		self.assertEqual("b", s.selections.selections[replaced_conflicts_path].id)
		self.assertEqual("2", s.selections.selections[replaced_conflicts_path].version)
		self.assertEqual("sha1=3ce644dc725f1d21cfcf02562c76f375944b266a", s.selections.selections["http://localhost:8000/Hello"].id)
		self.assertEqual(2, len(s.selections.selections))

		s.extra_restrictions[self.config.iface_cache.get_interface(r.interface_uri)] = [
				model.VersionRangeRestriction(model.parse_version('2'), None)]

		s.solve_for(r)
		assert s.ready, s.get_failure_reason()
		assert s.selections
		self.assertEqual("1", s.selections.selections[replaced_conflicts_path].version)
		self.assertEqual("0", s.selections.selections[replaced_path].version)
		self.assertEqual(2, len(s.selections.selections))
	def testStoreStability(self):
		iface_uri = model.canonical_iface_uri('Hello.xml')
		main_feed = reader.load_feed(iface_uri, local = True)
		impl = main_feed.implementations['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
		impl.user_stability = model.developer
		writer.save_feed(main_feed)

		# Rating now visible
		main_feed = reader.load_feed(iface_uri, local = True)
		reader.update_user_feed_overrides(main_feed)
		self.assertEqual(1, len(main_feed.implementations))

		impl = main_feed.implementations['sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
		self.assertEqual(model.developer, impl.user_stability)
Beispiel #36
0
def handle(config, options, args):
	if len(args) != 1:
		raise UsageError()
	iface_uri = model.canonical_iface_uri(args[0])

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

	if options.xml:
		select.show_xml(sels)
	if options.show:
		select.show_human(sels, config.stores)
Beispiel #37
0
    def testAlias(self):
        local_feed = model.canonical_iface_uri(os.path.join(
            mydir, 'Local.xml'))
        alias_path = os.path.join(mydir, '..', '0alias')
        child = subprocess.Popen([alias_path, 'local-app', local_feed],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 universal_newlines=True)
        out, err = child.communicate()
        assert '("0alias" is deprecated; using "0install add" instead)' in out, out
        assert not err, err

        app = self.config.app_mgr.lookup_app('local-app')
        assert app.get_requirements().interface_uri == local_feed
Beispiel #38
0
    def testStoreStability(self):
        iface_uri = model.canonical_iface_uri('Hello.xml')
        main_feed = reader.load_feed(iface_uri, local=True)
        impl = main_feed.implementations[
            'sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
        impl.user_stability = model.developer
        writer.save_feed(main_feed)

        # Rating now visible
        main_feed = reader.load_feed(iface_uri, local=True)
        reader.update_user_feed_overrides(main_feed)
        self.assertEqual(1, len(main_feed.implementations))

        impl = main_feed.implementations[
            'sha1=3ce644dc725f1d21cfcf02562c76f375944b266a']
        self.assertEqual(model.developer, impl.user_stability)
Beispiel #39
0
def handle(config, options, args):
    """@type config: L{zeroinstall.injector.config.Config}
	@type args: [str]"""
    if len(args) != 1:
        raise UsageError()

    app = config.app_mgr.lookup_app(args[0], missing_ok=True)
    if app is not None:
        old_sels = app.get_selections()

        requirements = app.get_requirements()
        changes = requirements.parse_update_options(options)
        iface_uri = old_sels.interface

        if requirements.extra_restrictions and not options.xml:
            print("User-provided restrictions in force:")
            for uri, expr in requirements.extra_restrictions.items():
                print("  {uri}: {expr}".format(uri=uri, expr=expr))
            print()
    else:
        iface_uri = model.canonical_iface_uri(args[0])
        requirements = None
        changes = False

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

    if options.xml:
        show_xml(sels)
    else:
        show_human(sels, config.stores)
        if app is not None:
            from zeroinstall.cmd import whatchanged
            changes = whatchanged.show_changes(old_sels.selections,
                                               sels.selections) or changes
            if changes:
                print(
                    _("(note: use '0install update' instead to save the changes)"
                      ))
Beispiel #40
0
def handle(config, options, args):
	if len(args) != 2:
		raise UsageError()

	pet_name = args[0]
	iface_uri = model.canonical_iface_uri(args[1])

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

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

	app = config.app_mgr.create_app(pet_name, r)
	app.set_selections(sels)
	app.integrate_shell(pet_name)
Beispiel #41
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)
Beispiel #42
0
	def testLocalFeedMirror(self):
		with resourcewarnings_suppressed():
			# This is like testImplMirror, except we have a local feed.
			run_server(server.Give404('/HelloWorld.tgz'),
					'/0mirror/archive/http%3A%23%23example.com%3A8000%23HelloWorld.tgz')
			iface_uri = model.canonical_iface_uri('Hello.xml')
			driver = Driver(requirements = Requirements(iface_uri), config = self.config)
			self.config.mirror = 'http://example.com:8000/0mirror'

			refreshed = driver.solve_with_downloads()
			tasks.wait_for_blocker(refreshed)
			assert driver.solver.ready

			getLogger().setLevel(logging.ERROR)
			downloaded = driver.download_uncached_implementations()
			tasks.wait_for_blocker(downloaded)
			path = self.config.stores.lookup_any(driver.solver.selections.selections[iface_uri].digests)
			assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
Beispiel #43
0
	def testLocalFeedMirror(self):
		with resourcewarnings_suppressed():
			# This is like testImplMirror, except we have a local feed.
			run_server(server.Give404('/HelloWorld.tgz'),
					'/0mirror/archive/http%3A%23%23example.com%3A8000%23HelloWorld.tgz')
			iface_uri = model.canonical_iface_uri('Hello.xml')
			driver = Driver(requirements = Requirements(iface_uri), config = self.config)
			self.config.mirror = 'http://example.com:8000/0mirror'

			refreshed = driver.solve_with_downloads()
			tasks.wait_for_blocker(refreshed)
			assert driver.solver.ready

			getLogger().setLevel(logging.ERROR)
			downloaded = driver.download_uncached_implementations()
			tasks.wait_for_blocker(downloaded)
			path = self.config.stores.lookup_any(driver.solver.selections.selections[iface_uri].digests)
			assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
Beispiel #44
0
        def finish():
            from . import xdgutils
            iface_uri = model.canonical_iface_uri(uri.get_text())
            iface = iface_cache.get_interface(iface_uri)
            feed = iface_cache.get_feed(iface_uri)

            try:
                icon_path = iface_cache.get_icon_path(iface)
                xdgutils.add_to_menu(feed, icon_path,
                                     categories[category.get_active()])
            except SafeException as ex:
                box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
                                        gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                        str(ex))
                box.run()
                box.destroy()
            else:
                self.window.destroy()
Beispiel #45
0
	def testLocalFeedMirror(self):
		# This is like testImplMirror, except we have a local feed.

		child_config = config.Config()
		child_config.auto_approve_keys = False
		child_config.key_info_server = 'http://localhost:3333/key-info'
		child_config.mirror = 'http://example.com:8000/0mirror'
		child_config.save_globals()

		run_server(server.Give404('/HelloWorld.tgz'),
				'/0mirror/archive/http%3A%23%23example.com%3A8000%23HelloWorld.tgz')
		iface_uri = model.canonical_iface_uri('Hello.xml')
		out, err = self.run_ocaml(['download', iface_uri, '--xml'], binary = True)
		assert b'Missing: HelloWorld.tgz: trying archive mirror at http://roscidus.com/0mirror/archive/http%3A%23%23example.com%3A8000%23HelloWorld.tgz', err

		sels = selections.Selections(qdom.parse(BytesIO(out)))
		path = self.config.stores.lookup_any(sels.selections[iface_uri].digests)
		assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
Beispiel #46
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)
Beispiel #47
0
		def update_details_page():
			iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text()))
			about.set_text('%s - %s' % (iface.get_name(), iface.summary))
			icon_path = iface_cache.get_icon_path(iface)
			from zeroinstall.gtkui import icon
			icon_pixbuf = icon.load_icon(icon_path)
			if icon_pixbuf:
				icon_widget.set_from_pixbuf(icon_pixbuf)

			feed_category = None
			for meta in iface.get_metadata(XMLNS_IFACE, 'category'):
				feed_category = meta.content
				break
			if feed_category:
				i = 0
				for row in categories:
					if row.lower() == feed_category.lower():
						category.set_active(i)
						break
					i += 1
			self.window.set_response_sensitive(_RESPONSE_PREV, True)
Beispiel #48
0
		def update_details_page():
			iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text()))
			about.set_text('%s - %s' % (iface.get_name(), iface.summary))
			icon_path = iface_cache.get_icon_path(iface)
			from zeroinstall.gtkui import icon
			icon_pixbuf = icon.load_icon(icon_path)
			if icon_pixbuf:
				icon_widget.set_from_pixbuf(icon_pixbuf)

			feed_category = None
			for meta in iface.get_metadata(XMLNS_IFACE, 'category'):
				feed_category = meta.content
				break
			if feed_category:
				i = 0
				for row in category.get_model():
					if row[0].lower() == feed_category.lower():
						category.set_active(i)
						break
					i += 1
			self.window.set_response_sensitive(_RESPONSE_PREV, True)
Beispiel #49
0
    def testDownload(self):
        out, err = self.run_0install(['download'])
        assert out.lower().startswith("usage:")
        assert '--show' in out

        assert 'file\n' in self.complete(["download", ""], 2)

        out, err = self.run_0install(['download', 'Local.xml', '--show'])
        assert not err, err
        assert 'Version: 0.1' in out

        local_uri = model.canonical_iface_uri('Local.xml')
        out, err = self.run_0install(['download', 'Local.xml', '--xml'])
        assert not err, err
        sels = selections.Selections(
            qdom.parse(BytesIO(str(out).encode('utf-8'))))
        assert sels.selections[local_uri].version == '0.1'

        out, err = self.run_0install(
            ['download', 'Local.xml', '--show', '--with-store=/foo'])
        assert not err, err
        assert self.config.stores.stores[-1].dir == '/foo'

        out, err = self.run_0install(
            ['download', '--offline', 'selections.xml'])
        assert 'Would download' in err
        self.config.network_use = model.network_full

        self.config.stores = TestStores()
        digest = 'sha1=3ce644dc725f1d21cfcf02562c76f375944b266a'
        self.config.fetcher.allow_download(digest)
        out, err = self.run_0install(['download', 'Hello.xml', '--show'])
        assert not err, err
        assert self.config.stores.lookup_any([digest]).startswith('/fake')
        assert 'Version: 1\n' in out

        out, err = self.run_0install(
            ['download', '--offline', 'selections.xml', '--show'])
        assert '/fake_store' in out
        self.config.network_use = model.network_full
Beispiel #50
0
    def testSelect(self):
        out, err = self.run_0install(['select'])
        assert out.lower().startswith("usage:")
        assert '--xml' in out

        out, err = self.run_0install(['select', 'Local.xml'])
        assert not err, err
        assert 'Version: 0.1' in out

        local_uri = model.canonical_iface_uri('Local.xml')
        out, err = self.run_0install(['select', 'Local.xml'])
        assert not err, err
        assert 'Version: 0.1' in out

        out, err = self.run_0install(['select', 'Local.xml', '--xml'])
        sels = selections.Selections(qdom.parse(StringIO(str(out))))
        assert sels.selections[local_uri].version == '0.1'

        out, err = self.run_0install(['select', 'selections.xml'])
        assert not err, err
        assert 'Version: 1\n' in out
        assert '(not cached)' in out
	def testSelect(self):
		out, err = self.run_0install(['select'])
		assert out.lower().startswith("usage:")
		assert '--xml' in out

		out, err = self.run_0install(['select', 'Local.xml'])
		assert not err, err
		assert 'Version: 0.1' in out

		local_uri = model.canonical_iface_uri('Local.xml')
		out, err = self.run_0install(['select', 'Local.xml'])
		assert not err, err
		assert 'Version: 0.1' in out

		out, err = self.run_0install(['select', 'Local.xml', '--xml'])
		sels = selections.Selections(qdom.parse(StringIO(str(out))))
		assert sels.selections[local_uri].version == '0.1'

		out, err = self.run_0install(['select', 'selections.xml'])
		assert not err, err
		assert 'Version: 1\n' in out
		assert '(not cached)' in out
Beispiel #52
0
def handle(config, options, args):
	"""@type config: L{zeroinstall.injector.config.Config}
	@type args: [str]"""
	if len(args) != 1:
		raise UsageError()

	app = config.app_mgr.lookup_app(args[0], missing_ok = True)
	if app is not None:
		old_sels = app.get_selections()

		requirements = app.get_requirements()
		changes = requirements.parse_update_options(options)
		iface_uri = old_sels.interface

		if requirements.extra_restrictions and not options.xml:
			print("User-provided restrictions in force:")
			for uri, expr in requirements.extra_restrictions.items():
				print("  {uri}: {expr}".format(uri = uri, expr = expr))
			print()
	else:
		iface_uri = model.canonical_iface_uri(args[0])
		requirements = None
		changes = False

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

	if options.xml:
		show_xml(sels)
	else:
		show_human(sels, config.stores)
		if app is not None:
			from zeroinstall.cmd import whatchanged
			changes = whatchanged.show_changes(old_sels.selections, sels.selections) or changes
			if changes:
				print(_("(note: use '0install update' instead to save the changes)"))
Beispiel #53
0
def handle(config, options, args):
	"""@type args: [str]"""
	if len(args) != 2:
		raise UsageError()

	pet_name = args[0]
	iface_uri = model.canonical_iface_uri(args[1])

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

	root_feed = config.iface_cache.get_feed(iface_uri)
	if root_feed:
		target = root_feed.get_replaced_by()
		if target is not None:
			print(_("Warning: interface {old} has been replaced by {new}".format(old = iface_uri, new = target)))

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

	app = config.app_mgr.create_app(pet_name, r)
	app.set_selections(sels)
	app.integrate_shell(pet_name)