mwilliamson / spur.py

Run commands and manipulate files locally or over SSH using the same interface
BSD 2-Clause "Simplified" License
267 stars 37 forks source link

cwd to non existent directory doesn't fail on SshShell #46

Closed beenje closed 8 years ago

beenje commented 8 years ago

Changing to a non existent directory with a local shell raises a FileNotFoundError:

>>> shell = spur.LocalShell() 
>>> shell.run(['mkdir', '-p', 'foo'], cwd='/some/silly/path')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/benjamin/Dev/spur/spur.py/spur/local.py", line 111, in run
    return self.spawn(*args, **kwargs).wait_for_result()
  File "/Users/benjamin/Dev/spur/spur.py/spur/local.py", line 68, in spawn
    **self._subprocess_args(command, *args, **kwargs)
  File "/Users/benjamin/miniconda/envs/spur/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/Users/benjamin/miniconda/envs/spur/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/some/silly/path'

But it doesn't with a SshShell. The command is executed anyway:

>>> ssh_shell = spur.SshShell(hostname="localhost", username="bob", password="password1")
>>> r = ssh_shell.run(['mkdir', '-p', 'foo'], cwd='/some/silly/path')
>>> r.return_code
0
>>> r = ssh_shell.run(['ls', '-ld', 'foo'])
>>> r.output
b'drwxr-xr-x 2 pi pi 4096 Aug  2 20:36 foo\n'

In this case, the directory is created in the home directory of the remote user. The command should not be executed.

mwilliamson commented 8 years ago

Thanks for the report. I suspect this is because we're issuing a cd command without checking whether it fails or not. Patches welcome!

beenje commented 8 years ago

Sure. Will try to send a pull request!