saltstack/salt

View on GitHub
salt/modules/cp.py

Summary

Maintainability
F
4 days
Test Coverage

File cp.py has 686 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Minion side functions for salt-cp
'''

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

    Function recv_chunked has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

    def recv_chunked(dest, chunk, append=False, compressed=True, mode=None):
        '''
        This function receives files copied to the minion using ``salt-cp`` and is
        not intended to be used directly on the CLI.
        '''
    Severity: Minor
    Found in salt/modules/cp.py - About 3 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 push has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def push(path, keep_symlinks=False, upload_path=None, remove_source=False):
        '''
        WARNING Files pushed to the master will have global read permissions..
    
        Push a file from the minion up to the master, the file will be saved to
    Severity: Minor
    Found in salt/modules/cp.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 push_dir has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def push_dir(path, glob=None, upload_path=None):
        '''
        Push a directory from the minion up to the master, the files will be saved
        to the salt master in the master's minion files cachedir (defaults to
        ``/var/cache/salt/master/minions/minion-id/files``).  It also has a glob
    Severity: Minor
    Found in salt/modules/cp.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 cache_file has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def cache_file(path, saltenv='base', source_hash=None):
        '''
        Used to cache a single file on the Minion
    
        Returns the location of the new cached file on the Minion
    Severity: Minor
    Found in salt/modules/cp.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 recv has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def recv(files, dest):
        '''
        Used with salt-cp, pass the files dict, and the destination.
    
        This function receives small fast copy files from the master via salt-cp.
    Severity: Minor
    Found in salt/modules/cp.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 _render_filenames has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def _render_filenames(path, dest, saltenv, template, **kw):
        '''
        Process markup in the :param:`path` and :param:`dest` variables (NOT the
        files under the paths they ultimately point to) according to the markup
        format provided by :param:`template`.
    Severity: Minor
    Found in salt/modules/cp.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 too many return statements within this function.
    Open

            return True
    Severity: Major
    Found in salt/modules/cp.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                          return ret
      Severity: Major
      Found in salt/modules/cp.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                            return True
        Severity: Major
        Found in salt/modules/cp.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return True
          Severity: Major
          Found in salt/modules/cp.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return _error(makedirs_exc.__str__())
            Severity: Major
            Found in salt/modules/cp.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return _error(exc.__str__())
              Severity: Major
              Found in salt/modules/cp.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return _error(exc.__str__())
                Severity: Major
                Found in salt/modules/cp.py - About 30 mins to fix

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

                  def _gather_pillar(pillarenv, pillar_override):
                      '''
                      Whenever a state run starts, gather the pillar data fresh
                      '''
                      pillar = salt.pillar.get_pillar(
                  Severity: Major
                  Found in salt/modules/cp.py and 1 other location - About 4 hrs to fix
                  salt/modules/cmdmod.py on lines 204..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 80.

                  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 _auth():
                      '''
                      Return the auth object
                      '''
                      if 'auth' not in __context__:
                  Severity: Minor
                  Found in salt/modules/cp.py and 1 other location - About 55 mins to fix
                  salt/thorium/key.py on lines 15..21

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 45.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

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

                      if 'pillarenv' in kw or 'pillar' in kw:
                          pillarenv = kw.get('pillarenv', __opts__.get('pillarenv'))
                          kwargs['pillar'] = _gather_pillar(pillarenv, kw.get('pillar'))
                  Severity: Minor
                  Found in salt/modules/cp.py and 1 other location - About 35 mins to fix
                  salt/modules/cmdmod.py on lines 2672..2674

                  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