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,12 +80,11 @@ 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) |  | ||||||
|  |  | ||||||
|  |     with logs.debug_time(u'Call: {}; with env: {};'.format(script, env), | ||||||
|  |                          settings): | ||||||
|         result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env) |         result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env) | ||||||
|         if wait_output(settings, result): |         if wait_output(settings, result): | ||||||
|             return types.Command(script, result.stdout.read().decode('utf-8'), |             return types.Command(script, result.stdout.read().decode('utf-8'), | ||||||
| @@ -96,7 +95,8 @@ 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), | ||||||
|  |                                  settings): | ||||||
|                 if rule.match(command, settings): |                 if rule.match(command, settings): | ||||||
|                     return rule |                     return rule | ||||||
|         except Exception: |         except Exception: | ||||||
| @@ -134,6 +134,7 @@ 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) | ||||||
|  |     with logs.debug_time('Total', settings): | ||||||
|         logs.debug(u'Run with settings: {}'.format(pformat(settings)), settings) |         logs.debug(u'Run with settings: {}'.format(pformat(settings)), settings) | ||||||
|  |  | ||||||
|         command = get_command(settings, sys.argv) |         command = get_command(settings, sys.argv) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user