Example #1
0
    def show(self, name):
        """Show the high-level commands executed by

            module show <collection>
        """
        collection = self.get(name)
        if collection is None:  # pragma: no cover
            tty.warning("{0!r} is not a collection".format(name))
            return

        sio = StringIO()
        loaded_modules = pymod.mc.get_loaded_modules()
        for m in loaded_modules[::-1]:
            sio.write("unload({0!r})\n".format(m.fullname))

        for (directory, archives) in collection:
            sio.write("use({0!r})\n".format(directory))
            for ar in archives:
                name = ar["fullname"]
                opts = ar["opts"]
                if opts:
                    opts_string = pymod.module.Namespace(**opts).joined(" ")
                    s = "load({0!r}, options={1!r})".format(name, opts_string)
                else:
                    s = "load({0!r})".format(name)
                sio.write(s + "\n")

        return sio.getvalue()
Example #2
0
    def issue_request(self, request, retry=True):
        """
        Given a prepared request, issue it.

        If we get an error, die. If
        there are times when we don't want to exit on error (but instead
        disable using the monitoring service) we could add that here.
        """
        try:
            response = urlopen(request)
        except URLError as e:

            # If we have an authorization request, retry once with auth
            if hasattr(e, "code") and e.code == 401 and retry:
                if self.authenticate_request(e):
                    request = self.prepare_request(
                        e.url,
                        sjson.load(request.data.decode('utf-8')),
                        self.headers
                    )
                    return self.issue_request(request, False)

            # Handle permanent re-directs!
            elif hasattr(e, "code") and e.code == 308:
                location = e.headers.get('Location')

                request_data = None
                if request.data:
                    request_data = sjson.load(request.data.decode('utf-8'))[0]

                if location:
                    request = self.prepare_request(
                        location,
                        request_data,
                        self.headers
                    )
                    return self.issue_request(request, True)

            # Otherwise, relay the message and exit on error
            msg = ""
            if hasattr(e, 'reason'):
                msg = e.reason
            elif hasattr(e, 'code'):
                msg = e.code

            # If we can parse the message, try it
            try:
                msg += "\n%s" % e.read().decode("utf8", 'ignore')
            except Exception:
                pass

            if self.allow_fail:
                tty.warning("Request to %s was not successful, but continuing." % e.url)
                return

            tty.die(msg)

        return response
Example #3
0
    def load_build_environment(self, spec):
        """
        Load a build environment from install_environment.json.

        If we are running an analyze command, we will need to load previously
        used build environment metadata from install_environment.json to capture
        what was done during the build.
        """
        if not hasattr(spec, "package") or not spec.package:
            tty.die("A spec must have a package to load the environment.")

        pkg_dir = os.path.dirname(spec.package.install_log_path)
        env_file = os.path.join(pkg_dir, "install_environment.json")
        build_environment = read_json(env_file)
        if not build_environment:
            tty.warning(
                "install_environment.json not found in package folder. "
                " This means that the current environment metadata will be used."
            )
        else:
            self.build_environment = build_environment
Example #4
0
    def configure_args(self):
        spec = self.spec

        args = ["--enable-ndb"]

        pkg_config = os.path.join(spec['lua'].prefix.lib, "pkgconfig")
        os.environ['PKG_CONFIG_PATH'] = pkg_config
        os.putenv('PKG_CONFIG_PATH', pkg_config)

        # cryptography library defaults to libgcrypt, but doesn't hurt to specify
        if "+openssl" in spec:
            args.append("--with-crypto=openssl")
            tty.warning(openssl_warning)
        else:
            args.append("--with-crypto=libgcrypt")

        # Default to ndb (no deps) if sqlite not wanted
        if "+sqlite" in spec:
            args.append("--enable-sqlite")
        if "+bdb_ro" in spec:
            args.append("--bdb-ro")

        # Enable support for selinux
        if "+selinux" in spec:
            args.append('--with-selinux')
        if "+python" in spec:
            args.append("--enable-python")

        # enable POSIX.1e draft 15 file capabilities support
        if "+posix" in spec:
            args.append('--with-cap')

        # OpenMP multithreading support automatically enabled if C compiler has
        # support for OpenMP version 4.5 or higher
        if "~openmp" in spec:
            args.append("--disable-openmp")

        return args
Example #5
0
    def issue_request(self, request, retry=True):
        """
        Given a prepared request, issue it.

        If we get an error, die. If
        there are times when we don't want to exit on error (but instead
        disable using the monitoring service) we could add that here.
        """
        try:
            response = urlopen(request)
        except URLError as e:

            # If we have an authorization request, retry once with auth
            if hasattr(e, "code") and e.code == 401 and retry:
                if self.authenticate_request(e):
                    request = self.prepare_request(
                        e.url,
                        sjson.load(request.data.decode('utf-8')),
                        self.headers
                    )
                    return self.issue_request(request, False)

            # Otherwise, relay the message and exit on error
            msg = ""
            if hasattr(e, 'reason'):
                msg = e.reason
            elif hasattr(e, 'code'):
                msg = e.code

            if self.allow_fail:
                tty.warning("Request to %s was not successful, but continuing." % e.url)
                return

            tty.die(msg)

        return response