mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 01:28:56 +00:00
parent
fb069b74d7
commit
f0adfaf936
@ -1,8 +1,17 @@
|
|||||||
|
import six
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
# FileNotFoundError is only available since Python 3.3
|
||||||
|
if six.PY2:
|
||||||
|
FileNotFoundError = OSError
|
||||||
|
|
||||||
|
|
||||||
def __command_available(command):
|
def __command_available(command):
|
||||||
try:
|
try:
|
||||||
|
# subprocess.DEVNULL is only available since Python 3.3
|
||||||
|
if six.PY2:
|
||||||
|
import os
|
||||||
|
subprocess.DEVNULL = open(os.devnull, 'w')
|
||||||
subprocess.check_output([command], stderr=subprocess.DEVNULL)
|
subprocess.check_output([command], stderr=subprocess.DEVNULL)
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
@ -10,16 +19,28 @@ def __command_available(command):
|
|||||||
return True
|
return True
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return False
|
return False
|
||||||
|
finally:
|
||||||
|
# The open file has to be closed
|
||||||
|
if six.PY2:
|
||||||
|
subprocess.DEVNULL.close()
|
||||||
|
|
||||||
|
|
||||||
def __get_pkgfile(command):
|
def __get_pkgfile(command):
|
||||||
try:
|
try:
|
||||||
|
# subprocess.DEVNULL is only available since Python 3.3
|
||||||
|
if six.PY2:
|
||||||
|
import os
|
||||||
|
subprocess.DEVNULL = open(os.devnull, 'w')
|
||||||
return subprocess.check_output(
|
return subprocess.check_output(
|
||||||
['pkgfile', '-b', '-v', command.script.split(" ")[0]],
|
['pkgfile', '-b', '-v', command.script.split(" ")[0]],
|
||||||
universal_newlines=True, stderr=subprocess.DEVNULL
|
universal_newlines=True, stderr=subprocess.DEVNULL
|
||||||
).split()
|
).split()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
finally:
|
||||||
|
# The open file has to be closed
|
||||||
|
if six.PY2:
|
||||||
|
subprocess.DEVNULL.close()
|
||||||
|
|
||||||
|
|
||||||
def match(command, settings):
|
def match(command, settings):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user