saltstack/salt

View on GitHub
salt/modules/rpm_lowpkg.py

Summary

Maintainability
F
1 wk
Test Coverage

Function info has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
Open

def info(*packages, **kwargs):
    '''
    Return a detailed package(s) summary information.
    If no packages specified, all packages will be returned.

Severity: Minor
Found in salt/modules/rpm_lowpkg.py - About 1 day 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

File rpm_lowpkg.py has 659 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Support for rpm
'''

Severity: Major
Found in salt/modules/rpm_lowpkg.py - About 1 day to fix

    Function verify has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
    Open

    def verify(*packages, **kwargs):
        '''
        Runs an rpm -Va on a system, and returns the results in a dict
    
        root
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.py - About 7 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

    Cyclomatic complexity is too high in function info. (46)
    Open

    def info(*packages, **kwargs):
        '''
        Return a detailed package(s) summary information.
        If no packages specified, all packages will be returned.
    
    
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function version_cmp has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    def version_cmp(ver1, ver2, ignore_epoch=False):
        '''
        .. versionadded:: 2015.8.9
    
        Do a cmp-style comparison on two packages. Return -1 if ver1 < ver2, 0 if
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.py - About 5 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 modified has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def modified(*packages, **flags):
        '''
        List the modified files that belong to a package. Not specifying any packages
        will return a list of _all_ modified files on the system's RPM database.
    
    
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.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

    Cyclomatic complexity is too high in function verify. (31)
    Open

    def verify(*packages, **kwargs):
        '''
        Runs an rpm -Va on a system, and returns the results in a dict
    
        root
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

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

    def bin_pkg_info(path, saltenv='base'):
        '''
        .. versionadded:: 2015.8.0
    
        Parses RPM metadata and returns a dictionary of information about the
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.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 file_dict has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def file_dict(*packages, **kwargs):
        '''
        List the files that belong to a package, sorted by group. Not specifying
        any packages will return a list of _every_ file on the system's rpm
        database (not generally recommended).
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.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 owner has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def owner(*paths, **kwargs):
        '''
        Return the name of the package that owns the file. Multiple file paths can
        be passed. If a single path is passed, a string will be returned,
        and if multiple paths are passed, a dictionary of file/package name pairs
    Severity: Minor
    Found in salt/modules/rpm_lowpkg.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 salt.utils.versions.version_cmp(ver1, ver2, ignore_epoch=False)
    Severity: Major
    Found in salt/modules/rpm_lowpkg.py - About 30 mins to fix

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

      def list_pkgs(*packages, **kwargs):
          '''
          List the packages currently installed in a dict::
      
              {'<package_name>': '<version>'}
      Severity: Minor
      Found in salt/modules/rpm_lowpkg.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

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

          if __salt__['config.valid_fileproto'](path):
              newpath = __salt__['cp.cache_file'](path, saltenv)
              if not newpath:
                  raise CommandExecutionError(
                      'Unable to retrieve {0} from saltenv \'{1}\''
      Severity: Major
      Found in salt/modules/rpm_lowpkg.py and 1 other location - About 7 hrs to fix
      salt/modules/dpkg_lowpkg.py on lines 62..77

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

      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 isinstance(ignore_types, six.string_types):
              try:
                  ignore_types = [x.strip() for x in ignore_types.split(',')]
              except AttributeError:
                  ignore_types = [x.strip() for x in six.text_type(ignore_types).split(',')]
      Severity: Major
      Found in salt/modules/rpm_lowpkg.py and 1 other location - About 3 hrs to fix
      salt/modules/rpm_lowpkg.py on lines 204..208

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

      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 isinstance(verify_options, six.string_types):
              try:
                  verify_options = [x.strip() for x in verify_options.split(',')]
              except AttributeError:
                  verify_options = [x.strip() for x in six.text_type(verify_options).split(',')]
      Severity: Major
      Found in salt/modules/rpm_lowpkg.py and 1 other location - About 3 hrs to fix
      salt/modules/rpm_lowpkg.py on lines 193..197

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

      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

          try:
              os_grain = __grains__['os'].lower()
              os_family = __grains__['os_family'].lower()
          except Exception:
              return (False, 'The rpm execution module failed to load: failed to detect os or os_family grains.')
      Severity: Minor
      Found in salt/modules/rpm_lowpkg.py and 1 other location - About 45 mins to fix
      salt/modules/yumpkg.py on lines 80..84

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

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

          normalize = lambda x: six.text_type(x).split(':', 1)[-1] \
              if ignore_epoch \
              else six.text_type(x)
      Severity: Major
      Found in salt/modules/rpm_lowpkg.py and 4 other locations - About 40 mins to fix
      salt/modules/aptpkg.py on lines 1425..1426
      salt/modules/opkg.py on lines 1215..1215
      salt/states/pip_state.py on lines 306..306
      salt/utils/versions.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 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

      There are no issues that match your filters.

      Category
      Status