Ejemplo n.º 1
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.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 ""
Ejemplo n.º 2
0
def setup_container(builddir, _container):
    """Prepare the container and returns the path where it can be found."""
    build_dir = local.path(builddir)
    in_dir = build_dir / "container-in"
    container_path = local.path(_container)
    with local.cwd(builddir):
        container_bin = container_path.basename
        container_in = in_dir / container_bin
        download.Copy(_container, container_in)
        uchrt = uchroot.no_args()

        with local.cwd("container-in"):
            uchrt = uchrt["-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 = uchrt[cmd[container_bin]]
        else:
            cmd = tar["xf"]
            cmd = cmd[container_in]

        with local.cwd("container-in"):
            cmd("--exclude=dev/*")
        rm(container_in)
    return in_dir
Ejemplo n.º 3
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.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 ""
Ejemplo n.º 4
0
def setup_container(builddir, _container):
    """Prepare the container and returns the path where it can be found."""
    build_dir = local.path(builddir)
    in_dir = build_dir / "container-in"
    container_path = local.path(_container)
    with local.cwd(builddir):
        container_bin = container_path.basename
        container_in = in_dir / container_bin
        download.Copy(_container, container_in)
        uchrt = uchroot.no_args()

        with local.cwd("container-in"):
            uchrt = uchrt["-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 = uchrt[cmd[container_bin]]
        else:
            cmd = tar["xf"]
            cmd = cmd[container_in]

        with local.cwd("container-in"):
            cmd("--exclude=dev/*")
        rm(container_in)
    return in_dir
Ejemplo n.º 5
0
def unpack(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
    from benchbuild.utils.uchroot import no_args

    path = local.path(path)
    c_filename = local.path(container.filename)
    name = c_filename.basename

    if not path.exists():
        path.mkdir()

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

        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)

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

        run(untar["--exclude=dev/*"])
        if not os.path.samefile(name, container.filename):
            rm(name)
        else:
            LOG.warning("File contents do not match: %s != %s", name,
                        container.filename)
        cp(container.filename + ".hash", path)
Ejemplo n.º 6
0
def unpack(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
    from benchbuild.utils.uchroot import no_args

    path = local.path(path)
    c_filename = local.path(container.filename)
    name = c_filename.basename

    if not path.exists():
        path.mkdir()

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

        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)

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

        run(untar["--exclude=dev/*"])
        if not os.path.samefile(name, container.filename):
            rm(name)
        else:
            LOG.warning("File contents do not match: %s != %s", name,
                        container.filename)
        cp(container.filename + ".hash", path)
Ejemplo n.º 7
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.uchroot import no_args, uretry

    uchroot = no_args()
    uchroot = uchroot["-E", "-A", "-C", "-w", "/", "-r"]
    uchroot = uchroot[os.path.abspath(root)]
    uretry(uchroot["--", "/bin/mkdir", "-p", dirpath])
Ejemplo n.º 8
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.uchroot import no_args, uretry

    uchroot = no_args()
    uchroot = uchroot["-E", "-A", "-C", "-w", "/", "-r"]
    uchroot = uchroot[os.path.abspath(root)]
    uretry(uchroot["--", "/bin/mkdir", "-p", dirpath])