From 21312c3dc2721a5116b1d3d27255084390346ec5 Mon Sep 17 00:00:00 2001 From: Richard Boß Date: Mon, 24 Oct 2016 22:26:38 +0200 Subject: fix issue #695: FileInfo Linemode crashes Ranger on Python 2.6 - replaced calls to subprocess.check_output by code downported from Python 2.7 --- ranger/core/linemode.py | 11 +++++++++-- ranger/ext/vcs/vcs.py | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index 96557515..ca9fb86a 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -97,9 +97,16 @@ class FileInfoLinemode(LinemodeBase): def infostring(self, file, metadata): if not file.is_directory: - from subprocess import check_output, CalledProcessError + from subprocess import Popen, PIPE, CalledProcessError try: - fileinfo = check_output(["file", "-bL", file.path]).strip() + process = Popen(stdout=PIPE, "file", "-bL", file.path) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + error = subprocess.CalledProcessError(retcode, "file") + error.output = output + raise error + fileinfo = output.strip() except CalledProcessError: return "unknown" if sys.version_info[0] >= 3: diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index 9c7be653..ed7838f7 100644 --- a/ranger/ext/vcs/vcs.py +++ b/ranger/ext/vcs/vcs.py @@ -119,7 +119,13 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes with open(os.devnull, 'w') as devnull: try: if catchout: - output = subprocess.check_output(cmd, cwd=path, stderr=devnull) + process = subprocess.Popen(stdout=subprocess.PIPE, cmd, cwd=path, stderr=devnull) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + error = subprocess.CalledProcessError(retcode, cmd) + error.output = output + raise error if retbytes: return output else: -- cgit 1.4.1-2-gfad0