[Python-modules-commits] [python-spur] 03/13: LocalShell: don't raise NoSuchComandError when cwd does not exist

Ruben Undheim rubund-guest at moszumanska.debian.org
Sun Jan 3 10:38:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

rubund-guest pushed a commit to branch master
in repository python-spur.

commit 91bd4177f9e9d32923704f7f645434e5d9d39cc9
Author: Michael Williamson <mike at zwobble.org>
Date:   Sun Dec 27 18:15:50 2015 +0000

    LocalShell: don't raise NoSuchComandError when cwd does not exist
---
 CHANGES                   |  4 ++++
 spur/local.py             | 25 +++++++++++++++++++++----
 tests/process_test_set.py | 11 +++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/CHANGES b/CHANGES
index f91a447..1b7b2be 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
 # CHANGES
 
+## 0.3.15
+
+* LocalShell: don't raise NoSuchComandError when cwd does not exist.
+
 ## 0.3.14
 
 * Raise spur.CommandInitializationError when SshShell fails to read integers
diff --git a/spur/local.py b/spur/local.py
index bb078fa..a4045e1 100644
--- a/spur/local.py
+++ b/spur/local.py
@@ -1,8 +1,10 @@
 import os
+import sys
 import subprocess
 import shutil
 io = __import__("io")
 import threading
+import errno
 
 try:
     import pty
@@ -62,8 +64,11 @@ class LocalShell(object):
                 bufsize=0,
                 **self._subprocess_args(command, *args, **kwargs)
             )
-        except OSError:
-            raise NoSuchCommandError(command[0])
+        except OSError as error:
+            if self._is_no_such_command_oserror(error, command[0]):
+                raise NoSuchCommandError(command[0])
+            else:
+                raise
             
         if use_pty:
             # TODO: Should close master ourselves rather than relying on
@@ -97,7 +102,7 @@ class LocalShell(object):
         if store_pid:
             spur_process.pid = process.pid
         return spur_process
-        
+    
     def run(self, *args, **kwargs):
         return self.spawn(*args, **kwargs).wait_for_result()
         
@@ -120,7 +125,19 @@ class LocalShell(object):
         if new_process_group:
             kwargs["preexec_fn"] = os.setpgrp
         return kwargs
-        
+    
+    def _is_no_such_command_oserror(self, error, command):
+        if error.errno != errno.ENOENT:
+            return False
+        if sys.version_info[0] < 3:
+            return error.filename is None
+        else:
+            # In Python 3, filename and filename2 are None both when
+            # the command and cwd don't exist, but in both cases,
+            # the repr of the non-existent path is appended to the
+            # error message
+            return error.args[1] == os.strerror(error.errno) + ": " + repr(command)
+            
 
 class LocalProcess(object):
     def __init__(self, subprocess, allow_error, process_stdin, process_stdout, process_stderr, stdout, stderr):
diff --git a/tests/process_test_set.py b/tests/process_test_set.py
index fbe3a95..56bed8c 100644
--- a/tests/process_test_set.py
+++ b/tests/process_test_set.py
@@ -201,6 +201,17 @@ class ProcessTestSet(object):
             )
             assert_equal(expected_message, error.args[0])
             assert_equal("i-am-not-a-command", error.command)
+        
+        
+    @test
+    def using_non_existent_cwd_does_not_raise_no_such_command_error(shell):
+        cwd = "/some/path/that/hopefully/doesnt/exists/ljaslkfjaslkfjas"
+        try:
+            shell.spawn(["echo", "1"], cwd=cwd)
+            # Expected exception
+            assert False
+        except Exception as error:
+            assert not isinstance(error, spur.NoSuchCommandError)
 
 
     @test

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-spur.git



More information about the Python-modules-commits mailing list