Beispiel #1
0
    def valid_libc(release, libc):
        try:
            info = DistroInfo().find(release=release)
        except DistroInfoError as e:
            raise BuildBoxError(str(e))

        return info.get("supported-architectures", {}).get(libc) is not None
Beispiel #2
0
    def list(self, *args):
        config = copy.deepcopy(self.config)

        def print_usage():
            print(
                textwrap.dedent("""
                USAGE:

                  bolt-distro-info list [OPTIONS]

                OPTIONS:

                  -h, --help           Print this help message.
                  -s, --supported      Show supported releases.
                  -u, --unsupported    Show old, unsupported releases.

                Per default supported and unsupported releases are listed.
                """))

        try:
            opts, args = getopt.getopt(args, "hsu",
                                       ["help", "supported", "unsupported"])
        except getopt.GetoptError as e:
            raise DistroInfoError("error parsing command line: {}".format(
                str(e)))

        supported = False
        unsupported = False

        for o, v in opts:
            if o in ["-h", "--help"]:
                print_usage()
                sys.exit(EXIT_OK)
            elif o in ["-s", "--supported"]:
                supported = True
            elif o in ["-u", "--unsupported"]:
                unsupported = True

        if not (supported or unsupported):
            supported = unsupported = True

        if args:
            print_usage()
            sys.exit(EXIT_ERROR)

        dists = DistroInfo(**config).list(supported=supported,
                                          unsupported=unsupported)

        if dists:
            print("\n".join(dists.keys()))
Beispiel #3
0
    def show(self, *args):
        config = copy.deepcopy(self.config)

        def print_usage():
            print(
                textwrap.dedent("""
                USAGE:

                  bolt-distro-info show [OPTIONS] <release-name>

                OPTIONS:

                  -h, --help           Print this help message.
                """))

        try:
            opts, args = getopt.getopt(args, "h", ["help"])
        except getopt.GetoptError as e:
            raise DistroInfoError("error parsing command line: {}".format(
                str(e)))

        for o, v in opts:
            if o in ["-h", "--help"]:
                print_usage()
                sys.exit(EXIT_OK)

        if len(args) != 1:
            print_usage()
            sys.exit(EXIT_ERROR)

        print(
            json.dumps(DistroInfo(**config).find(release=args[0]),
                       ensure_ascii=False,
                       indent=4))
Beispiel #4
0
    def valid_arch(release, arch, libc="musl"):
        try:
            info = DistroInfo().find(release=release)
        except DistroInfoError as e:
            raise BuildBoxError(str(e))

        return arch in info \
            .get("supported-architectures", {}) \
            .get(libc, [])
Beispiel #5
0
    def refresh(self, *args):
        config = copy.deepcopy(self.config)

        def print_usage():
            print(
                textwrap.dedent("""
                USAGE:

                  bolt-distro-info refresh [OPTIONS]

                OPTIONS:

                  -h, --help              Print this help message.
                  -r, --releases          Update release info.
                  -m, --mirrors           Update mirrors list.
                  --overwrite-existing    Overwrite existing entries.
                """))

        try:
            opts, args = getopt.getopt(
                args, "hmr",
                ["help", "mirrors", "overwrite-existing", "releases"])
        except getopt.GetoptError as e:
            raise DistroInfoError("error parsing command line: {}".format(
                str(e)))

        kwargs = {
            "releases": False,
            "mirrors": False,
            "overwrite_existing": False,
        }

        for o, v in opts:
            if o in ["-h", "--help"]:
                print_usage()
                sys.exit(EXIT_OK)
            elif o in ["-r", "--releases"]:
                kwargs["releases"] = True
            elif o in ["-m", "--mirrors"]:
                kwargs["mirrors"] = True
            elif o == "--overwrite-existing":
                kwargs["overwrite_existing"] = True
        #end for

        if args:
            print_usage()
            sys.exit(EXIT_ERROR)

        if not (kwargs["releases"] or kwargs["mirrors"]):
            raise DistroInfoError("specify at least one of -r or -m.")

        DistroInfo(**config).refresh(**kwargs)
Beispiel #6
0
    def fetch_from_repo(self, repo_name, pkg_name, version, filename,
            sha256sum=None):
        downloader = Downloader(progress_bar_class=ProgressBar)

        if pkg_name.startswith("lib"):
            first_letter = pkg_name[3]
        else:
            first_letter = pkg_name[0]

        rel_path = os.sep.join([first_letter, pkg_name, version, filename])

        mirror_url = DistroInfo().pick_mirror(
            release=self.release, repo_name=repo_name
        )

        source_url = "/".join([
            mirror_url,
            self.release,
            repo_name,
            "sources",
            rel_path
        ])

        target_url = os.sep.join([
            self.cache_dir,
            "bolt",
            "dists",
            self.release,
            "sources",
            repo_name,
            rel_path
        ])

        h = hashlib.sha256()

        LOGGER.info("retrieving {}".format(source_url))
        try:
            os.makedirs(os.path.dirname(target_url), exist_ok=True)

            with open(target_url, "wb+") as f:
                for chunk in downloader.get(source_url, digest=h):
                    f.write(chunk)
        except urllib.error.URLError as e:
            raise NetworkError(
                "failed to retrieve {}: {}".format(source_url, e.reason)
            )

        if sha256sum and sha256sum != h.hexdigest():
            raise BoltError("file {} has invalid checksum!".format(target_url))

        return target_url
Beispiel #7
0
    def bootstrap(self, *args):
        def print_usage(specfile_list=None):
            print(
                textwrap.dedent("""
                USAGE:

                  bolt-image bootstrap [OPTIONS] <sysroot> <specfile> ...

                OPTIONS:

                  -h, --help       Print this help message.
                  -r, --release    The name of the release (e.g. ollie).
                  -a, --arch       The target architecture.
                  -l, --libc       The C runtime to use ("musl" or "glibc").

                  --repo-base      Repository base URL not including the release
                                   name.
                  --copy-qemu      Copy the appropriate QEMU interpreter to the
                                   chroot (should not be necessary).
                  --no-verify      Do not verify package list signatures.
                """

                                # noqa
                                ))

            if specfile_list:
                print("INTERNAL SPECS:\n")
                for spec in specfile_list:
                    print("  * {}".format(spec))
                print("")

        #end inline function

        try:
            opts, args = getopt.getopt(args, "a:hl:r:", [
                "arch=", "copy-qemu", "help", "libc=", "no-verify", "release=",
                "repo-base="
            ])
        except getopt.GetoptError as e:
            raise ImageGenCli.Error("error parsing command line: {}".format(
                str(e)))

        distro_info = DistroInfo()

        kwargs = {
            "release": distro_info.latest_release(),
            "libc": "musl",
            "arch": Platform.uname("-m"),
            "repo_base": "http://archive.boltlinux.org/dists",
            "copy_qemu": False,
            "verify": True,
        }

        for o, v in opts:
            if o in ["-h", "--help"]:
                print_usage()
                sys.exit(EXIT_OK)
            elif o in ["-r", "--release"]:
                kwargs["release"] = v.strip()
            elif o in ["-a", "--arch"]:
                kwargs["arch"] = v.strip().replace("-", "_")
            elif o in ["-l", "--libc"]:
                kwargs["libc"] = v.strip()
            elif o == "--repo-base":
                kwargs["repo_base"] = v.strip()
            elif o == "--copy-qemu":
                kwargs["copy_qemu"] = True
            elif o == "--no-verify":
                kwargs["verify"] = False
        #end for

        release, libc, arch = kwargs["release"], kwargs["libc"], kwargs["arch"]

        if not distro_info.release_exists(release):
            raise ImageGenCli.Error(
                'release "{}" not found, run `bolt-distro-info refresh -r`.'.
                format(release))

        if not distro_info.is_supported_libc(release, libc):
            raise ImageGenCli.Error(
                'release "{}" does not support C runtime library "{}".'.format(
                    release, libc))

        if not distro_info.is_supported_arch(release, arch, libc=libc):
            raise ImageGenCli.Error(
                'release "{}" does not support architecture "{}".'.format(
                    release, arch))

        if len(args) == 0:
            print_usage(
                ImageGeneratorUtils.list_internal_specs(release, libc, arch))
            sys.exit(EXIT_ERROR)

        sysroot = args[0]

        if not os.path.isdir(sysroot):
            raise ImageGenCli.Error("no such directory: {}".format(sysroot))

        if len(args) < 2:
            print_usage(
                ImageGeneratorUtils.list_internal_specs(release, libc, arch))
            sys.exit(EXIT_ERROR)

        specfile_list = ImageGeneratorUtils.collect_specfiles(
            release, libc, arch, *args[1:])

        if os.geteuid() != 0:
            raise ImageGenCli.Error(
                "image generation needs to be done as root.")

        image_gen = ImageGenerator(**kwargs)
        image_gen.prepare(sysroot)

        with Sysroot(sysroot):
            for specfile in specfile_list:
                image_gen.customize(sysroot, specfile)
Beispiel #8
0
 def latest_release():
     try:
         return list(DistroInfo().list(supported=True).keys())[-1]
     except DistroInfoError as e:
         raise BuildBoxError(str(e))
Beispiel #9
0
 def valid_release(name):
     try:
         return name in DistroInfo().list(supported=True)
     except DistroInfoError as e:
         BuildBoxError(str(e))