Example #1
0
def _0install_man(config, command):
	from zeroinstall import apps, alias, helpers

	path = support.find_in_path(command)
	if not path:
		return None

	with open(path, 'rt') as stream:
		app_info = apps.parse_script_header(stream)
		if app_info:
			app = config.app_mgr.lookup_app(app_info.name)
			sels = app.get_selections()
			main = None
		else:
			alias_info = alias.parse_script_header(stream)
			if alias_info is None:
				return None
			sels = helpers.ensure_cached(alias_info.uri, alias_info.command, config = config)
			if not sels:
				# Cancelled by user
				sys.exit(1)
			main = alias_info.main

	helpers.exec_man(config.stores, sels, main, fallback_name = command)
	assert 0
Example #2
0
	def action_help(self, uri):
		from zeroinstall.injector.config import load_config
		from zeroinstall import helpers
		c = load_config()
		sels = helpers.ensure_cached(uri, config = c)
		if not sels:
			return

		impl = sels.selections[uri]
		assert impl, "Failed to choose an implementation of %s" % uri
		help_dir = impl.attrs.get('doc-dir')

		if impl.id.startswith('package:'):
			assert os.path.isabs(help_dir), "Package doc-dir must be absolute!"
			path = help_dir
		else:
			path = impl.local_path or c.stores.lookup_any(impl.digests)

			assert path, "Chosen implementation is not cached!"
			if help_dir:
				path = os.path.join(path, help_dir)
			else:
				main = impl.main
				if main:
					# Hack for ROX applications. They should be updated to
					# set doc-dir.
					help_dir = os.path.join(path, os.path.dirname(main), 'Help')
					if os.path.isdir(help_dir):
						path = help_dir

		# xdg-open has no "safe" mode, so check we're not "opening" an application.
		if os.path.exists(os.path.join(path, 'AppRun')):
			raise Exception(_("Documentation directory '%s' is an AppDir; refusing to open") % path)

		subprocess.Popen(['xdg-open', path])
Example #3
0
def _0install_man(config, command):
    from zeroinstall import apps, alias, helpers

    path = support.find_in_path(command)
    if not path:
        return None

    with open(path, 'rt') as stream:
        app_info = apps.parse_script_header(stream)
        if app_info:
            app = config.app_mgr.lookup_app(app_info.name)
            sels = app.get_selections()
            main = None
        else:
            alias_info = alias.parse_script_header(stream)
            if alias_info is None:
                return None
            sels = helpers.ensure_cached(alias_info.uri,
                                         alias_info.command,
                                         config=config)
            if not sels:
                # Cancelled by user
                sys.exit(1)
            main = alias_info.main

    helpers.exec_man(config.stores, sels, main, fallback_name=command)
    assert 0
Example #4
0
def _0install_man(config, command):
    """@type command: str"""
    from zeroinstall import apps, alias, helpers

    path = support.find_in_path(command)
    if not path:
        return None

    try:
        with open(path, 'rt') as stream:
            app_info = apps.parse_script_header(stream)
            if app_info:
                app = config.app_mgr.lookup_app(app_info.name)
                sels = app.get_selections()
                main = None
            else:
                alias_info = alias.parse_script_header(stream)
                if alias_info is None:
                    return None
                sels = helpers.ensure_cached(alias_info.uri,
                                             alias_info.command,
                                             config=config)
                if not sels:
                    # Cancelled by user
                    sys.exit(1)
                main = alias_info.main
    except IOError as ex:
        logger.info("%s: falling back to `man %s`", ex, command)
        os.execlp('man', 'man', command)
        sys.exit(1)

    helpers.exec_man(config.stores, sels, main, fallback_name=command)
    assert 0
Example #5
0
def _0install_man(config, command):
    """@type command: str"""
    from zeroinstall import apps, alias, helpers

    path = support.find_in_path(command)
    if not path:
        return None

    try:
        with open(path, "rt") as stream:
            app_info = apps.parse_script_header(stream)
            if app_info:
                app = config.app_mgr.lookup_app(app_info.name)
                sels = app.get_selections()
                main = None
            else:
                alias_info = alias.parse_script_header(stream)
                if alias_info is None:
                    return None
                sels = helpers.ensure_cached(alias_info.uri, alias_info.command, config=config)
                if not sels:
                    # Cancelled by user
                    sys.exit(1)
                main = alias_info.main
    except IOError as ex:
        logger.info("%s: falling back to `man %s`", ex, command)
        os.execlp("man", "man", command)
        sys.exit(1)

    helpers.exec_man(config.stores, sels, main, fallback_name=command)
    assert 0
Example #6
0
	def testHelpers(self):
		from zeroinstall import helpers

		with output_suppressed():
			run_server('Hello.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz')
			sys.stdin = Reply("Y\n")
			sels = helpers.ensure_cached('http://example.com:8000/Hello.xml', config = self.config)
			path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests)
			assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
			assert sels.download_missing(self.config) is None
Example #7
0
	def testHelpers(self):
		from zeroinstall import helpers

		with output_suppressed():
			run_server('Hello.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz')
			sys.stdin = Reply("Y\n")
			sels = helpers.ensure_cached('http://example.com:8000/Hello.xml', config = self.config)
			path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests)
			assert os.path.exists(os.path.join(path, 'HelloWorld', 'main'))
			assert sels.download_missing(self.config) is None
Example #8
0
    def testHelpers(self):
        from zeroinstall import helpers

        with output_suppressed():
            self.child = server.handle_requests(
                "Hello.xml",
                "6FCF121BE2390E0B.gpg",
                "/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B",
                "HelloWorld.tgz",
            )
            sys.stdin = Reply("Y\n")
            sels = helpers.ensure_cached("http://example.com:8000/Hello.xml")
            path = self.config.stores.lookup_any(sels.selections["http://example.com:8000/Hello.xml"].digests)
            assert os.path.exists(os.path.join(path, "HelloWorld", "main"))
            assert sels.download_missing(self.config) is None
Example #9
0
def find(url):
	try:
		del os.environ['DISPLAY']
	except KeyError: pass
	if os.path.isfile(url):
		url = os.path.abspath(url)
	selections = helpers.ensure_cached(url, command=None)
	if not selections:
		return None
	selection = selections.selections[url]

	if selection.id.startswith("package:"):
		print >> sys.stderr, "Package implementation: %s" % (selection.id,)
		return None
	if os.path.exists(selection.id):
		return selection.id
	return zerostore.Stores().lookup_any(selection.digests)
Example #10
0
def ZeroFindPath(url):
    """
    find the path on the file system from the url
    from https://github.com/gfxmonk/0find/blob/master/zerofind.py
    """
    try:
        del os.environ['DISPLAY']
    except KeyError: pass
    selections = helpers.ensure_cached(url, command=None)
    if not selections:
        return None
    selection = selections.selections[url]

    if selection.id.startswith("package:"):
        print >> sys.stderr, "Package implementation: %s" % (selection.id,)
        return None
    if os.path.exists(selection.id):
        return selection.id
    return zerostore.Stores().lookup_any(selection.digests)
Example #11
0
def ZeroFindPath(url):
    """
    find the path on the file system from the url
    from https://github.com/gfxmonk/0find/blob/master/zerofind.py
    """
    try:
        del os.environ['DISPLAY']
    except KeyError:
        pass
    selections = helpers.ensure_cached(url, command=None)
    if not selections:
        return None
    selection = selections.selections[url]

    if selection.id.startswith("package:"):
        print >> sys.stderr, "Package implementation: %s" % (selection.id, )
        return None
    if os.path.exists(selection.id):
        return selection.id
    return zerostore.Stores().lookup_any(selection.digests)
Example #12
0
    def action_help(self, uri):
        from zeroinstall.injector.config import load_config
        from zeroinstall import helpers
        c = load_config()
        sels = helpers.ensure_cached(uri, config=c)
        if not sels:
            return

        impl = sels.selections[uri]
        assert impl, "Failed to choose an implementation of %s" % uri
        help_dir = impl.attrs.get('doc-dir')

        if impl.id.startswith('package:'):
            assert os.path.isabs(help_dir), "Package doc-dir must be absolute!"
            path = help_dir
        else:
            path = impl.local_path or c.stores.lookup_any(impl.digests)

            assert path, "Chosen implementation is not cached!"
            if help_dir:
                path = os.path.join(path, help_dir)
            else:
                main = impl.main
                if main:
                    # Hack for ROX applications. They should be updated to
                    # set doc-dir.
                    help_dir = os.path.join(path, os.path.dirname(main),
                                            'Help')
                    if os.path.isdir(help_dir):
                        path = help_dir

        # xdg-open has no "safe" mode, so check we're not "opening" an application.
        if os.path.exists(os.path.join(path, 'AppRun')):
            raise Exception(
                _("Documentation directory '%s' is an AppDir; refusing to open"
                  ) % path)

        subprocess.Popen(['xdg-open', path])
Example #13
0
			full = os.path.join(root, item)
			if os.path.islink(full):
				# Allows getting read access to the rest of the filesystem
				raise SafeException("Package file %s is a symlink; this is not currently allowed, sorry!" % full)

my_dir = os.path.dirname(__file__)
try:
	apprun = options.apprun
	if apprun:
		# Run existing app-dir
		appdir = os.path.dirname(os.path.realpath(apprun))
		print "Running E instance", appdir
		with open(os.path.join(appdir, 'uri')) as uri_stream:
			root_uri = uri_stream.read()
		print "Selecting", root_uri
		sels = ensure_cached(root_uri, command = 'org.erights/rune')
		if sels is None:
			sys.exit(1)

		locations = {}
		dependencies = {}
		for uri, impl in sels.selections.items():
			locations[uri] = _get_implementation_path(impl)

			ensure_no_symlinks(locations[uri])

			my_deps = []
			for dep in impl.dependencies:
				dep_impl = sels.selections[dep.interface]
				assert not dep_impl.id.startswith('package:'), dep_impl
				for b in dep.bindings: