saltstack/salt

View on GitHub
salt/modules/file.py

Summary

Maintainability
F
2 mos
Test Coverage

File file.py has 5334 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Manage information about regular files, directories,
and special files on the minion, set/read user,
group, mode, and data
Severity: Major
Found in salt/modules/file.py - About 2 wks to fix

    Function check_perms has a Cognitive Complexity of 229 (exceeds 5 allowed). Consider refactoring.
    Open

    def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False, seuser=None,
                    serole=None, setype=None, serange=None):
        '''
        .. versionchanged:: Neon
    
    
    Severity: Minor
    Found in salt/modules/file.py - About 4 days 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 manage_file has a Cognitive Complexity of 211 (exceeds 5 allowed). Consider refactoring.
    Open

    def manage_file(name,
                    sfn,
                    ret,
                    source,
                    source_sum,
    Severity: Minor
    Found in salt/modules/file.py - About 4 days 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 blockreplace has a Cognitive Complexity of 107 (exceeds 5 allowed). Consider refactoring.
    Open

    def blockreplace(path,
            marker_start='#-- start managed zone --',
            marker_end='#-- end managed zone --',
            content='',
            append_if_not_found=False,
    Severity: Minor
    Found in salt/modules/file.py - About 2 days 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 check_perms. (105)
    Open

    def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False, seuser=None,
                    serole=None, setype=None, serange=None):
        '''
        .. versionchanged:: Neon
    
    
    Severity: Minor
    Found in salt/modules/file.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 replace has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring.
    Open

    def replace(path,
                pattern,
                repl,
                count=0,
                flags=8,
    Severity: Minor
    Found in salt/modules/file.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

    Function extract_hash has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring.
    Open

    def extract_hash(hash_fn,
                     hash_type='sha256',
                     file_name='',
                     source='',
                     source_hash_name=None):
    Severity: Minor
    Found in salt/modules/file.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

    Function source_list has a Cognitive Complexity of 84 (exceeds 5 allowed). Consider refactoring.
    Open

    def source_list(source, source_hash, saltenv):
        '''
        Check the source list and return the source to use
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/file.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

    Function get_managed has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_managed(
            name,
            template,
            source,
            source_hash,
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function manage_file. (79)
    Open

    def manage_file(name,
                    sfn,
                    ret,
                    source,
                    source_sum,
    Severity: Minor
    Found in salt/modules/file.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 _set_line has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
    Open

    def _set_line(lines,
                  content=None,
                  match=None,
                  mode=None,
                  location=None,
    Severity: Minor
    Found in salt/modules/file.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

    Function check_file_meta has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
    Open

    def check_file_meta(
            name,
            sfn,
            source,
            source_sum,
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function replace. (64)
    Open

    def replace(path,
                pattern,
                repl,
                count=0,
                flags=8,
    Severity: Minor
    Found in salt/modules/file.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 line has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

    def line(path, content=None, match=None, mode=None, location=None,
             before=None, after=None, show_changes=True, backup=False,
             quiet=False, indent=True):
        # pylint: disable=W1401
        '''
    Severity: Minor
    Found in salt/modules/file.py - About 6 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 comment_line has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

    def comment_line(path,
                     regex,
                     char='#',
                     cmnt=True,
                     backup='.bak'):
    Severity: Minor
    Found in salt/modules/file.py - About 6 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 blockreplace. (48)
    Open

    def blockreplace(path,
            marker_start='#-- start managed zone --',
            marker_end='#-- end managed zone --',
            content='',
            append_if_not_found=False,
    Severity: Minor
    Found in salt/modules/file.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

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

    def _set_line(lines,
                  content=None,
                  match=None,
                  mode=None,
                  location=None,
    Severity: Minor
    Found in salt/modules/file.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

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

    def extract_hash(hash_fn,
                     hash_type='sha256',
                     file_name='',
                     source='',
                     source_hash_name=None):
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function check_file_meta. (43)
    Open

    def check_file_meta(
            name,
            sfn,
            source,
            source_sum,
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function source_list. (43)
    Open

    def source_list(source, source_hash, saltenv):
        '''
        Check the source list and return the source to use
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/file.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 get_source_sum has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_source_sum(file_name='',
                       source='',
                       source_hash=None,
                       source_hash_name=None,
                       saltenv='base'):
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function line. (37)
    Open

    def line(path, content=None, match=None, mode=None, location=None,
             before=None, after=None, show_changes=True, backup=False,
             quiet=False, indent=True):
        # pylint: disable=W1401
        '''
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function get_managed. (37)
    Open

    def get_managed(
            name,
            template,
            source,
            source_hash,
    Severity: Minor
    Found in salt/modules/file.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 open_files has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def open_files(by_pid=False):
        '''
        Return a list of all physical open files on the system.
    
        CLI Examples:
    Severity: Minor
    Found in salt/modules/file.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

    Cyclomatic complexity is too high in function comment_line. (30)
    Open

    def comment_line(path,
                     regex,
                     char='#',
                     cmnt=True,
                     backup='.bak'):
    Severity: Minor
    Found in salt/modules/file.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 get_diff has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_diff(file1,
                 file2,
                 saltenv='base',
                 show_filenames=True,
                 show_changes=True,
    Severity: Minor
    Found in salt/modules/file.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 patch has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def patch(originalfile, patchfile, options='', dry_run=False):
        '''
        .. versionadded:: 0.10.4
    
        Apply a patch to a file or directory.
    Severity: Minor
    Found in salt/modules/file.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 copy has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def copy(src, dst, recurse=False, remove_existing=False):
        '''
        Copy a file or directory from source to dst
    
        In order to copy a directory, the recurse flag is required, and
    Severity: Minor
    Found in salt/modules/file.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 check_managed_changes has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def check_managed_changes(
            name,
            source,
            source_hash,
            source_hash_name,
    Severity: Minor
    Found in salt/modules/file.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 stats has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def stats(path, hash_type=None, follow_symlinks=True):
        '''
        Return a dict containing the stats for a given file
    
        CLI Example:
    Severity: Minor
    Found in salt/modules/file.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_backups has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_backups(path, limit=None):
        '''
        .. versionadded:: 0.17.0
    
        Lists the previous versions of a file backed up using Salt's :ref:`file
    Severity: Minor
    Found in salt/modules/file.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_backups_dir has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_backups_dir(path, limit=None):
        '''
        Lists the previous versions of a directory backed up using Salt's :ref:`file
        state backup <file-state-backups>` system.
    
    
    Severity: Minor
    Found in salt/modules/file.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 chown has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def chown(path, user, group):
        '''
        Chown a file, pass the file the desired user and group
    
        path
    Severity: Minor
    Found in salt/modules/file.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 makedirs_perms has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def makedirs_perms(name,
                       user=None,
                       group=None,
                       mode='0755'):
        '''
    Severity: Minor
    Found in salt/modules/file.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 append has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def append(path, *args, **kwargs):
        '''
        .. versionadded:: 0.9.5
    
        Append text to the end of a file
    Severity: Minor
    Found in salt/modules/file.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 tail has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def tail(path, lines):
        '''
        .. versionadded:: Neon
    
        Read the last n lines from a file
    Severity: Minor
    Found in salt/modules/file.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 restore_backup has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def restore_backup(path, backup_id):
        '''
        .. versionadded:: 0.17.0
    
        Restore a previous version of a file that was backed up using Salt's
    Severity: Minor
    Found in salt/modules/file.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 set_selinux_context has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def set_selinux_context(path,
                            user=None,
                            role=None,
                            type=None,    # pylint: disable=W0622
                            range=None,   # pylint: disable=W0622
    Severity: Minor
    Found in salt/modules/file.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 touch has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def touch(name, atime=None, mtime=None):
        '''
        .. versionadded:: 0.9.5
    
        Just like the ``touch`` command, create a file if it doesn't exist or
    Severity: Minor
    Found in salt/modules/file.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 diskusage has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def diskusage(path):
        '''
        Recursively calculate disk usage of path and return it
        in bytes
    
    
    Severity: Minor
    Found in salt/modules/file.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

    Consider simplifying this complex logical expression.
    Open

            if (salt.utils.platform.is_windows() and
                    group_to_gid(group) != group_to_gid(
                        get_group(name, follow_symlinks=follow_symlinks)) and
                    user != '') or (
                not salt.utils.platform.is_windows() and
    Severity: Major
    Found in salt/modules/file.py - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if (salt.utils.platform.is_windows() and
                      user_to_uid(user) != user_to_uid(
                          get_user(name, follow_symlinks=follow_symlinks)) and
                      user != ''
                  ) or (
      Severity: Major
      Found in salt/modules/file.py - About 1 hr to fix

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

        def mknod_fifo(name,
                       user=None,
                       group=None,
                       mode='0660'):
            '''
        Severity: Minor
        Found in salt/modules/file.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 mknod_chrdev has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def mknod_chrdev(name,
                         major,
                         minor,
                         user=None,
                         group=None,
        Severity: Minor
        Found in salt/modules/file.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 makedirs_ has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def makedirs_(path,
                      user=None,
                      group=None,
                      mode=None):
            '''
        Severity: Minor
        Found in salt/modules/file.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 apply_template_on_contents has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def apply_template_on_contents(
                contents,
                template,
                context,
                defaults,
        Severity: Minor
        Found in salt/modules/file.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 mknod_blkdev has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def mknod_blkdev(name,
                         major,
                         minor,
                         user=None,
                         group=None,
        Severity: Minor
        Found in salt/modules/file.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 grep has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def grep(path,
                 pattern,
                 *opts):
            '''
            Grep for a string in the specified file
        Severity: Minor
        Found in salt/modules/file.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 lsattr has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def lsattr(path):
            '''
            .. versionadded:: 2018.3.0
            .. versionchanged:: 2018.3.1
                If ``lsattr`` is not installed on the system, ``None`` is returned.
        Severity: Minor
        Found in salt/modules/file.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 _get_flags has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        def _get_flags(flags):
            '''
            Return an integer appropriate for use as a flag for the re module from a
            list of human-readable strings
        
        
        Severity: Minor
        Found in salt/modules/file.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

        Avoid deeply nested control flow statements.
        Open

                            if insert_before_match:
                                match_idx += 1
                        block_found = True
        Severity: Major
        Found in salt/modules/file.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if matched_type is None:
                                  # There was a match, but it's not of the correct length
                                  # to match one of the supported hash types.
                                  matched = None
                              else:
          Severity: Major
          Found in salt/modules/file.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if line[file_name_idx] in filename_separators:
                                        _add_to_matches(found, line, 'file_name',
                                                        file_name, matched)
                                        hash_matched = True
                                except IndexError:
            Severity: Major
            Found in salt/modules/file.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (requested_seuser or requested_serole or requested_serange) and not requested_setype:
                                          requested_setype = current_setype
                                      result = set_selinux_context(name, user=requested_seuser, role=requested_serole,
              Severity: Major
              Found in salt/modules/file.py - About 45 mins to fix

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

                def lchown(path, user, group):
                    '''
                    Chown a file, pass the file the desired user and group without following
                    symlinks.
                
                
                Severity: Minor
                Found in salt/modules/file.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 insert_after_match:
                                        match_idx += 1
                                    new_file.insert(match_idx, line)
                Severity: Major
                Found in salt/modules/file.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if not senv:
                                          senv = saltenv
                                      if (path, saltenv) in mfiles or (path, saltenv) in mdirs:
                  Severity: Major
                  Found in salt/modules/file.py - About 45 mins to fix

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

                    def chattr(*files, **kwargs):
                        '''
                        .. versionadded:: 2018.3.0
                    
                        Change the attributes of files. This function accepts one or more files and
                    Severity: Minor
                    Found in salt/modules/file.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 line[source_hash_name_idx] in string.whitespace:
                                                _add_to_matches(found, line, 'source_hash_name',
                                                                source_hash_name, matched)
                                                hash_matched = True
                                        except IndexError:
                    Severity: Major
                    Found in salt/modules/file.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                      if cmnt:
                                                          wline = '{0}{1}'.format(char, line)
                                                      else:
                                                          wline = line.lstrip(char)
                                                  else:
                      Severity: Major
                      Found in salt/modules/file.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                            if (path, saltenv) in mfiles or (path, saltenv) in mdirs:
                                                ret = (single_src, single_hash)
                                                break
                                        elif proto.startswith('http') or proto == 'ftp':
                        Severity: Major
                        Found in salt/modules/file.py - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                              if diff_attrs.added:
                                                  chattr(
                                                      name,
                                                      operator="add",
                                                      attributes=diff_attrs.added,
                          Severity: Major
                          Found in salt/modules/file.py - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                if not selinux_error:
                                                    ret['comment'].append('The file {0} is set to be changed'.format(name))
                            
                                                    if requested_seuser:
                                                        if current_seuser != requested_seuser:
                            Severity: Major
                            Found in salt/modules/file.py - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                      if line[source_idx] in filename_separators:
                                                          _add_to_matches(found, line, 'source',
                                                                          source, matched)
                                                          hash_matched = True
                                                  except IndexError:
                              Severity: Major
                              Found in salt/modules/file.py - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                    if mode != salt.utils.files.normalize_mode(get_mode(name)):
                                                        ret['result'] = False
                                                        ret['comment'].append(
                                                            'Failed to change mode to {0}'.format(mode)
                                                        )
                                Severity: Major
                                Found in salt/modules/file.py - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                      if salt.utils.platform.is_windows():
                                                          contents = os.linesep.join(
                                                              _splitlines_preserving_trailing_newline(contents))
                                                      log.debug('File will be encoded with %s', encoding)
                                  Severity: Major
                                  Found in salt/modules/file.py - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                        if urlparsed_single_src.scheme.lower() in string.ascii_lowercase:
                                                            urlparsed_single_src = _urlparse('file://' + single_src)
                                                    proto = urlparsed_single_src.scheme
                                    Severity: Major
                                    Found in salt/modules/file.py - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                          if diff_attrs.removed:
                                                              chattr(
                                                                  name,
                                                                  operator="remove",
                                                                  attributes=diff_attrs.removed,
                                      Severity: Major
                                      Found in salt/modules/file.py - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                            if not __opts__['test']:
                                                                if touch(name):
                                                                    ret['changes']['new'] = 'file {0} created'.format(name)
                                                                    ret['comment'] = 'Empty file'
                                                                else:
                                        Severity: Major
                                        Found in salt/modules/file.py - About 45 mins to fix

                                          Avoid deeply nested control flow statements.
                                          Open

                                                              if not __opts__['test']:
                                                                  if touch(name):
                                                                      ret['changes']['diff'] = 'New file'
                                                                  else:
                                                                      return _error(
                                          Severity: Major
                                          Found in salt/modules/file.py - About 45 mins to fix

                                            Avoid deeply nested control flow statements.
                                            Open

                                                                if urlparsed_src.scheme.lower() in string.ascii_lowercase:
                                                                    urlparsed_src = _urlparse('file://' + single)
                                                            proto = urlparsed_src.scheme
                                            Severity: Major
                                            Found in salt/modules/file.py - About 45 mins to fix

                                              Avoid deeply nested control flow statements.
                                              Open

                                                                  if any(attr for attr in cmp_attrs):
                                                                      ret['result'] = False
                                                                      ret['comment'].append(
                                                                          'Failed to change attributes to {0}'.format(attrs)
                                                                      )
                                              Severity: Major
                                              Found in salt/modules/file.py - About 45 mins to fix

                                                Consider simplifying this complex logical expression.
                                                Open

                                                                if proto == 'salt':
                                                                    path, senv = salt.utils.url.parse(single_src)
                                                                    if not senv:
                                                                        senv = saltenv
                                                                    if (path, saltenv) in mfiles or (path, saltenv) in mdirs:
                                                Severity: Major
                                                Found in salt/modules/file.py - About 40 mins to fix

                                                  Consider simplifying this complex logical expression.
                                                  Open

                                                                  if proto == 'file' and (
                                                                          os.path.exists(urlparsed_src.netloc) or
                                                                          os.path.exists(urlparsed_src.path) or
                                                                          os.path.exists(os.path.join(
                                                                              urlparsed_src.netloc,
                                                  Severity: Major
                                                  Found in salt/modules/file.py - About 40 mins to fix

                                                    Function _mkstemp_copy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                    def _mkstemp_copy(path,
                                                                      preserve_inode=True):
                                                        '''
                                                        Create a temp file and move/copy the contents of ``path`` to the temp file.
                                                        Return the path to the temp file.
                                                    Severity: Minor
                                                    Found in salt/modules/file.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 check_managed has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                    def check_managed(
                                                            name,
                                                            source,
                                                            source_hash,
                                                            source_hash_name,
                                                    Severity: Minor
                                                    Found in salt/modules/file.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 check_hash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                    def check_hash(path, file_hash):
                                                        '''
                                                        Check if a file matches the given hash string
                                                    
                                                        Returns ``True`` if the hash matches, otherwise ``False``.
                                                    Severity: Minor
                                                    Found in salt/modules/file.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 contains_regex has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                    def contains_regex(path, regex, lchar=''):
                                                        '''
                                                        .. deprecated:: 0.17.0
                                                           Use :func:`search` instead.
                                                    
                                                    
                                                    Severity: Minor
                                                    Found in salt/modules/file.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 _error(
                                                    Severity: Major
                                                    Found in salt/modules/file.py - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                          return _error(ret, 'Parent directory not present')
                                                      Severity: Major
                                                      Found in salt/modules/file.py - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                            return '', {}, msg
                                                        Severity: Major
                                                        Found in salt/modules/file.py - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                          return _error(
                                                          Severity: Major
                                                          Found in salt/modules/file.py - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                                        return _error(
                                                            Severity: Major
                                                            Found in salt/modules/file.py - About 30 mins to fix

                                                              Avoid too many return statements within this function.
                                                              Open

                                                                          return sfn, {}, 'Source file \'{0}\' not found'.format(_source)
                                                              Severity: Major
                                                              Found in salt/modules/file.py - About 30 mins to fix

                                                                Avoid too many return statements within this function.
                                                                Open

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

                                                                  Avoid too many return statements within this function.
                                                                  Open

                                                                                      return _error(
                                                                  Severity: Major
                                                                  Found in salt/modules/file.py - About 30 mins to fix

                                                                    Avoid too many return statements within this function.
                                                                    Open

                                                                                        return _error(ret, 'Parent directory not present')
                                                                    Severity: Major
                                                                    Found in salt/modules/file.py - About 30 mins to fix

                                                                      Avoid too many return statements within this function.
                                                                      Open

                                                                                                  return _error(
                                                                      Severity: Major
                                                                      Found in salt/modules/file.py - About 30 mins to fix

                                                                        Avoid too many return statements within this function.
                                                                        Open

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

                                                                          Avoid too many return statements within this function.
                                                                          Open

                                                                                          return sfn, {}, ('Specified template format {0} is not supported'
                                                                          Severity: Major
                                                                          Found in salt/modules/file.py - About 30 mins to fix

                                                                            Avoid too many return statements within this function.
                                                                            Open

                                                                                return sfn, source_sum, ''
                                                                            Severity: Major
                                                                            Found in salt/modules/file.py - About 30 mins to fix

                                                                              Avoid too many return statements within this function.
                                                                              Open

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

                                                                                Avoid too many return statements within this function.
                                                                                Open

                                                                                                return sfn, {}, data['data']
                                                                                Severity: Major
                                                                                Found in salt/modules/file.py - About 30 mins to fix

                                                                                  Avoid too many return statements within this function.
                                                                                  Open

                                                                                                  return '', {}, 'Failed to cache {0}: {1}'.format(_source, exc)
                                                                                  Severity: Major
                                                                                  Found in salt/modules/file.py - About 30 mins to fix

                                                                                    Avoid too many return statements within this function.
                                                                                    Open

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

                                                                                      Avoid too many return statements within this function.
                                                                                      Open

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

                                                                                        Avoid too many return statements within this function.
                                                                                        Open

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

                                                                                          Avoid too many return statements within this function.
                                                                                          Open

                                                                                                          return _error(
                                                                                          Severity: Major
                                                                                          Found in salt/modules/file.py - About 30 mins to fix

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

                                                                                            def prepend(path, *args, **kwargs):
                                                                                                '''
                                                                                                .. versionadded:: 2014.7.0
                                                                                            
                                                                                                Prepend text to the beginning of a file
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.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 delete_backup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                            Open

                                                                                            def delete_backup(path, backup_id):
                                                                                                '''
                                                                                                .. versionadded:: 0.17.0
                                                                                            
                                                                                                Delete a previous version of a file that was backed up using Salt's
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.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 mknod_chrdev(name,
                                                                                                             major,
                                                                                                             minor,
                                                                                                             user=None,
                                                                                                             group=None,
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 2 days to fix
                                                                                            salt/modules/file.py on lines 6329..6377

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

                                                                                            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 mknod_blkdev(name,
                                                                                                             major,
                                                                                                             minor,
                                                                                                             user=None,
                                                                                                             group=None,
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 2 days to fix
                                                                                            salt/modules/file.py on lines 6254..6302

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

                                                                                            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 group:
                                                                                                    if isinstance(group, int):
                                                                                                        group = gid_to_group(group)
                                                                                                    if (salt.utils.platform.is_windows() and
                                                                                                            group_to_gid(group) != group_to_gid(
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 day to fix
                                                                                            salt/modules/file.py on lines 4880..4899

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

                                                                                            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 user:
                                                                                                    if isinstance(user, int):
                                                                                                        user = uid_to_user(user)
                                                                                                    if (salt.utils.platform.is_windows() and
                                                                                                            user_to_uid(user) != user_to_uid(
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 day to fix
                                                                                            salt/modules/file.py on lines 4901..4919

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

                                                                                            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 user:
                                                                                                    if isinstance(user, int):
                                                                                                        user = uid_to_user(user)
                                                                                                    if (salt.utils.platform.is_windows() and
                                                                                                            user_to_uid(user) != user_to_uid(perms['luser'])
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 4852..4860

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

                                                                                            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 group:
                                                                                                    if isinstance(group, int):
                                                                                                        group = gid_to_group(group)
                                                                                                    if (salt.utils.platform.is_windows() and
                                                                                                            group_to_gid(group) != group_to_gid(perms['lgroup'])
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 4842..4850

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

                                                                                            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 not skip_verify \
                                                                                                                and _urlparse(source).scheme != 'salt':
                                                                                                            dl_sum = get_hash(sfn, source_sum['hash_type'])
                                                                                                            if dl_sum != source_sum['hsum']:
                                                                                                                ret['comment'] = (
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 5854..5867
                                                                                            salt/modules/file.py on lines 5957..5971

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

                                                                                            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 not skip_verify \
                                                                                                                and _urlparse(source).scheme != 'salt':
                                                                                                            dl_sum = get_hash(sfn, source_sum['hash_type'])
                                                                                                            if dl_sum != source_sum['hsum']:
                                                                                                                ret['comment'] = (
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 5763..5780
                                                                                            salt/modules/file.py on lines 5854..5867

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

                                                                                            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 not skip_verify and _urlparse(source).scheme != 'salt':
                                                                                                            dl_sum = get_hash(sfn, source_sum['hash_type'])
                                                                                                            if dl_sum != source_sum['hsum']:
                                                                                                                ret['comment'] = (
                                                                                                                    'Specified {0} checksum for {1} ({2}) does not match '
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 5763..5780
                                                                                            salt/modules/file.py on lines 5957..5971

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

                                                                                            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

                                                                                                try:
                                                                                                    if len(six.text_type(backup_id)) == len(six.text_type(int(backup_id))):
                                                                                                        backup = list_backups(path)[int(backup_id)]
                                                                                                    else:
                                                                                                        return ret
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 6646..6656

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

                                                                                            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

                                                                                                try:
                                                                                                    if len(six.text_type(backup_id)) == len(six.text_type(int(backup_id))):
                                                                                                        backup = list_backups(path)[int(backup_id)]
                                                                                                    else:
                                                                                                        return ret
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 6706..6716

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

                                                                                            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 source:
                                                                                                            if line.endswith(source_basename):
                                                                                                                # Same as above, we can't just do an rsplit here.
                                                                                                                try:
                                                                                                                    if line[source_idx] in filename_separators:
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 4730..4746

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

                                                                                            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 file_name:
                                                                                                            if line.endswith(file_name_basename):
                                                                                                                # Checking the character before where the basename
                                                                                                                # should start for either whitespace or a path
                                                                                                                # separator. We can't just rsplit on spaces/whitespace,
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 5 hrs to fix
                                                                                            salt/modules/file.py on lines 4747..4759

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

                                                                                            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 is_chrdev(name):
                                                                                                '''
                                                                                                Check if a file exists and is a character device.
                                                                                            
                                                                                                CLI Example:
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 3 hrs to fix
                                                                                            salt/modules/file.py on lines 6305..6326
                                                                                            salt/modules/file.py on lines 6380..6401

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

                                                                                            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 is_fifo(name):
                                                                                                '''
                                                                                                Check if a file exists and is a FIFO.
                                                                                            
                                                                                                CLI Example:
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 3 hrs to fix
                                                                                            salt/modules/file.py on lines 6230..6251
                                                                                            salt/modules/file.py on lines 6305..6326

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

                                                                                            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 is_blkdev(name):
                                                                                                '''
                                                                                                Check if a file exists and is a block device.
                                                                                            
                                                                                                CLI Example:
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 3 hrs to fix
                                                                                            salt/modules/file.py on lines 6230..6251
                                                                                            salt/modules/file.py on lines 6380..6401

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

                                                                                            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

                                                                                                while True:
                                                                                                    if os.path.isdir(dirname):
                                                                                                        break
                                                                                            
                                                                                                    directories_to_create.append(dirname)
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 3 hrs to fix
                                                                                            salt/modules/win_file.py on lines 1446..1456

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

                                                                                            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 not os.path.isdir(contain_dir):
                                                                                                            if makedirs:
                                                                                                                _set_mode_and_make_dirs(name, dir_mode, mode, user, group)
                                                                                                            else:
                                                                                                                __clean_tmp(sfn)
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 3 hrs to fix
                                                                                            salt/modules/file.py on lines 5983..5990

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

                                                                                            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 not os.path.isdir(contain_dir):
                                                                                                            if makedirs:
                                                                                                                _set_mode_and_make_dirs(name, dir_mode, mode, user, group)
                                                                                                            else:
                                                                                                                __clean_tmp(sfn)
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 3 hrs to fix
                                                                                            salt/modules/file.py on lines 5974..5981

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

                                                                                            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.platform.is_windows():
                                                                                                        # This function resides in win_file.py and will be available
                                                                                                        # on Windows. The local function will be overridden
                                                                                                        # pylint: disable=E1120,E1121,E1123
                                                                                                        ret = check_perms(
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 5882..5893

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

                                                                                            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.platform.is_windows():
                                                                                                        # This function resides in win_file.py and will be available
                                                                                                        # on Windows. The local function will be overridden
                                                                                                        # pylint: disable=E1120,E1121,E1123
                                                                                                        ret = check_perms(
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 6050..6061

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

                                                                                            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

                                                                                                            try:
                                                                                                                salt.utils.files.copyfile(tmp,
                                                                                                                                          real_name,
                                                                                                                                          __salt__['config.backup_mode'](backup),
                                                                                                                                          __opts__['cachedir'])
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 5795..5803
                                                                                            salt/modules/file.py on lines 5869..5877

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

                                                                                            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

                                                                                                        try:
                                                                                                            salt.utils.files.copyfile(sfn,
                                                                                                                                      real_name,
                                                                                                                                      __salt__['config.backup_mode'](backup),
                                                                                                                                      __opts__['cachedir'])
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 5834..5842
                                                                                            salt/modules/file.py on lines 5869..5877

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

                                                                                            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

                                                                                                        try:
                                                                                                            salt.utils.files.copyfile(sfn,
                                                                                                                                name,
                                                                                                                                __salt__['config.backup_mode'](backup),
                                                                                                                                __opts__['cachedir'])
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 5795..5803
                                                                                            salt/modules/file.py on lines 5834..5842

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

                                                                                            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

                                                                                                            elif proto == 'file' and (
                                                                                                                     os.path.exists(urlparsed_single_src.netloc) or
                                                                                                                     os.path.exists(urlparsed_single_src.path) or
                                                                                                                     os.path.exists(os.path.join(
                                                                                                                         urlparsed_single_src.netloc,
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 4273..4278

                                                                                            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

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

                                                                                                            if proto == 'file' and (
                                                                                                                    os.path.exists(urlparsed_src.netloc) or
                                                                                                                    os.path.exists(urlparsed_src.path) or
                                                                                                                    os.path.exists(os.path.join(
                                                                                                                        urlparsed_src.netloc,
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 4246..4251

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

                                                                                                if 'args' in kwargs:
                                                                                                    if isinstance(kwargs['args'], list):
                                                                                                        args = kwargs['args']
                                                                                                    else:
                                                                                                        args = [kwargs['args']]
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 3269..3273
                                                                                            salt/modules/file.py on lines 3339..3343

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

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

                                                                                                if 'args' in kwargs:
                                                                                                    if isinstance(kwargs['args'], list):
                                                                                                        args = kwargs['args']
                                                                                                    else:
                                                                                                        args = [kwargs['args']]
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 3269..3273
                                                                                            salt/modules/file.py on lines 3396..3400

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

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

                                                                                                if 'args' in kwargs:
                                                                                                    if isinstance(kwargs['args'], list):
                                                                                                        args = kwargs['args']
                                                                                                    else:
                                                                                                        args = [kwargs['args']]
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 2 hrs to fix
                                                                                            salt/modules/file.py on lines 3339..3343
                                                                                            salt/modules/file.py on lines 3396..3400

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

                                                                                            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 not salt.utils.platform.is_windows():
                                                                                                    pre_user = get_user(src)
                                                                                                    pre_group = get_group(src)
                                                                                                    pre_mode = salt.utils.files.normalize_mode(get_mode(src))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 1556..1559
                                                                                            salt/modules/file.py on lines 2486..2489

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

                                                                                            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 not salt.utils.platform.is_windows():
                                                                                                    pre_user = get_user(path)
                                                                                                    pre_group = get_group(path)
                                                                                                    pre_mode = salt.utils.files.normalize_mode(get_mode(path))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 1556..1559
                                                                                            salt/modules/file.py on lines 3745..3748

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

                                                                                            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 not salt.utils.platform.is_windows():
                                                                                                    pre_user = get_user(path)
                                                                                                    pre_group = get_group(path)
                                                                                                    pre_mode = salt.utils.files.normalize_mode(get_mode(path))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 2486..2489
                                                                                            salt/modules/file.py on lines 3745..3748

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

                                                                                            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 not ret:
                                                                                                    ret = {'name': name,
                                                                                                           'changes': {},
                                                                                                           'comment': [],
                                                                                                           'result': True}
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/utils/win_dacl.py on lines 2289..2297

                                                                                            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

                                                                                                    if (group is not None
                                                                                                            and group != lstats['group']
                                                                                                            and group != lstats['gid']):
                                                                                                        changes['group'] = group
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 5386..5389

                                                                                            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

                                                                                                    if (user is not None
                                                                                                            and user != lstats['user']
                                                                                                            and user != lstats['uid']):
                                                                                                        changes['user'] = user
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 5392..5395

                                                                                            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

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

                                                                                                        if _urlparse(source).scheme in ('salt', 'file') \
                                                                                                                or source.startswith('/'):
                                                                                                            try:
                                                                                                                mode = __salt__['cp.stat_file'](source, saltenv=saltenv, octal=True)
                                                                                                            except Exception as exc:
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 5734..5738

                                                                                            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

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

                                                                                                        if _urlparse(source).scheme in ('salt', 'file', ''):
                                                                                                            try:
                                                                                                                mode = __salt__['cp.stat_file'](source, saltenv=saltenv, octal=True)
                                                                                                            except Exception as exc:
                                                                                                                log.warning('Unable to stat %s: %s', sfn, exc)
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 5234..5239

                                                                                            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

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

                                                                                                if mode not in ('insert', 'ensure', 'delete', 'replace'):
                                                                                                    if mode is None:
                                                                                                        raise CommandExecutionError('Mode was not defined. How to process the file?')
                                                                                                    else:
                                                                                                        raise CommandExecutionError('Unknown mode: {0}'.format(mode))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 2221..2225

                                                                                            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

                                                                                                if mode not in ['insert', 'ensure', 'delete', 'replace']:
                                                                                                    if mode is None:
                                                                                                        raise CommandExecutionError('Mode was not defined. How to process the file?')
                                                                                                    else:
                                                                                                        raise CommandExecutionError('Unknown mode: "{0}"'.format(mode))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 1 other location - About 1 hr to fix
                                                                                            salt/modules/file.py on lines 1865..1869

                                                                                            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

                                                                                                            if salt.utils.platform.is_windows():
                                                                                                                # urlparse doesn't handle a local Windows path without the
                                                                                                                # protocol indicator (file://). The scheme will be the
                                                                                                                # drive letter instead of the protocol. So, we'll add the
                                                                                                                # protocol and re-parse
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.py and 1 other location - About 55 mins to fix
                                                                                            salt/modules/file.py on lines 4228..4234

                                                                                            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 salt.utils.platform.is_windows():
                                                                                                                # urlparse doesn't handle a local Windows path without the
                                                                                                                # protocol indicator (file://). The scheme will be the
                                                                                                                # drive letter instead of the protocol. So, we'll add the
                                                                                                                # protocol and re-parse
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.py and 1 other location - About 55 mins to fix
                                                                                            salt/modules/file.py on lines 4265..4271

                                                                                            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

                                                                                                                try:
                                                                                                                    # set_selinux_context requires type to be set on any other change
                                                                                                                    if (requested_seuser or requested_serole or requested_serange) and not requested_setype:
                                                                                                                        requested_setype = current_setype
                                                                                                                    result = set_selinux_context(name, user=requested_seuser, role=requested_serole,
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.py and 1 other location - About 50 mins to fix
                                                                                            salt/modules/file.py on lines 4985..4997

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

                                                                                            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:
                                                                                                        current_seuser, current_serole, current_setype, current_serange = get_selinux_context(name).split(':')
                                                                                                        log.debug(
                                                                                                            'Current selinux context user:%s role:%s type:%s range:%s',
                                                                                                            current_seuser, current_serole, current_setype, current_serange
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.py and 1 other location - About 50 mins to fix
                                                                                            salt/modules/file.py on lines 5037..5051

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

                                                                                            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:
                                                                                                        split = salt.utils.args.shlex_split(opt)
                                                                                                    except AttributeError:
                                                                                                        split = salt.utils.args.shlex_split(six.text_type(opt))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 3 other locations - About 45 mins to fix
                                                                                            salt/modules/rbenv.py on lines 394..397
                                                                                            salt/modules/rbenv.py on lines 430..433
                                                                                            salt/modules/rvm.py on lines 467..470

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

                                                                                                with salt.utils.files.fopen(path, "w") as ofile:
                                                                                                    ofile.write(salt.utils.stringutils.to_str(''.join(contents)))
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 2 other locations - About 40 mins to fix
                                                                                            salt/modules/debuild_pkgbuild.py on lines 722..723
                                                                                            salt/modules/xbpspkg.py on lines 597..601

                                                                                            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

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

                                                                                                                    if requested_serange:
                                                                                                                        if current_serange != requested_serange:
                                                                                                                            ret['comment'].append("Unable to update serange context")
                                                                                                                            ret['result'] = False
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 3 other locations - About 30 mins to fix
                                                                                            salt/modules/file.py on lines 5056..5059
                                                                                            salt/modules/file.py on lines 5060..5063
                                                                                            salt/modules/file.py on lines 5064..5067

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

                                                                                            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

                                                                                                                    if requested_serole:
                                                                                                                        if current_serole != requested_serole:
                                                                                                                            ret['comment'].append("Unable to update serole context")
                                                                                                                            ret['result'] = False
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 3 other locations - About 30 mins to fix
                                                                                            salt/modules/file.py on lines 5056..5059
                                                                                            salt/modules/file.py on lines 5064..5067
                                                                                            salt/modules/file.py on lines 5068..5071

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

                                                                                            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

                                                                                                                    if requested_seuser:
                                                                                                                        if current_seuser != requested_seuser:
                                                                                                                            ret['comment'].append("Unable to update seuser context")
                                                                                                                            ret['result'] = False
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 3 other locations - About 30 mins to fix
                                                                                            salt/modules/file.py on lines 5060..5063
                                                                                            salt/modules/file.py on lines 5064..5067
                                                                                            salt/modules/file.py on lines 5068..5071

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

                                                                                            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

                                                                                                                    if requested_setype:
                                                                                                                        if current_setype != requested_setype:
                                                                                                                            ret['comment'].append("Unable to update setype context")
                                                                                                                            ret['result'] = False
                                                                                            Severity: Major
                                                                                            Found in salt/modules/file.py and 3 other locations - About 30 mins to fix
                                                                                            salt/modules/file.py on lines 5056..5059
                                                                                            salt/modules/file.py on lines 5060..5063
                                                                                            salt/modules/file.py on lines 5068..5071

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

                                                                                            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 parsed_scheme and parsed_scheme.lower() in string.ascii_lowercase:
                                                                                                        parsed_path = ':'.join([parsed_scheme, parsed_path])
                                                                                                        parsed_scheme = 'file'
                                                                                            Severity: Minor
                                                                                            Found in salt/modules/file.py and 2 other locations - About 30 mins to fix
                                                                                            salt/fileclient.py on lines 480..482
                                                                                            salt/states/archive.py on lines 797..800

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

                                                                                            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