diff options
author | nfnty <git@nfnty.se> | 2015-12-22 18:38:34 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2016-02-08 04:43:04 +0100 |
commit | 12fdaa9e4b205e683fc5a8681f5be12c8c825843 (patch) | |
tree | b1b8ec74aac34bcd6821dfd67ff02a4637eae990 /ranger | |
parent | 3fe88d2be06920e5a477963f6c5816e8d2a6f19c (diff) | |
download | ranger-12fdaa9e4b205e683fc5a8681f5be12c8c825843.tar.gz |
VCS: Fix python2 compatibility
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/ext/vcs/vcs.py | 23 |
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""" |