1
0
Fork 0

Fix running commands with directories; also fix editing

master
LEdoian 4 years ago
parent 7c02d2c1da
commit f6497245b9

@ -128,7 +128,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile: with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
# Fill the file with data # Fill the file with data
for cmd in hunk: for cmd in hunk:
tmpfile.file.write(f"{cmd.user}\t{cmd.directory}\t{cmd.command}\n") tmpfile.file.write(f"{cmd.user}\t{cmd.directory if cmd.directory else ''}\t{cmd.command}\n")
tmpfile.file.flush() # Should not be needed, but better safe than sorry tmpfile.file.flush() # Should not be needed, but better safe than sorry
# Let the user edit the file # Let the user edit the file
import os import os
@ -146,9 +146,11 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
if line == '': if line == '':
continue continue
parts = line.split('\t', maxsplit=2) parts = line.split('\t', maxsplit=2)
# Change directory to None if it is not specified
parts[1] = parts[1].strip() if parts[1].strip() != '' else None
new_hunk.append(Command(user=parts[0],directory=parts[1],command=parts[2],context=None)) new_hunk.append(Command(user=parts[0],directory=parts[1],command=parts[2],context=None))
# Python has no goto for restarting, but we can recurse # Python has no goto for restarting, but we can recurse
return user_action(new_hunk, context) return user_action(new_hunk, context)
elif answer.startswith(('y', 'Y')): elif answer.startswith(('y', 'Y')):
return hunk return hunk
elif answer.startswith(('n', 'N')): elif answer.startswith(('n', 'N')):
@ -160,11 +162,12 @@ def run_command(cmd: Command):
# Generate and run the SSH command. # Generate and run the SSH command.
global host global host
local_command = ['ssh', host] local_command = ['ssh', host]
remote_command = cmd.command
if cmd.user is not None: if cmd.user is not None:
local_command.extend(['-l', cmd.user]) local_command.extend(['-l', cmd.user])
if cmd.directory is not None: if cmd.directory is not None:
cmd.command += f'cd {cmd.directory}; {cmd.command}' remote_command = f'cd {cmd.directory}; {remote_command}'
local_command.append(cmd.command) local_command.append(remote_command)
# Run # Run
import subprocess import subprocess

Loading…
Cancel
Save