kontron/python-ipmi

View on GitHub
pyipmi/hpm.py

Summary

Maintainability
F
3 days
Test Coverage

File hpm.py has 541 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright (c) 2014  Kontron Europe GmbH
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
Severity: Major
Found in pyipmi/hpm.py - About 1 day to fix

    Hpm has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Hpm(object):
    
        @staticmethod
        def _get_component_count(components):
            """Return the number of components."""
    Severity: Minor
    Found in pyipmi/hpm.py - About 4 hrs to fix

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

          def upload_binary(self, binary, timeout=2, interval=0.1, retry=3):
              """Upload all firmware blocks from a binary."""
              block_number = 0
              block_size = self._determine_max_block_size()
      
      
      Severity: Minor
      Found in pyipmi/hpm.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 wait_for_long_duration_command has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def wait_for_long_duration_command(self, expected_cmd, timeout, interval):
      
              start_time = time.time()
              while time.time() < start_time + timeout:
                  try:
      Severity: Minor
      Found in pyipmi/hpm.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 _from_rsp_data has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _from_rsp_data(self, data):
              support = []
              cap = data[0]
      
              if cap & self.ROLLBACK_SUPPORT_MASK == 0:
      Severity: Minor
      Found in pyipmi/hpm.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 get_component_properties has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_component_properties(self, component_id):
              properties = []
              for p in (PROPERTY_GENERAL_PROPERTIES, PROPERTY_CURRENT_VERSION,
                        PROPERTY_DESCRIPTION_STRING, PROPERTY_ROLLBACK_VERSION,
                        PROPERTY_DEFERRED_VERSION):
      Severity: Minor
      Found in pyipmi/hpm.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 preparation_stage has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def preparation_stage(self, image):
              ####################################################
              # match device ID, manfuacturer ID, etc.
              device_id = self.get_device_id()
      
      
      Severity: Minor
      Found in pyipmi/hpm.py - About 35 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 from_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def from_data(component_id, data):
              if isinstance(data, str):
                  data = [ord(c) for c in data]
      
              if component_id is PROPERTY_GENERAL_PROPERTIES:
      Severity: Minor
      Found in pyipmi/hpm.py - About 35 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

      Avoid too many return statements within this function.
      Open

                  return ComponentPropertyDeferredVersion(data)
      Severity: Major
      Found in pyipmi/hpm.py - About 30 mins to fix

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

            def _from_data(self, data):
                self.signature = data[0:8]
        
                for a in self.FORMAT:
                    setattr(self, a.field_name, struct.unpack(
        Severity: Minor
        Found in pyipmi/hpm.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 find_component_id_by_descriptor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def find_component_id_by_descriptor(self, descriptor):
                caps = self.get_target_upgrade_capabilities()
                for component_id in caps.components:
                    prop = self.get_component_property(component_id,
                                                       PROPERTY_DESCRIPTION_STRING)
        Severity: Minor
        Found in pyipmi/hpm.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

                self.manufacturer_id = data[10] | data[11] << 8 | data[12] << 16
        Severity: Major
        Found in pyipmi/hpm.py and 1 other location - About 1 hr to fix
        pyipmi/fru.py on lines 394..395

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

        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

                try:
                    rsp = self.finish_firmware_upload(component, length)
                    check_completion_code(rsp.completion_code)
                except CompletionCodeError as e:
                    if e.cc == CC_LONG_DURATION_CMD_IN_PROGRESS:
        Severity: Major
        Found in pyipmi/hpm.py and 3 other locations - About 1 hr to fix
        pyipmi/hpm.py on lines 131..139
        pyipmi/hpm.py on lines 160..167
        pyipmi/hpm.py on lines 229..235

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

        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

                try:
                    self.initiate_upgrade_action(components_mask, action)
                except CompletionCodeError as e:
                    if e.cc == CC_LONG_DURATION_CMD_IN_PROGRESS:
                        self.wait_for_long_duration_command(
        Severity: Major
        Found in pyipmi/hpm.py and 3 other locations - About 1 hr to fix
        pyipmi/hpm.py on lines 160..167
        pyipmi/hpm.py on lines 184..193
        pyipmi/hpm.py on lines 229..235

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

        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

                    except CompletionCodeError as e:
                        if e.cc == CC_LONG_DURATION_CMD_IN_PROGRESS:
        
                            self.wait_for_long_duration_command(
                                    constants.CMDID_HPM_UPLOAD_FIRMWARE_BLOCK,
        Severity: Major
        Found in pyipmi/hpm.py and 3 other locations - About 1 hr to fix
        pyipmi/hpm.py on lines 131..139
        pyipmi/hpm.py on lines 184..193
        pyipmi/hpm.py on lines 229..235

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

        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

                except CompletionCodeError as e:
                    if e.cc == CC_LONG_DURATION_CMD_IN_PROGRESS:
                        self.wait_for_long_duration_command(
                                    constants.CMDID_HPM_ACTIVATE_FIRMWARE,
                                    timeout, interval)
        Severity: Major
        Found in pyipmi/hpm.py and 3 other locations - About 1 hr to fix
        pyipmi/hpm.py on lines 131..139
        pyipmi/hpm.py on lines 160..167
        pyipmi/hpm.py on lines 184..193

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

        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 3 locations. Consider refactoring.
        Open

                if header.product_id != device_id.product_id:
                    raise HpmError('Product ID: image=0x%x device=0x%x'
                                   % (header.product_id, device_id.product_id))
        Severity: Major
        Found in pyipmi/hpm.py and 2 other locations - About 40 mins to fix
        pyipmi/hpm.py on lines 303..305
        pyipmi/hpm.py on lines 306..309

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

        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 3 locations. Consider refactoring.
        Open

                if header.manufacturer_id != device_id.manufacturer_id:
                    raise HpmError('Manufacturer ID: image=0x%x device=0x%x'
                                   % (header.manufacturer_id,
                                      device_id.manufacturer_id))
        Severity: Major
        Found in pyipmi/hpm.py and 2 other locations - About 40 mins to fix
        pyipmi/hpm.py on lines 303..305
        pyipmi/hpm.py on lines 310..312

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

        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 3 locations. Consider refactoring.
        Open

                if header.device_id != device_id.device_id:
                    raise HpmError('Device ID: image=0x%x device=0x%x'
                                   % (header.device_id, device_id.device_id))
        Severity: Major
        Found in pyipmi/hpm.py and 2 other locations - About 40 mins to fix
        pyipmi/hpm.py on lines 306..309
        pyipmi/hpm.py on lines 310..312

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

        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

            @staticmethod
            def _do_upgrade_action_prepare(image):
                for action in image.actions:
                    if isinstance(action, UpgradeActionRecordPrepare):
                        print("do ACTION_PREPARE_COMPONENT")
        Severity: Minor
        Found in pyipmi/hpm.py and 1 other location - About 30 mins to fix
        pyipmi/hpm.py on lines 290..294

        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

            @staticmethod
            def _do_upgrade_action_upload(image):
                for action in image.actions:
                    if isinstance(action, UpgradeActionRecordUploadForUpgrade):
                        print("do ACTION_UPLOAD_FOR_UPGRADE")
        Severity: Minor
        Found in pyipmi/hpm.py and 1 other location - About 30 mins to fix
        pyipmi/hpm.py on lines 284..288

        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