From e55423899613ce62c530774dd02b6ef8d0d50202 Mon Sep 17 00:00:00 2001 From: nvbn Date: Fri, 24 Apr 2015 05:22:19 +0200 Subject: [PATCH] #78 Disable when can't import `CommandNotFound` --- thefuck/rules/apt_get.py | 43 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/thefuck/rules/apt_get.py b/thefuck/rules/apt_get.py index 0e7af59e..4d5eca6b 100644 --- a/thefuck/rules/apt_get.py +++ b/thefuck/rules/apt_get.py @@ -1,28 +1,23 @@ -import sys +try: + import CommandNotFound +except ImportError: + enabled_by_default = False + def match(command, settings): - try: - import CommandNotFound - if 'not found' in command.stderr: - try: - c = CommandNotFound.CommandNotFound() - pkgs = c.getPackages(command.script.split(" ")[0]) - name,_ = pkgs[0] - return True - except IndexError: - # IndexError is thrown when no matching package is found - return False - except: - return False + if 'not found' in command.stderr: + try: + c = CommandNotFound.CommandNotFound() + pkgs = c.getPackages(command.script.split(" ")[0]) + name, _ = pkgs[0] + return True + except IndexError: + # IndexError is thrown when no matching package is found + return False + def get_new_command(command, settings): - try: - import CommandNotFound - c = CommandNotFound.CommandNotFound() - if 'not found' in command.stderr: - pkgs = c.getPackages(command.script.split(" ")[0]) - name,_ = pkgs[0] - return "sudo apt-get install %s" % name - except: - sys.stderr.write("Can't apt fuck\n") - return "" + c = CommandNotFound.CommandNotFound() + pkgs = c.getPackages(command.script.split(" ")[0]) + name, _ = pkgs[0] + return "sudo apt-get install {} && {}".format(name, command.script)