saltstack/salt

View on GitHub
salt/modules/freebsdpkg.py

Summary

Maintainability
F
3 days
Test Coverage

File freebsdpkg.py has 422 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Remote package support using ``pkg_add(1)``

.. important::
Severity: Minor
Found in salt/modules/freebsdpkg.py - About 6 hrs to fix

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

    def list_pkgs(versions_as_list=False, with_origin=False, **kwargs):
        '''
        List the packages currently installed as a dict::
    
            {'<package_name>': '<version>'}
    Severity: Minor
    Found in salt/modules/freebsdpkg.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 _match has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _match(names):
        '''
        Since pkg_delete requires the full "pkgname-version" string, this function
        will attempt to match the package name with its version. Returns a list of
        partial matches and package names that match the "pkgname-version" string
    Severity: Minor
    Found in salt/modules/freebsdpkg.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 file_dict has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

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

    def install(name=None,
                refresh=False,
                fromrepo=None,
                pkgs=None,
                sources=None,
    Severity: Minor
    Found in salt/modules/freebsdpkg.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 ret
    Severity: Major
    Found in salt/modules/freebsdpkg.py - About 30 mins to fix

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

      def __virtual__():
          '''
          Load as 'pkg' on FreeBSD versions less than 10.
          Don't load on FreeBSD 9 when the config option
          ``providers:pkg`` is set to 'pkgng'.
      Severity: Minor
      Found in salt/modules/freebsdpkg.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 remove has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def remove(name=None, pkgs=None, **kwargs):
          '''
          Remove packages using ``pkg_delete(1)``
      
          name
      Severity: Minor
      Found in salt/modules/freebsdpkg.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 version(*names, **kwargs):
          '''
          Returns a string representing the package version or an empty string if not
          installed. If more than one package name is specified, a dict of
          name/version pairs is returned.
      Severity: Major
      Found in salt/modules/freebsdpkg.py and 1 other location - About 1 day to fix
      salt/modules/pkgng.py on lines 172..219

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

      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

      def _rehash():
          '''
          Recomputes internal hash table for the PATH variable. Use whenever a new
          command is created during the current session.
          '''
      Severity: Major
      Found in salt/modules/freebsdpkg.py and 2 other locations - About 2 hrs to fix
      salt/modules/pkgin.py on lines 626..634
      salt/modules/xbpspkg.py on lines 70..78

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

      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 salt.utils.data.is_true(with_origin):
              return dict([
                  (x, {'origin': origins.get(x, ''), 'version': y})
                  for x, y in six.iteritems(ret)
      Severity: Major
      Found in salt/modules/freebsdpkg.py and 1 other location - About 2 hrs to fix
      salt/modules/pkgng.py on lines 433..436

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

      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 file_list(*packages, **kwargs):
          '''
          List the files that belong to a package. Not specifying any packages will
          return a list of _every_ file on the system's package database (not
          generally recommended).
      Severity: Major
      Found in salt/modules/freebsdpkg.py and 1 other location - About 2 hrs to fix
      salt/modules/pkgin.py on lines 637..652

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

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

          if out['retcode'] != 0 and out['stderr']:
              errors = [out['stderr']]
          else:
              errors = []
      Severity: Major
      Found in salt/modules/freebsdpkg.py and 16 other locations - About 1 hr to fix
      salt/modules/apkpkg.py on lines 334..337
      salt/modules/apkpkg.py on lines 410..413
      salt/modules/aptpkg.py on lines 810..813
      salt/modules/ebuildpkg.py on lines 1034..1037
      salt/modules/freebsdpkg.py on lines 472..475
      salt/modules/mac_brew_pkg.py on lines 261..264
      salt/modules/mac_brew_pkg.py on lines 415..418
      salt/modules/openbsdpkg.py on lines 299..302
      salt/modules/pacmanpkg.py on lines 614..617
      salt/modules/pacmanpkg.py on lines 739..742
      salt/modules/pkgin.py on lines 429..432
      salt/modules/pkgin.py on lines 577..580
      salt/modules/pkgng.py on lines 893..896
      salt/modules/pkgng.py on lines 1070..1073
      salt/modules/solarispkg.py on lines 466..469
      salt/modules/yumpkg.py on lines 2018..2021

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

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

          if out['retcode'] != 0 and out['stderr']:
              errors = [out['stderr']]
          else:
              errors = []
      Severity: Major
      Found in salt/modules/freebsdpkg.py and 16 other locations - About 1 hr to fix
      salt/modules/apkpkg.py on lines 334..337
      salt/modules/apkpkg.py on lines 410..413
      salt/modules/aptpkg.py on lines 810..813
      salt/modules/ebuildpkg.py on lines 1034..1037
      salt/modules/freebsdpkg.py on lines 409..412
      salt/modules/mac_brew_pkg.py on lines 261..264
      salt/modules/mac_brew_pkg.py on lines 415..418
      salt/modules/openbsdpkg.py on lines 299..302
      salt/modules/pacmanpkg.py on lines 614..617
      salt/modules/pacmanpkg.py on lines 739..742
      salt/modules/pkgin.py on lines 429..432
      salt/modules/pkgin.py on lines 577..580
      salt/modules/pkgng.py on lines 893..896
      salt/modules/pkgng.py on lines 1070..1073
      salt/modules/solarispkg.py on lines 466..469
      salt/modules/yumpkg.py on lines 2018..2021

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

      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