summary refs log tree commit diff stats
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
parent3fe88d2be06920e5a477963f6c5816e8d2a6f19c (diff)
downloadranger-12fdaa9e4b205e683fc5a8681f5be12c8c825843.tar.gz
VCS: Fix python2 compatibility
-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"""