How to use the jishaku.shell.ShellReader function in jishaku

To help you get started, we’ve selected a few jishaku examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Gorialis / jishaku / tests / test_shell.py View on Github external
async def test_reader_basic():
    return_data = []

    with ShellReader("echo hi") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 1
    assert return_data[0] == "hi"

    with pytest.raises(asyncio.TimeoutError):
        with ShellReader("sleep 2", timeout=1) as reader:
            async for result in reader:
                pass
github Gorialis / jishaku / tests / test_shell.py View on Github external
async def test_reader_basic():
    return_data = []

    with ShellReader("echo hi") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 1
    assert return_data[0] == "hi"

    with pytest.raises(asyncio.TimeoutError):
        with ShellReader("sleep 2", timeout=1) as reader:
            async for result in reader:
                pass
github Gorialis / jishaku / tests / test_shell.py View on Github external
async def test_linux():
    return_data = []

    with ShellReader(">&2 echo oops") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 1
    assert return_data[0] == "[stderr] oops"

    return_data = []

    with ShellReader("echo one && echo two") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 2
    assert return_data[0] == "one"
    assert return_data[1] == "two"
github Gorialis / jishaku / tests / test_shell.py View on Github external
async def test_windows():
    return_data = []

    with ShellReader("cmd /c \"echo one && echo two && echo three 1>&2\"") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 3
    return_data = [x.strip() for x in return_data]

    assert "one" in return_data
    assert "two" in return_data
    assert "[stderr] three" in return_data
github Gorialis / jishaku / tests / test_shell.py View on Github external
async def test_linux():
    return_data = []

    with ShellReader(">&2 echo oops") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 1
    assert return_data[0] == "[stderr] oops"

    return_data = []

    with ShellReader("echo one && echo two") as reader:
        async for result in reader:
            return_data.append(result)

    assert len(return_data) == 2
    assert return_data[0] == "one"
    assert return_data[1] == "two"
github Gorialis / jishaku / jishaku / cog_base.py View on Github external
"""
        Executes statements in the system shell.

        This uses the system shell as defined in $SHELL, or `/bin/bash` otherwise.
        Execution can be cancelled by closing the paginator.
        """

        async with ReplResponseReactor(ctx.message):
            with self.submit(ctx):
                paginator = WrappedPaginator(prefix="```sh", max_size=1985)
                paginator.add_line(f"$ {argument.content}\n")

                interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
                self.bot.loop.create_task(interface.send_to(ctx))

                with ShellReader(argument.content) as reader:
                    async for line in reader:
                        if interface.closed:
                            return
                        await interface.add_line(line)

                await interface.add_line(f"\n[status] Return code {reader.close_code}")
github techwithtim / Discord-Bot / cogs / debugging.py View on Github external
if pull_push == "push":
            shellcmd = f'sudo git add .&&sudo git commit -m "{message}"&&sudo git push'
        elif pull_push == "pull":
            shellcmd = 'sudo git pull'
        else:
            return await ctx.send("Invalid option given")

        async with ReplResponseReactor(ctx.message):
            paginator = WrappedPaginator(prefix="```sh", max_size=1985)
            paginator.add_line(f"$ git {pull_push}\n")

            interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
            self.bot.loop.create_task(interface.send_to(ctx))

            with ShellReader(shellcmd) as reader:
                async for line in reader:
                    if interface.closed:
                        return
                    await interface.add_line(line)