Improve brew* rules import time

This commit is contained in:
mcarton
2015-08-26 19:46:23 +02:00
parent 2b750bac8b
commit b0702d309f
5 changed files with 56 additions and 59 deletions
+18 -18
View File
@@ -1,38 +1,38 @@
import os
import re
from subprocess import check_output
from thefuck.utils import get_closest, replace_argument
from thefuck.utils import get_closest, replace_argument, which
from thefuck.specific.brew import get_brew_path_prefix
# Formulars are base on each local system's status
brew_formulas = []
try:
brew_path_prefix = check_output(['brew', '--prefix'],
universal_newlines=True).strip()
brew_formula_path = brew_path_prefix + '/Library/Formula'
enabled_by_default = bool(which('brew'))
for file_name in os.listdir(brew_formula_path):
if file_name.endswith('.rb'):
brew_formulas.append(file_name.replace('.rb', ''))
except:
pass
def _get_formulas():
# Formulas are based on each local system's status
try:
brew_path_prefix = get_brew_path_prefix()
brew_formula_path = brew_path_prefix + '/Library/Formula'
for file_name in os.listdir(brew_formula_path):
if file_name.endswith('.rb'):
yield file_name[:-3]
except:
pass
def _get_similar_formula(formula_name):
return get_closest(formula_name, brew_formulas, 1, 0.85)
return get_closest(formula_name, _get_formulas(), 1, 0.85)
def match(command, settings):
is_proper_command = ('brew install' in command.script and
'No available formula' in command.stderr)
has_possible_formulas = False
if is_proper_command:
formula = re.findall(r'Error: No available formula for ([a-z]+)',
command.stderr)[0]
has_possible_formulas = bool(_get_similar_formula(formula))
return has_possible_formulas
return bool(_get_similar_formula(formula))
return False
def get_new_command(command, settings):