示例#1
0
def emerge_package(pearl_env: PearlEnvironment, package: Package,
                   args: Namespace):
    """
    Installs or updates the Pearl package.
    This function is idempotent.
    """
    if package.is_installed():
        update_package(pearl_env, package, args=args)
    else:
        install_package(pearl_env, package, args=args)
示例#2
0
def install_package(pearl_env: PearlEnvironment, package: Package,
                    args: Namespace):
    """
    Installs the Pearl package.
    """
    if package.is_installed():
        raise PackageAlreadyInstalledError(
            '{} package is already installed.'.format(package))

    messenger.print('{cyan}* {normal}Installing {pkg} package'.format(
        cyan=Color.CYAN,
        normal=Color.NORMAL,
        pkg=package,
    ))
    package.dir.mkdir(parents=True, exist_ok=True)
    if package.is_local():
        check_and_copy(Path(package.url), package.dir)
    else:
        quiet = "false" if args.verbose else "true"
        script = dedent("""
            install_git_repo {pkgurl} {pkgdir} "" {quiet}
            """).format(pkgdir=package.dir, pkgurl=package.url, quiet=quiet)
        run_pearl_bash(script,
                       pearl_env,
                       input=_DEFAULT_INPUT if args.no_confirm else None)

    package.vardir.mkdir(parents=True, exist_ok=True)

    hook = 'post_install'
    try:
        _run(
            hook,
            pearl_env,
            package,
            input=_DEFAULT_INPUT if args.no_confirm else None,
            enable_xtrace=(args.verbose >= 2),
            enable_errexit=(not args.force),
        )
    except Exception as exc:
        msg = "Error while performing {} hook function. Rolling back...".format(
            hook)
        if args.force:
            message = "{}: {}".format(msg, exc.args)
            if args.verbose:
                messenger.exception(message)
            else:
                messenger.error(message)
        else:
            args.force = True
            remove_package(
                pearl_env,
                package,
                args=args,
            )
            raise HookFunctionError(msg) from exc
示例#3
0
def info_package(pearl_env: PearlEnvironment, package: Package,
                 args: Namespace):
    """
    Provide info about a package.
    """
    requires = pearl_env.required_by(package)
    messenger.print(
        dedent("""
        {cyan}Name{normal}: {full_name}
        {cyan}Description{normal}: {description}
        {cyan}Homepage{normal}: {homepage}
        {cyan}URL{normal}: {url}
        {cyan}Author{normal}: {author}
        {cyan}License{normal}: {license}
        {cyan}Operating Systems{normal}: {os}
        {cyan}Keywords{normal}: {keywords}
        {cyan}Installed{normal}: {installed}
        {cyan}Pkg Directory{normal}: {pkg_dir}
        {cyan}Var Directory{normal}: {var_dir}
        {cyan}Depends on{normal}: {depends}
        {cyan}Required by{normal}: {requires}
        """.format(
            cyan=Color.CYAN,
            normal=Color.NORMAL,
            full_name=package.full_name,
            description=package.description,
            homepage=package.homepage,
            url=package.url,
            author=package.author,
            license=package.license,
            os=tuple(o.name.lower() for o in package.os),
            keywords=package.keywords,
            installed=package.is_installed(),
            pkg_dir=package.dir,
            var_dir=package.vardir,
            depends=tuple(d.full_name for d in package.depends),
            requires=tuple(r.full_name for r in requires),
        )))
    return package, requires
示例#4
0
def remove_package(pearl_env: PearlEnvironment, package: Package,
                   args: Namespace):
    """
    Remove the Pearl package.
    """
    if not package.is_installed():
        raise PackageNotInstalledError(
            '{} package has not been installed.'.format(package))

    messenger.print('{cyan}* {normal}Removing {pkg} package'.format(
        cyan=Color.CYAN,
        normal=Color.NORMAL,
        pkg=package,
    ))

    hook = 'pre_remove'
    try:
        _run(
            hook,
            pearl_env,
            package,
            input=_DEFAULT_INPUT if args.no_confirm else None,
            enable_xtrace=(args.verbose >= 2),
            enable_errexit=(not args.force),
        )
    except Exception as exc:
        msg = "Error while performing {} hook function".format(hook)
        if not args.force:
            raise HookFunctionError(msg) from exc
        message = "{}: {}".format(msg, exc.args)
        if args.verbose:
            messenger.exception(message)
        else:
            messenger.error(message)

    shutil.rmtree(str(package.dir))
示例#5
0
def update_package(pearl_env: PearlEnvironment, package: Package,
                   args: Namespace):
    """
    Updates the Pearl package.
    """
    if not package.is_installed():
        raise PackageNotInstalledError(
            '{} package has not been installed.'.format(package))

    messenger.print('{cyan}* {normal}Updating {pkg} package'.format(
        cyan=Color.CYAN,
        normal=Color.NORMAL,
        pkg=package,
    ))

    if package.has_url_changed():
        messenger.info("The package URL for {} has changed to {}".format(
            package.full_name, package.url))
        messenger.info("Replacing the package with the new repository...")
        remove_package(pearl_env, package, args)
        install_package(pearl_env, package, args)

    hook = 'pre_update'
    try:
        _run(
            hook,
            pearl_env,
            package,
            input=_DEFAULT_INPUT if args.no_confirm else None,
            enable_xtrace=(args.verbose >= 2),
            enable_errexit=(not args.force),
        )
    except Exception as exc:
        msg = "Error while performing {} hook function".format(hook)
        if not args.force:
            raise HookFunctionError(msg) from exc
        message = "{}: {}".format(msg, exc.args)
        if args.verbose:
            messenger.exception(message)
        else:
            messenger.error(message)

    if package.is_local():
        check_and_copy(Path(package.url), package.dir)
    else:
        quiet = "false" if args.verbose else "true"
        script = dedent("""
            update_git_repo {pkgdir} "" {quiet}
            """).format(pkgdir=package.dir, quiet=quiet)
        run_pearl_bash(script,
                       pearl_env,
                       input=_DEFAULT_INPUT if args.no_confirm else None)

    hook = 'post_update'
    try:
        _run(
            hook,
            pearl_env,
            package,
            input=_DEFAULT_INPUT if args.no_confirm else None,
            enable_xtrace=(args.verbose >= 2),
            enable_errexit=(not args.force),
        )
    except Exception as exc:
        msg = "Error while performing {} hook function".format(hook)
        if not args.force:
            raise HookFunctionError(msg) from exc
        message = "{}: {}".format(msg, exc.args)
        if args.verbose:
            messenger.exception(message)
        else:
            messenger.error(message)