1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 02:41:10 +01:00

#165 fix python 2 support

This commit is contained in:
nvbn 2015-05-06 13:17:14 +02:00
parent 608d48e408
commit 5864faadef
3 changed files with 9 additions and 7 deletions

View File

@ -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

View File

@ -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')

View File

@ -4,6 +4,9 @@ import six
from .types import Command
DEVNULL = open(os.devnull, 'w')
def which(program):
"""Returns `program` path or `None`."""