Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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"
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
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"
"""
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}")
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)