summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/ext/spawn.py27
-rw-r--r--ranger/fsobject/fsobject.py5
2 files changed, 29 insertions, 3 deletions
diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py
new file mode 100644
index 00000000..9723c1ed
--- /dev/null
+++ b/ranger/ext/spawn.py
@@ -0,0 +1,27 @@
+# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from subprocess import Popen, PIPE
+ENCODING = 'utf-8'
+
+def spawn(*args):
+	"""Runs a program, waits for its termination and returns its stdout"""
+	if len(args) == 1:
+		popen_arguments = args[0]
+	else:
+		popen_arguments = args
+	process = Popen(popen_arguments, stdout=PIPE)
+	stdout, stderr = process.communicate()
+	return stdout.decode(ENCODING)
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index 3a2f6012..66b726ec 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -24,11 +24,11 @@ import os
 from stat import S_ISLNK, S_ISCHR, S_ISBLK, S_ISSOCK, S_ISFIFO, \
 		S_ISDIR, S_IXUSR
 from time import time
-from subprocess import Popen, PIPE
 from os.path import abspath, basename, dirname, realpath
 from . import BAD_INFO
 from ranger.shared import MimeTypeAware, FileManagerAware
 from ranger.ext.shell_escape import shell_escape
+from ranger.ext.spawn import spawn
 from ranger.ext.human_readable import human_readable
 
 class FileSystemObject(MimeTypeAware, FileManagerAware):
@@ -104,8 +104,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware):
 	def filetype(self):
 		if self._filetype is None:
 			try:
-				got = Popen(["file", '-Lb', '--mime-type', self.path],
-						stdout=PIPE).communicate()[0]
+				got = spawn(["file", '-Lb', '--mime-type', self.path])
 			except OSError:
 				self._filetype = ''
 			else: