mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	#N/A Log common operations time
This commit is contained in:
		| @@ -1,4 +1,5 @@ | |||||||
| from pprint import pformat | from contextlib import contextmanager | ||||||
|  | from datetime import datetime | ||||||
| import sys | import sys | ||||||
| from traceback import format_exception | from traceback import format_exception | ||||||
| import colorama | import colorama | ||||||
| @@ -62,3 +63,12 @@ def debug(msg, settings): | |||||||
|             reset=color(colorama.Style.RESET_ALL, settings), |             reset=color(colorama.Style.RESET_ALL, settings), | ||||||
|             blue=color(colorama.Fore.BLUE, settings), |             blue=color(colorama.Fore.BLUE, settings), | ||||||
|             bold=color(colorama.Style.BRIGHT, settings))) |             bold=color(colorama.Style.BRIGHT, settings))) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @contextmanager | ||||||
|  | def debug_time(msg, settings): | ||||||
|  |     started = datetime.now() | ||||||
|  |     try: | ||||||
|  |         yield | ||||||
|  |     finally: | ||||||
|  |         debug('{} took: {}'.format(msg, datetime.now() - started), settings) | ||||||
|   | |||||||
| @@ -80,25 +80,25 @@ def get_command(settings, args): | |||||||
|         return |         return | ||||||
|  |  | ||||||
|     script = shells.from_shell(script) |     script = shells.from_shell(script) | ||||||
|     logs.debug(u'Call: {}'.format(script), settings) |  | ||||||
|  |  | ||||||
|     env = dict(os.environ) |     env = dict(os.environ) | ||||||
|     env.update(settings.env) |     env.update(settings.env) | ||||||
|     logs.debug(u'Executing with env: {}'.format(env), settings) |  | ||||||
|  |  | ||||||
|     result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env) |     with logs.debug_time(u'Call: {}; with env: {};'.format(script, env), | ||||||
|     if wait_output(settings, result): |                          settings): | ||||||
|         return types.Command(script, result.stdout.read().decode('utf-8'), |         result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env) | ||||||
|                              result.stderr.read().decode('utf-8')) |         if wait_output(settings, result): | ||||||
|  |             return types.Command(script, result.stdout.read().decode('utf-8'), | ||||||
|  |                                  result.stderr.read().decode('utf-8')) | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_matched_rule(command, rules, settings): | def get_matched_rule(command, rules, settings): | ||||||
|     """Returns first matched rule for command.""" |     """Returns first matched rule for command.""" | ||||||
|     for rule in rules: |     for rule in rules: | ||||||
|         try: |         try: | ||||||
|             logs.debug(u'Trying rule: {}'.format(rule.name), settings) |             with logs.debug_time(u'Trying rule: {};'.format(rule.name), | ||||||
|             if rule.match(command, settings): |                                  settings): | ||||||
|                 return rule |                 if rule.match(command, settings): | ||||||
|  |                     return rule | ||||||
|         except Exception: |         except Exception: | ||||||
|             logs.rule_failed(rule, sys.exc_info(), settings) |             logs.rule_failed(rule, sys.exc_info(), settings) | ||||||
|  |  | ||||||
| @@ -134,25 +134,26 @@ def main(): | |||||||
|     colorama.init() |     colorama.init() | ||||||
|     user_dir = setup_user_dir() |     user_dir = setup_user_dir() | ||||||
|     settings = conf.get_settings(user_dir) |     settings = conf.get_settings(user_dir) | ||||||
|     logs.debug(u'Run with settings: {}'.format(pformat(settings)), settings) |     with logs.debug_time('Total', settings): | ||||||
|  |         logs.debug(u'Run with settings: {}'.format(pformat(settings)), settings) | ||||||
|  |  | ||||||
|     command = get_command(settings, sys.argv) |         command = get_command(settings, sys.argv) | ||||||
|     if command: |         if command: | ||||||
|         logs.debug(u'Received stdout: {}'.format(command.stdout), settings) |             logs.debug(u'Received stdout: {}'.format(command.stdout), settings) | ||||||
|         logs.debug(u'Received stderr: {}'.format(command.stderr), settings) |             logs.debug(u'Received stderr: {}'.format(command.stderr), settings) | ||||||
|  |  | ||||||
|         rules = get_rules(user_dir, settings) |             rules = get_rules(user_dir, settings) | ||||||
|         logs.debug( |             logs.debug( | ||||||
|             u'Loaded rules: {}'.format(', '.join(rule.name for rule in rules)), |                 u'Loaded rules: {}'.format(', '.join(rule.name for rule in rules)), | ||||||
|             settings) |                 settings) | ||||||
|  |  | ||||||
|         matched_rule = get_matched_rule(command, rules, settings) |             matched_rule = get_matched_rule(command, rules, settings) | ||||||
|         if matched_rule: |             if matched_rule: | ||||||
|             logs.debug(u'Matched rule: {}'.format(matched_rule.name), settings) |                 logs.debug(u'Matched rule: {}'.format(matched_rule.name), settings) | ||||||
|             run_rule(matched_rule, command, settings) |                 run_rule(matched_rule, command, settings) | ||||||
|             return |                 return | ||||||
|  |  | ||||||
|     logs.failed('No fuck given', settings) |         logs.failed('No fuck given', settings) | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_alias(): | def print_alias(): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user