From 12fdaa9e4b205e683fc5a8681f5be12c8c825843 Mon Sep 17 00:00:00 2001 From: nfnty Date: Tue, 22 Dec 2015 18:38:34 +0100 Subject: VCS: Fix python2 compatibility --- ranger/ext/vcs/vcs.py | 23 +++++++++++++---------- 1 file 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""" -- cgit 1.4.1-2-gfad0