From 5864faadeff34bad0b2b15d904802707dd68fbfd Mon Sep 17 00:00:00 2001 From: nvbn Date: Wed, 6 May 2015 13:17:14 +0200 Subject: [PATCH] #165 fix python 2 support --- thefuck/rules/pacman.py | 5 +++-- thefuck/shells.py | 8 +++----- thefuck/utils.py | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/thefuck/rules/pacman.py b/thefuck/rules/pacman.py index f709895..4115798 100644 --- a/thefuck/rules/pacman.py +++ b/thefuck/rules/pacman.py @@ -1,14 +1,15 @@ import subprocess +from thefuck.utils import DEVNULL def __command_available(command): try: - subprocess.check_output([command], stderr=subprocess.DEVNULL) + subprocess.check_output([command], stderr=DEVNULL) return True except subprocess.CalledProcessError: # command exists but is not happy to be called without any argument return True - except FileNotFoundError: + except OSError: return False diff --git a/thefuck/shells.py b/thefuck/shells.py index c0bb089..1d128cd 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -8,9 +8,7 @@ from subprocess import Popen, PIPE from time import time import os from psutil import Process - - -FNULL = open(os.devnull, 'w') +from .utils import DEVNULL class Generic(object): @@ -58,7 +56,7 @@ class Bash(Generic): return name, value def _get_aliases(self): - proc = Popen('bash -ic alias', stdout=PIPE, stderr=FNULL, shell=True) + proc = Popen('bash -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True) return dict( self._parse_alias(alias) for alias in proc.stdout.read().decode('utf-8').split('\n') @@ -80,7 +78,7 @@ class Zsh(Generic): return name, value def _get_aliases(self): - proc = Popen('zsh -ic alias', stdout=PIPE, stderr=FNULL, shell=True) + proc = Popen('zsh -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True) return dict( self._parse_alias(alias) for alias in proc.stdout.read().decode('utf-8').split('\n') diff --git a/thefuck/utils.py b/thefuck/utils.py index 7ee66c2..3247111 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -4,6 +4,9 @@ import six from .types import Command +DEVNULL = open(os.devnull, 'w') + + def which(program): """Returns `program` path or `None`."""