CiscoUcs/imcsdk

View on GitHub
imcsdk/imceventhandler.py

Summary

Maintainability
F
4 days
Test Coverage

File imceventhandler.py has 466 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2013 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Minor
Found in imcsdk/imceventhandler.py - About 7 hrs to fix

    Function __dequeue_function has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def __dequeue_function(self):
            """
            Internal method to dequeue to events.
            """
    
    
    Severity: Minor
    Found in imcsdk/imceventhandler.py - About 4 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

    Function __get_mo_elem has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def __get_mo_elem(self, xml_str):
            """
            Internal method to extract mo elements from xml string
            """
    
    
    Severity: Minor
    Found in imcsdk/imceventhandler.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

    Function __enqueue_function has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def __enqueue_function(self):
            """
            Internal method used by add_event_handler.
            Provides functionality of enqueue/dequeue of the events and
            triggering callbacks.
    Severity: Minor
    Found in imcsdk/imceventhandler.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

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

    class ImcEventHandle(object):
        """This class provides api to add and remove event handler."""
    
        def __init__(self, handle):
            self.__handle = handle
    Severity: Minor
    Found in imcsdk/imceventhandler.py - About 2 hrs to fix

      Function add has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def add(self,
      Severity: Major
      Found in imcsdk/imceventhandler.py - About 1 hr to fix

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

            def __prop_val_exist(self, mo, prop, success_value,
                                 failure_value, transient_value,
                                 change_list=None):
                if isinstance(mo, imcmo.GenericMo):
                    n_prop = prop
        Severity: Minor
        Found in imcsdk/imceventhandler.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 _add_mo_watch has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def _add_mo_watch(self, managed_object, prop=None, success_value=[],
                              poll_sec=None, platform=None):
                if imccoreutils.find_class_id_in_mo_meta_ignore_case(
                        managed_object.get_class_id()) is None:
                    raise ImcValidationException(
        Severity: Minor
        Found in imcsdk/imceventhandler.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 __dequeue_mo_prop_poll has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def __dequeue_mo_prop_poll(self, mo, prop, poll_sec, watch_block,
                                       timeout_sec=None, time_left=None):
        
                success_value = watch_block.params["success_value"]
                failure_value = watch_block.params["failure_value"]
        Severity: Minor
        Found in imcsdk/imceventhandler.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

        Avoid deeply nested control flow statements.
        Open

                                    with self.__condition:
                                        self.__condition.notify()
        
        
        Severity: Major
        Found in imcsdk/imceventhandler.py - About 45 mins to fix

          Function wait has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def wait(handle, mo, prop, value, cb, timeout_sec=None):
          Severity: Minor
          Found in imcsdk/imceventhandler.py - About 45 mins to fix

            Function __dequeue_mo_prop_poll has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __dequeue_mo_prop_poll(self, mo, prop, poll_sec, watch_block,
            Severity: Minor
            Found in imcsdk/imceventhandler.py - About 45 mins to fix

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

                  def add(self,
                          class_id=None,
                          managed_object=None,
                          prop=None,
                          success_value=[],
              Severity: Minor
              Found in imcsdk/imceventhandler.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 __prop_val_exist has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def __prop_val_exist(self, mo, prop, success_value,
              Severity: Minor
              Found in imcsdk/imceventhandler.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        for mo_elem in in_config:
                                            mo_elems.append(
                                                (mo_elem, cmce.attrib.get('inEid')))
                        elif root.tag == "configMoChangeEvent":
                Severity: Major
                Found in imcsdk/imceventhandler.py - About 45 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if (len(success_value) > 0 and n_prop_val in success_value) or \
                                  (len(failure_value) > 0 and n_prop_val in failure_value) or \
                                  (len(transient_value) > 0 and n_prop_val in transient_value):
                              return True
                          return False
                  Severity: Major
                  Found in imcsdk/imceventhandler.py - About 40 mins to fix

                    Function _add_mo_watch has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def _add_mo_watch(self, managed_object, prop=None, success_value=[],
                    Severity: Minor
                    Found in imcsdk/imceventhandler.py - About 35 mins to fix

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

                          def dequeue(self, miliseconds_timeout):
                              """Internal method to dequeue the events."""
                              while True:
                                  if self.error_code != 0:
                                      log.debug("queue error:" + str(self.error_code))
                      Severity: Minor
                      Found in imcsdk/imceventhandler.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

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

                          def __dequeue_mce(self, time_left, watch_block):
                              if time_left and time_left > 0:
                                  if self.__lowest_timeout is None or \
                                          self.__lowest_timeout > time_left:
                                      self.__lowest_timeout = time_left
                      Severity: Minor
                      Found in imcsdk/imceventhandler.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

                          def __thread_enqueue_start(self):
                              """
                              Internal method to start the enqueue thread which adds the events in
                              an internal queue.
                              """
                      Severity: Major
                      Found in imcsdk/imceventhandler.py and 1 other location - About 1 hr to fix
                      imcsdk/imceventhandler.py on lines 360..368

                      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 45.

                      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

                          def __thread_dequeue_start(self):
                              """
                              Internal method to start dequeue thread.
                              """
                      
                      
                      Severity: Major
                      Found in imcsdk/imceventhandler.py and 1 other location - About 1 hr to fix
                      imcsdk/imceventhandler.py on lines 170..179

                      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 45.

                      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

                              print(('EventId'.ljust(tab_size * 2) + ':' + str(mce.event_id)))
                      Severity: Minor
                      Found in imcsdk/imceventhandler.py and 1 other location - About 35 mins to fix
                      imcsdk/imceventhandler.py on lines 88..88

                      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 33.

                      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

                              print(('ChangeList'.ljust(tab_size * 2) + ':' + str(mce.change_list)))
                      Severity: Minor
                      Found in imcsdk/imceventhandler.py and 1 other location - About 35 mins to fix
                      imcsdk/imceventhandler.py on lines 87..87

                      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 33.

                      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 self.__lowest_timeout is None or self.__lowest_timeout > poll_sec:
                                  self.__lowest_timeout = poll_sec
                      Severity: Minor
                      Found in imcsdk/imceventhandler.py and 1 other location - About 30 mins to fix
                      imcsdk/imceventhandler.py on lines 193..195

                      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

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

                                  if self.__lowest_timeout is None or \
                                          self.__lowest_timeout > time_left:
                                      self.__lowest_timeout = time_left
                      Severity: Minor
                      Found in imcsdk/imceventhandler.py and 1 other location - About 30 mins to fix
                      imcsdk/imceventhandler.py on lines 243..244

                      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