summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2015-12-22 18:38:34 +0100
committernfnty <git@nfnty.se>2016-02-08 04:43:04 +0100
commit12fdaa9e4b205e683fc5a8681f5be12c8c825843 (patch)
treeb1b8ec74aac34bcd6821dfd67ff02a4637eae990 /ranger
parent3fe88d2be06920e5a477963f6c5816e8d2a6f19c (diff)
downloadranger-12fdaa9e4b205e683fc5a8681f5be12c8c825843.tar.gz
VCS: Fix python2 compatibility
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/vcs/vcs.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index 2552d955..6e207b09 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -7,6 +7,10 @@ import os
 import subprocess
 import threading
 import time
+try:
+    FileNotFoundError
+except NameError:
+    FileNotFoundError = OSError
 
 class VcsError(Exception):
     """VCS exception"""
@@ -108,16 +112,15 @@ class Vcs(object):
 
     def _vcs(self, cmd, path, catchout=True, retbytes=False):
         """Run a VCS command"""
-        try:
-            if catchout:
-                output = subprocess.check_output(cmd, cwd=path,
-                                                 stderr=subprocess.DEVNULL)
-                return output if retbytes else output.decode('UTF-8')
-            else:
-                subprocess.check_call(cmd, cwd=path,
-                                      stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
-        except (subprocess.CalledProcessError, FileNotFoundError):
-            raise VcsError('{0:s}: {1:s}'.format(str(cmd), path))
+        with open(os.devnull, 'w') as devnull:
+            try:
+                if catchout:
+                    output = subprocess.check_output(cmd, cwd=path, stderr=devnull)
+                    return output if retbytes else output.decode('UTF-8')
+                else:
+                    subprocess.check_call(cmd, cwd=path, stdout=devnull, stderr=devnull)
+            except (subprocess.CalledProcessError, FileNotFoundError):
+                raise VcsError('{0:s}: {1:s}'.format(str(cmd), path))
 
     def _get_repotype(self, path):
         """Get type for path"""
f='#n198'>198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275