| Conditions | 7 | 
| Total Lines | 86 | 
| Lines | 0 | 
| Ratio | 0 % | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import os | ||
| 16 | def run_coala(log_printer=None, | ||
| 17 | print_results=do_nothing, | ||
| 18 | acquire_settings=fail_acquire_settings, | ||
| 19 | print_section_beginning=do_nothing, | ||
| 20 | nothing_done=do_nothing, | ||
| 21 | autoapply=True): | ||
| 22 | """ | ||
| 23 | This is a main method that should be usable for almost all purposes and | ||
| 24 | reduces executing coala to one function call. | ||
| 25 | |||
| 26 | :param log_printer: A LogPrinter object to use for logging. | ||
| 27 | :param print_results: A callback that takes a LogPrinter, a | ||
| 28 | section, a list of results to be printed, | ||
| 29 | the file dict and the mutable file diff | ||
| 30 | dict. | ||
| 31 | :param acquire_settings: The method to use for requesting settings. | ||
| 32 | It will get a parameter which is a | ||
| 33 | dictionary with the settings name as key | ||
| 34 | and a list containing a description in [0] | ||
| 35 | and the names of the bears who need this | ||
| 36 | setting in all following indexes. | ||
| 37 | :param print_section_beginning: A callback that will be called with a | ||
| 38 | section name string whenever analysis of a | ||
| 39 | new section is started. | ||
| 40 | :param nothing_done: A callback that will be called with only a | ||
| 41 | log printer that shall indicate that | ||
| 42 | nothing was done. | ||
| 43 | :param autoapply: Set to False to autoapply nothing by | ||
| 44 | default; this is overridable via any | ||
| 45 | configuration file/CLI. | ||
| 46 | :return: A dictionary containing a list of results | ||
| 47 | for all analyzed sections as key. | ||
| 48 | """ | ||
| 49 | log_printer = log_printer or LogPrinter(ConsolePrinter()) | ||
| 50 | |||
| 51 | exitcode = 0 | ||
| 52 | results = None | ||
| 53 | try: | ||
| 54 | yielded_results = yielded_unfixed_results = False | ||
| 55 | did_nothing = True | ||
| 56 | sections, local_bears, global_bears, targets = gather_configuration( | ||
| 57 | acquire_settings, | ||
| 58 | log_printer, | ||
| 59 | autoapply=autoapply) | ||
| 60 | |||
| 61 |         tag = str(sections['default'].get('tag', None)) | ||
| 62 |         dtag = str(sections['default'].get('dtag', None)) | ||
| 63 |         config_file = os.path.abspath(str(sections["default"].get("config"))) | ||
| 64 | |||
| 65 | # Deleting all .orig files, so the latest files are up to date! | ||
| 66 | coala_delete_orig.main(log_printer, sections["default"]) | ||
| 67 | |||
| 68 | delete_tagged_results(dtag, config_file, log_printer) | ||
| 69 | |||
| 70 |         results = {} | ||
| 71 | for section_name, section in sections.items(): | ||
| 72 | if not section.is_enabled(targets): | ||
| 73 | continue | ||
| 74 | |||
| 75 | print_section_beginning(section) | ||
| 76 | section_result = execute_section( | ||
| 77 | section=section, | ||
| 78 | global_bear_list=global_bears[section_name], | ||
| 79 | local_bear_list=local_bears[section_name], | ||
| 80 | print_results=print_results, | ||
| 81 | log_printer=log_printer) | ||
| 82 | yielded, yielded_unfixed, results[section_name] = ( | ||
| 83 | simplify_section_result(section_result)) | ||
| 84 | |||
| 85 | yielded_results = yielded_results or yielded | ||
| 86 | yielded_unfixed_results = ( | ||
| 87 | yielded_unfixed_results or yielded_unfixed) | ||
| 88 | did_nothing = False | ||
| 89 | |||
| 90 | tag_results(tag, config_file, results, log_printer) | ||
| 91 | |||
| 92 | if did_nothing: | ||
| 93 | nothing_done(log_printer) | ||
| 94 | elif yielded_unfixed_results: | ||
| 95 | exitcode = 1 | ||
| 96 | elif yielded_results: | ||
| 97 | exitcode = 5 | ||
| 98 | except BaseException as exception: # pylint: disable=broad-except | ||
| 99 | exitcode = exitcode or get_exitcode(exception, log_printer) | ||
| 100 | |||
| 101 | return results, exitcode | ||
| 102 |