Beispiel #1
0
def setup_container(builddir, container):
    """Prepare the container and returns the path where it can be found."""
    with local.cwd(builddir):
        container_filename = str(container).split(os.path.sep)[-1]
        container_in = os.path.join("container-in", container_filename)
        Copy(container, container_in)
        uchroot = uchroot_no_args()

        with local.cwd("container-in"):
            uchroot = uchroot["-E", "-A", "-u", "0", "-g", "0", "-C", "-r",
                              "/", "-w",
                              os.path.abspath("."), "--"]

        # Check, if we need erlent support for this archive.
        has_erlent = bash["-c",
                          "tar --list -f './{0}' | grep --silent '.erlent'".
                          format(container_in)]
        has_erlent = (has_erlent & TF)

        # Unpack input container to: container-in
        if not has_erlent:
            cmd = local["/bin/tar"]["xf"]
            cmd = uchroot[cmd[container_filename]]
        else:
            cmd = tar["xf"]
            cmd = cmd[os.path.abspath(container_in)]

        with local.cwd("container-in"):
            cmd("--exclude=dev/*")
        rm(container_in)
    return os.path.join(builddir, "container-in")
Beispiel #2
0
    def __str__(self):
        try:
            domain, _, name = self.name.partition("_")
            package = domain + '/' + name
            container = self.container()

            uchroot = uchroot_no_args()
            uchroot = uchroot["-E", "-A", "-C", "-w", "/", "-r"]
            uchroot = uchroot[container.local]
            with local.env(CONFIG_PROTECT="-*"):
                fake_emerge = uchroot["emerge", "--autounmask-only=y",
                                      "--autounmask-write=y", "--nodeps"]
                run(fake_emerge[package])

            emerge_in_chroot = uchroot["emerge", "-p", "--nodeps", package]
            _, stdout, _ = emerge_in_chroot.run()

            for line in stdout.split('\n'):
                if package in line:
                    _, _, package_name = line.partition("/")
                    _, name, version = package_name.partition(name)
                    version, _, _ = version.partition(" ")
                    return version[1:]
        except ProcessExecutionError:
            logger = logging.getLogger(__name__)
            logger.info("This older package might not exist any more.")
        return "Default"
Beispiel #3
0
def run_in_container(command, container_dir, mounts):
    uchroot = uchroot_no_args()["-E", "-A", "-u", "0", "-g", "0", "-C", "-w",
                                "/", "-r", os.path.abspath(container_dir)]
    uchroot_m = uchroot
    uchroot = uchroot["--"]

    for mount in mounts:
        absdir = os.path.abspath(str(mount))
        dirname = os.path.split(absdir)[-1]
        uchroot_m = uchroot_m["-m", "{0}:/mnt/{1}".format(absdir, dirname)]
        mount_path = os.path.join(container_dir, "mnt", dirname)
        if not os.path.exists(mount_path):
            uchroot("mkdir", "-p", "/mnt/{0}".format(dirname))
        print("Mounting: '{0}' inside container at '/mnt/{1}'".format(mount,
                                                                      dirname))

    cmd_path = os.path.join(container_dir, command.lstrip('/'))
    if not os.path.exists(cmd_path):
        logging.error(
            "The command does not exist inside the container! {0}".format(
                cmd_path))
        return

    cmd = uchroot_m[command]
    return cmd & FG
Beispiel #4
0
def setup_container(builddir, container):
    with local.cwd(builddir):
        container_filename = str(container).split(os.path.sep)[-1]
        container_in = os.path.join("container-in", container_filename)
        Copy(container, container_in)
        uchroot = uchroot_no_args()

        with local.cwd("container-in"):
            uchroot = uchroot["-E", "-A", "-u", "0", "-g", "0", "-C", "-r",
                              "/", "-w", os.path.abspath("."), "--"]

        # Check, if we need erlent support for this archive.
        has_erlent = bash[
            "-c", "tar --list -f './{0}' | grep --silent '.erlent'".format(
                container_in)]
        has_erlent = (has_erlent & TF)

        # Unpack input container to: container-in
        if not has_erlent:
            cmd = local["/bin/tar"]["xf"]
            cmd = uchroot[cmd[container_filename]]
        else:
            cmd = tar["xf"]
            cmd = cmd[os.path.abspath(container_in)]

        with local.cwd("container-in"):
            cmd("--exclude=dev/*")
        rm(container_in)
    return os.path.join(builddir, "container-in")
Beispiel #5
0
def unpack_container(container, path):
    """
    Unpack a container usable by uchroot.

    Method that checks if a directory for the container exists,
    checks if erlent support is needed and then unpacks the
    container accordingly.

    Args:
        path: The location where the container is, that needs to be unpacked.

    """
    from benchbuild.utils.run import run, uchroot_no_args

    path = os.path.abspath(path)
    name = os.path.basename(os.path.abspath(container.filename))
    if not os.path.exists(path):
        mkdir("-p", path)

    with local.cwd(path):
        Wget(container.remote, name)

        uchroot = uchroot_no_args()
        uchroot = uchroot["-E", "-A", "-C", "-r", "/", "-w",
                          os.path.abspath("."), "--"]

        # Check, if we need erlent support for this archive.
        has_erlent = bash[
            "-c",
            "tar --list -f './{0}' | grep --silent '.erlent'".format(name)]
        has_erlent = (has_erlent & TF)

        cmd = local["/bin/tar"]["xf"]
        if not has_erlent:
            cmd = uchroot[cmd["./" + name]]
        else:
            cmd = cmd[name]

        run(cmd["--exclude=dev/*"])
        if not os.path.samefile(name, container.filename):
            rm(name)
        else:
            logging.warning("File contents do not match: {0} != {1}", name,
                            container.filename)
        cp(container.filename + ".hash", path)
Beispiel #6
0
def mkdir_uchroot(dirpath, root="."):
    """
    Create a file inside a uchroot env.

    You will want to use this when you need to create a file with apropriate
    rights inside a uchroot container with subuid/subgid handling enabled.

    Args:
        dirpath:
            The dirpath that should be created. Absolute inside the
            uchroot container.
        root:
            The root PATH of the container filesystem as seen outside of
            the container.
    """
    from benchbuild.utils.run import uchroot_no_args

    uchroot = uchroot_no_args()
    uchroot = uchroot["-E", "-A", "-C", "-w", "/", "-r"]
    uchroot = uchroot[os.path.abspath(root)]
    uchroot("--", "/bin/mkdir", "-p", dirpath)
Beispiel #7
0
    def download(self):
        from benchbuild.utils.run import uchroot_no_args
        with local.cwd(self.builddir):
            Wget(self.src_uri, self.src_file)
            uchroot = uchroot_no_args()
            uchroot = uchroot["-E", "-A", "-C", "-r", "/", "-w", path.abspath(
                "."), "--"]

            # Check, if we need erlent support for this archive.
            has_erlent = bash[
                "-c", "tar --list -f './{0}' | grep --silent '.erlent'".format(
                    self.src_file)]
            has_erlent = (has_erlent & TF)

            cmd = local["/bin/tar"]["xf"]
            if not has_erlent:
                cmd = uchroot[cmd["./" + path.basename(self.src_file)]]
            else:
                cmd = cmd[self.src_file]

            run(cmd["--exclude=dev/*"])
            rm(self.src_file)