| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,3 +3,4 @@ | |||
| 3 | 3 | *~ | |
| 4 | 4 | /lib/GitPython.egg-info | |
| 5 | 5 | /build | |
| 6 | + /dist | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,6 +81,7 @@ def execute(self, command, | |||
| 81 | 81 | with_stderr=False, | |
| 82 | 82 | with_exceptions=False, | |
| 83 | 83 | with_raw_output=False, | |
| 84 | + with_keep_cwd=False, | ||
| 84 | 85 | ): | |
| 85 | 86 | """ | |
| 86 | 87 | Handles executing the command on the shell and consumes and returns | |
@@ -104,6 +105,9 @@ def execute(self, command, | |||
| 104 | 105 | ``with_raw_output`` | |
| 105 | 106 | Whether to avoid stripping off trailing whitespace. | |
| 106 | 107 | ||
| 108 | + ``with_keep_cwd`` | ||
| 109 | + Whether to use the current working directory from os.getcwd(). | ||
| 110 | + | ||
| 107 | 111 | Returns | |
| 108 | 112 | str(output) # with_status = False (Default) | |
| 109 | 113 | tuple(int(status), str(output)) # with_status = True | |
@@ -119,9 +123,15 @@ def execute(self, command, | |||
| 119 | 123 | else: | |
| 120 | 124 | stderr = subprocess.PIPE | |
| 121 | 125 | ||
| 126 | + # Allow the user to have the command executed in their working dir. | ||
| 127 | + if with_keep_cwd: | ||
| 128 | + cwd = os.getcwd() | ||
| 129 | + else: | ||
| 130 | + cwd=self._cwd | ||
| 131 | + | ||
| 122 | 132 | # Start the process | |
| 123 | 133 | proc = subprocess.Popen(command, | |
| 124 | - cwd=self._cwd, | ||
| 134 | + cwd=cwd, | ||
| 125 | 135 | stdin=istream, | |
| 126 | 136 | stderr=stderr, | |
| 127 | 137 | stdout=subprocess.PIPE | |
@@ -132,6 +142,10 @@ def execute(self, command, | |||
| 132 | 142 | status = proc.wait() | |
| 133 | 143 | proc.stdout.close() | |
| 134 | 144 | ||
| 145 | + if proc.stderr: | ||
| 146 | + stderr_value = proc.stderr.read() | ||
| 147 | + proc.stderr.close() | ||
| 148 | + | ||
| 135 | 149 | # Strip off trailing whitespace by default | |
| 136 | 150 | if not with_raw_output: | |
| 137 | 151 | stdout_value = stdout_value.rstrip() | |
@@ -143,7 +157,12 @@ def execute(self, command, | |||
| 143 | 157 | % (str(command), status)) | |
| 144 | 158 | ||
| 145 | 159 | if GIT_PYTHON_TRACE == 'full': | |
| 146 | - print "%s %d: '%s'" % (command, status, stdout_value) | ||
| 160 | + if stderr_value: | ||
| 161 | + print "%s -> %d: '%s' !! '%s'" % (command, status, stdout_value, stderr_value) | ||
| 162 | + elif stdout_value: | ||
| 163 | + print "%s -> %d: '%s'" % (command, status, stdout_value) | ||
| 164 | + else: | ||
| 165 | + print "%s -> %d" % (command, status) | ||
| 147 | 166 | ||
| 148 | 167 | # Allow access to the command's status code | |
| 149 | 168 | if with_status: | |
@@ -199,6 +218,7 @@ def method_missing(self, method, *args, **kwargs): | |||
| 199 | 218 | with_stderr = kwargs.pop("with_stderr", None) | |
| 200 | 219 | with_exceptions = kwargs.pop("with_exceptions", None) | |
| 201 | 220 | with_raw_output = kwargs.pop("with_raw_output", None) | |
| 221 | + with_keep_cwd = kwargs.pop("with_keep_cwd", None) | ||
| 202 | 222 | ||
| 203 | 223 | # Prepare the argument list | |
| 204 | 224 | opt_args = self.transform_kwargs(**kwargs) | |
@@ -214,4 +234,5 @@ def method_missing(self, method, *args, **kwargs): | |||
| 214 | 234 | with_stderr = with_stderr, | |
| 215 | 235 | with_exceptions = with_exceptions, | |
| 216 | 236 | with_raw_output = with_raw_output, | |
| 237 | + with_keep_cwd = with_keep_cwd, | ||
| 217 | 238 | ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments