示例#1
0
def pikaur(cmd: str,
           capture_stdout=True,
           capture_stderr=False,
           fake_makepkg=False) -> CmdResult:

    PackageDB.discard_local_cache()

    new_args = ['pikaur'] + cmd.split(' ')
    if '-S ' in cmd:
        new_args += [
            '--noconfirm',
            '--hide-build-log',
        ]
    if fake_makepkg:
        new_args += [
            '--makepkg-path=' + os.path.join(TEST_DIR, 'fake_makepkg')
        ]
        if '--mflags' not in cmd:
            new_args += [
                '--mflags=--noextract',
            ]

    print(color_line('\n => ', 10, force=True) + ' '.join(new_args))

    intercepted: InterceptSysOutput
    with InterceptSysOutput(capture_stderr=capture_stderr,
                            capture_stdout=capture_stdout) as _intercepted:
        try:

            # re-parse args:
            sys.argv = new_args
            CachedArgs.args = None  # pylint:disable=protected-access
            MakePkgCommand._cmd = None  # pylint:disable=protected-access
            parse_args()
            # monkey-patch to force always uncolored output:
            CachedArgs.args.color = 'never'  # type: ignore # pylint:disable=protected-access

            # finally run pikaur's mainloop
            main()

        except FakeExit:
            pass
        intercepted = _intercepted

    PackageDB.discard_local_cache()
    PackageDB.discard_repo_cache()

    return CmdResult(
        returncode=intercepted.returncode,
        stdout=intercepted.stdout_text,
        stderr=intercepted.stderr_text,
    )
示例#2
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
""" This file is licensed under GPLv3, see https://www.gnu.org/licenses/ """

from pikaur.main import main


if __name__ == '__main__':
    main()
示例#3
0
def pikaur(cmd: str,
           capture_stdout=True,
           capture_stderr=False,
           fake_makepkg=False,
           skippgpcheck=False) -> CmdResult:

    PackageDB.discard_local_cache()

    new_args = ['pikaur'] + cmd.split(' ')
    mflags = []

    if '-S ' in cmd:
        new_args += [
            '--noconfirm',
        ]
    if fake_makepkg:
        new_args += [
            '--makepkg-path=' + os.path.join(TEST_DIR, 'fake_makepkg')
        ]
        mflags.append('--noextract')
    if skippgpcheck:
        mflags.append('--skippgpcheck')
    if '--mflags' in cmd:
        for arg in new_args[::]:
            if arg.startswith('--mflags'):
                for mflag in arg.split('=', maxsplit=1)[1].split(','):
                    mflags.append(mflag)
                new_args.remove(arg)
                break
    if mflags:
        new_args += [
            f"--mflags={','.join(mflags)}",
        ]

    print(color_line('\n => ', 10, force=True) + ' '.join(new_args))

    intercepted: InterceptSysOutput
    with InterceptSysOutput(capture_stderr=capture_stderr,
                            capture_stdout=capture_stdout) as _intercepted:
        try:

            # re-parse args:
            sys.argv = new_args
            CachedArgs.args = None
            MakePkgCommand._cmd = None  # pylint: disable=protected-access
            parse_args()
            # monkey-patch to force always uncolored output:
            CachedArgs.args.color = 'never'  # type: ignore

            # finally run pikaur's mainloop
            main()

        except FakeExit:
            pass
        intercepted = _intercepted

    PackageDB.discard_local_cache()
    PackageDB.discard_repo_cache()

    return CmdResult(
        returncode=intercepted.returncode,
        stdout=intercepted.stdout_text,
        stderr=intercepted.stderr_text,
    )