1
0
Fork 0

Fix a few things

Good commit message, I know
master
LEdoian 5 years ago
parent ed3cf574a8
commit 472dbda98a

@ -77,7 +77,7 @@ def parse_snippet(s: Tuple[str, str]) -> Sequence[Command]:
parts = line.split(maxsplit=5)
assert parts[3] == '-H', "Insecure sudo?"
user = parts[2]
directory = f'~{user}' # This actually works with SSH. That is nice, since we don't need to know the mapping of
directory = f'~{user}' # This actually works with SSH. That is nice, since we don't need to know the target's /etc/passwd
cmd = parts[4]
elif line.startswith('sudo'):
parts = line.split(maxsplit=2)
@ -112,6 +112,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
for cmd in hunk:
global host
result += f'SSH: {cmd.user}@{host} {cmd.directory} $ {cmd.command}\n'
return result
# TODO: Print context in color (gray?)
@ -124,7 +125,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
answer = input("What to do: edit(e), run(y), skip(n)?")
if answer.startswith(('e', 'E')):
import tempfile
with tempfile.NamedTemporaryFile() as tmpfile:
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
# Fill the file with data
for cmd in hunk:
tmpfile.file.write(f"{cmd.user}\t{cmd.directory}\t{cmd.command}\n")
@ -180,7 +181,7 @@ def process_file(fn: str):
snippets = extract_snippets(pd)
for snip in snippets:
cmds = parse_snippet(snip)
cmds = user_action(cmds)
cmds = user_action(cmds, context=cmds[0].context)
for cmd in cmds:
run_command(cmd)

Loading…
Cancel
Save