pkg/build/builder/ansible/callback/live.py

Summary

Maintainability
F
4 days
Test Coverage

File live.py has 385 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Severity: Minor
Found in pkg/build/builder/ansible/callback/live.py - About 5 hrs to fix

    Function _get_task_info_from_args has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_task_info_from_args(self, task, start=False):
            info = ''
            if task.action in self.FREE_FORM_MODULES:
                info = task.args.get('_raw_params', '')
            if task.action == 'file':
    Severity: Minor
    Found in pkg/build/builder/ansible/callback/live.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    CallbackModule has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CallbackModule(LiveCallbackHelpers):
        CALLBACK_VERSION = 2.0
        CALLBACK_TYPE = 'stdout'
        CALLBACK_NAME = 'live'
    
    
    Severity: Minor
    Found in pkg/build/builder/ansible/callback/live.py - About 2 hrs to fix

      Function _display_msg has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _display_msg(self, task, result, color):
              if task.action in self.SQUASH_LOOP_MODULES and 'results' in result:
                  if len(result['results']) > 0:
                      self.LogArgs(stringc(result['results'][0], color), "\n")
                      return
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _flatten has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _flatten(self, l):
              """Yield items from any nested iterable"""
              if isinstance(l, (unicode, str, bytes)):
                  yield l
                  return
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _handle_warnings has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _handle_warnings(self, res):
              ''' display warnings, if enabled and any exist in the result '''
              if C.ACTION_WARNINGS:
                  if 'warnings' in res and res['warnings']:
                      for warning in res['warnings']:
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _display_debug_msg has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _display_debug_msg(self, task, result):
              #if (self._display.verbosity > 0 or '_ansible_verbose_always' in result) and '_ansible_verbose_override' not in result:
              if task.args.get('msg'):
                  color = C.COLOR_OK
                  msg = u"\n".join(self._flatten(result.get('msg', '')))
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _dump_results has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False):
              if not indent and (result.get('_ansible_verbose_always') or self._display.verbosity > 2):
                  indent = 4
      
              # All result keys stating with _ansible_ are internal, so remove them from the result before we output anything.
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _item_details has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def _item_details(self, task, item_result):
              task_name = self._clean_str(task.name)
              if '_ansible_item_label' in item_result:
                  item_name = item_result.get('_ansible_item_label','')
              else:
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _task_details has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _task_details(self, task, start=False):
              task_name = self._clean_str(task.name)
              info = self._get_task_info_from_args(task, start) or ''
      
              if info != '':
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _deprecated_msg has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def _deprecated_msg(self, msg, version=None, removed=False):
              ''' used to print out a deprecation message.'''
              if not removed and not C.DEPRECATION_WARNINGS:
                  return
      
      
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              if item_name != '':
                  if len(task_name)+len(item_name) > self.HEADER_NAME_INFO_LEN:
                      item_name = self._squash_right(item_name, self.HEADER_NAME_INFO_LEN-len(task_name))
                  item_name = " item '%s'" % (item_name)
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 1 other location - About 3 hrs to fix
      pkg/build/builder/ansible/callback/live.py on lines 183..186

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 71.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              if task_name != '':
                  if len(task_name)+len(info) > self.HEADER_NAME_INFO_LEN:
                      task_name = self._squash_right(task_name, self.HEADER_NAME_INFO_LEN-len(info))
                  task_name = " '%s'" % task_name
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 1 other location - About 3 hrs to fix
      pkg/build/builder/ansible/callback/live.py on lines 210..213

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 71.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if task.action == 'debug':
                  self._display_debug_msg(result._task, result._result)
              else:
                  self._display_msg(result._task, result._result, color)
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 1 other location - About 1 hr to fix
      pkg/build/builder/ansible/callback/live.py on lines 415..418

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 42.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

                  if task.action == 'debug':
                      self._display_debug_msg(result._task, result._result)
                  else:
                      self._display_msg(result._task, result._result, color)
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 1 other location - About 1 hr to fix
      pkg/build/builder/ansible/callback/live.py on lines 438..441

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 42.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              self._display.v("TASK action=%s item OK => %s" % (result._task.action, json.dumps(result._result, indent=4)))
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 3 other locations - About 50 mins to fix
      pkg/build/builder/ansible/callback/live.py on lines 404..404
      pkg/build/builder/ansible/callback/live.py on lines 457..457
      pkg/build/builder/ansible/callback/live.py on lines 472..472

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              self._display.v("TASK action=%s ITEM FAILED => %s" % (result._task.action, json.dumps(result._result, indent=4)))
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 3 other locations - About 50 mins to fix
      pkg/build/builder/ansible/callback/live.py on lines 404..404
      pkg/build/builder/ansible/callback/live.py on lines 426..426
      pkg/build/builder/ansible/callback/live.py on lines 457..457

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              self._display.v("TASK action=%s OK => %s" % (result._task.action, json.dumps(result._result, indent=4)))
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 3 other locations - About 50 mins to fix
      pkg/build/builder/ansible/callback/live.py on lines 426..426
      pkg/build/builder/ansible/callback/live.py on lines 457..457
      pkg/build/builder/ansible/callback/live.py on lines 472..472

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

              self._display.v("TASK action=%s FAILED => %s" % (result._task.action, json.dumps(result._result, indent=4)))
      Severity: Major
      Found in pkg/build/builder/ansible/callback/live.py and 3 other locations - About 50 mins to fix
      pkg/build/builder/ansible/callback/live.py on lines 404..404
      pkg/build/builder/ansible/callback/live.py on lines 426..426
      pkg/build/builder/ansible/callback/live.py on lines 472..472

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              if 'changed' in result._result and result._result['changed']:
                  color = C.COLOR_CHANGED
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py and 1 other location - About 30 mins to fix
      pkg/build/builder/ansible/callback/live.py on lines 411..412

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 32.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

                  if 'changed' in result._result and result._result['changed']:
                      color = C.COLOR_CHANGED
      Severity: Minor
      Found in pkg/build/builder/ansible/callback/live.py and 1 other location - About 30 mins to fix
      pkg/build/builder/ansible/callback/live.py on lines 434..435

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 32.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status