Пример #1
0
def test_package():
    pkg = Package(Path('/home'), 'repo', 'pkg1', 'https://pkg1', 'pkg1 descr')
    assert pkg.name == 'pkg1'
    assert pkg.repo_name == 'repo'
    assert pkg.full_name == 'repo/pkg1'
    assert pkg.url == 'https://pkg1'
    assert pkg.description == 'pkg1 descr'
    assert pkg.dir == Path('/home/packages/repo/pkg1')
    assert pkg.vardir == Path('/home/var/repo/pkg1')
    assert not pkg.is_local()

    pkg = Package(Path('/home'), 'repo', 'pkg1', '/pkg1', 'pkg1 descr')
    assert pkg.is_local()
Пример #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 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)