saltstack/salt

View on GitHub
salt/modules/pkgin.py

Summary

Maintainability
F
4 days
Test Coverage

File pkgin.py has 496 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Package support for pkgin based systems, inspired from freebsdpkg module

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

    Function latest_version has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

    def latest_version(*names, **kwargs):
        '''
        .. versionchanged: 2016.3.0
    
        Return the latest version of the named package available for upgrade or
    Severity: Minor
    Found in salt/modules/pkgin.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 install has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def install(name=None, refresh=False, fromrepo=None,
                pkgs=None, sources=None, **kwargs):
        '''
        Install the passed package
    
    
    Severity: Minor
    Found in salt/modules/pkgin.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 file_dict has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def file_dict(*packages, **kwargs):
        '''
        .. versionchanged: 2016.3.0
    
        List the files that belong to a package.
    Severity: Minor
    Found in salt/modules/pkgin.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 remove has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove(name=None, pkgs=None, **kwargs):
        '''
        name
            The name of the package to be deleted.
    
    
    Severity: Minor
    Found in salt/modules/pkgin.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 upgrade has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def upgrade(refresh=True, pkgs=None, **kwargs):
        '''
        Run pkg upgrade, if pkgin used. Otherwise do nothing
    
        refresh
    Severity: Minor
    Found in salt/modules/pkgin.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 list_pkgs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_pkgs(versions_as_list=False, **kwargs):
        '''
        .. versionchanged: 2016.3.0
    
        List the packages currently installed as a dict::
    Severity: Minor
    Found in salt/modules/pkgin.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 refresh_db has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def refresh_db(force=False, **kwargs):
        '''
        Use pkg update to get latest pkg_summary
    
        force
    Severity: Minor
    Found in salt/modules/pkgin.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 _check_pkgin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def _check_pkgin():
        '''
        Looks to see if pkgin is present on the system, return full path
        '''
        ppath = salt.utils.path.which('pkgin')
    Severity: Minor
    Found in salt/modules/pkgin.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

    Avoid deeply nested control flow statements.
    Open

                        if not s[0] in pkglist:
                            if len(p) > 1 and p[1] in ('<', '', '='):
                                pkglist[s[0]] = s[1]
                            else:
                                pkglist[s[0]] = ''
    Severity: Major
    Found in salt/modules/pkgin.py - About 45 mins to fix

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

      def search(pkg_name, **kwargs):
          '''
          Searches for an exact match using pkgin ^package$
      
          CLI Example:
      Severity: Minor
      Found in salt/modules/pkgin.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

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

          if 'pkg.list_pkgs' in __context__:
              if versions_as_list:
                  return __context__['pkg.list_pkgs']
              else:
                  ret = copy.deepcopy(__context__['pkg.list_pkgs'])
      Severity: Major
      Found in salt/modules/pkgin.py and 11 other locations - About 2 hrs to fix
      salt/modules/aixpkg.py on lines 107..114
      salt/modules/apkpkg.py on lines 139..145
      salt/modules/ebuildpkg.py on lines 424..430
      salt/modules/mac_brew_pkg.py on lines 117..123
      salt/modules/mac_portspkg.py on lines 105..111
      salt/modules/openbsdpkg.py on lines 75..81
      salt/modules/opkg.py on lines 990..996
      salt/modules/pacmanpkg.py on lines 211..217
      salt/modules/pkgutil.py on lines 149..155
      salt/modules/solarisipspkg.py on lines 268..274
      salt/modules/solarispkg.py on lines 102..108

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

      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/pkgin.py and 2 other locations - About 2 hrs to fix
      salt/modules/freebsdpkg.py on lines 496..503
      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 call['retcode'] != 0:
                  comment = ''
                  if 'stderr' in call:
                      comment += call['stderr']
      
      
      Severity: Major
      Found in salt/modules/pkgin.py and 1 other location - About 2 hrs to fix
      salt/modules/xbpspkg.py on lines 277..282

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

      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(package, **kwargs):
          '''
          List the files that belong to a package.
      
          CLI Examples:
      Severity: Major
      Found in salt/modules/pkgin.py and 1 other location - About 2 hrs to fix
      salt/modules/freebsdpkg.py on lines 506..525

      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/pkgin.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/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/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/pkgin.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/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 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

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

      @decorators.memoize
      def _supports_parsing():
          '''
          Check support of parsing
          '''
      Severity: Minor
      Found in salt/modules/pkgin.py and 1 other location - About 35 mins to fix
      salt/modules/pkgin.py on lines 78..83

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

      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

      @decorators.memoize
      def _supports_regex():
          '''
          Check support of regexp
          '''
      Severity: Minor
      Found in salt/modules/pkgin.py and 1 other location - About 35 mins to fix
      salt/modules/pkgin.py on lines 86..91

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

      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