From 472dbda98ae38ec5fd64ca7a2696aa4aca21535d Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Mon, 4 May 2020 19:00:59 +0200 Subject: [PATCH] Fix a few things Good commit message, I know --- markdownrunner.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/markdownrunner.py b/markdownrunner.py index 048f441..8f040ee 100755 --- a/markdownrunner.py +++ b/markdownrunner.py @@ -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)