saltstack/salt

View on GitHub
salt/utils/win_reg.py

Summary

Maintainability
F
3 days
Test Coverage

File win_reg.py has 712 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Manage the Windows registry

-----
Severity: Major
Found in salt/utils/win_reg.py - About 1 day to fix

    Function read_value has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def read_value(hive, key, vname=None, use_32bit_registry=False):
        r'''
        Reads a registry value entry or the default value for a key. To read the
        default value, don't pass ``vname``
    
    
    Severity: Minor
    Found in salt/utils/win_reg.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 delete_key_recursive has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def delete_key_recursive(hive, key, use_32bit_registry=False):
        '''
        .. versionadded:: 2015.5.4
    
        Delete a registry key to include all subkeys and value/data pairs.
    Severity: Minor
    Found in salt/utils/win_reg.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_values has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
        '''
        Enumerates the values in a registry key or hive.
    
        Args:
    Severity: Minor
    Found in salt/utils/win_reg.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 value_exists has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def value_exists(hive, key, vname, use_32bit_registry=False):
        '''
        Check that the value/data pair is found in the registry.
    
        .. version-added:: 2018.3.4
    Severity: Minor
    Found in salt/utils/win_reg.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 cast_vdata has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def cast_vdata(vdata=None, vtype='REG_SZ'):
        '''
        Cast the ``vdata` value to the appropriate data type for the registry type
        specified in ``vtype``
    
    
    Severity: Minor
    Found in salt/utils/win_reg.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 list_keys has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def list_keys(hive, key=None, use_32bit_registry=False):
        '''
        Enumerates the subkeys in a registry key or hive.
    
        Args:
    Severity: Minor
    Found in salt/utils/win_reg.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 vdata if six.PY3 else long(vdata)  # pylint: disable=incompatible-py3-code,undefined-variable
    Severity: Major
    Found in salt/utils/win_reg.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return int(vdata)
      Severity: Major
      Found in salt/utils/win_reg.py - About 30 mins to fix

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

        def delete_value(hive, key, vname=None, use_32bit_registry=False):
            '''
            Delete a registry value entry or the default value for a key.
        
            Args:
        Severity: Minor
        Found in salt/utils/win_reg.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

                        if vtype == win32con.REG_MULTI_SZ:
                            ret['vdata'] = [_to_mbcs(i) for i in vdata]
                        elif vtype in [win32con.REG_SZ, win32con.REG_EXPAND_SZ]:
                            ret['vdata'] = _to_mbcs(vdata)
                        else:
        Severity: Major
        Found in salt/utils/win_reg.py and 1 other location - About 3 hrs to fix
        salt/utils/win_reg.py on lines 425..430

        Duplicated Code

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

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

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

        Tuning

        This issue has a mass of 80.

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

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

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

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

        Refactorings

        Further Reading

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

                    if vtype == win32con.REG_MULTI_SZ:
                        value['vdata'] = [_to_mbcs(i) for i in vdata]
                    elif vtype in [win32con.REG_SZ, win32con.REG_EXPAND_SZ]:
                        value['vdata'] = _to_mbcs(vdata)
                    else:
        Severity: Major
        Found in salt/utils/win_reg.py and 1 other location - About 3 hrs to fix
        salt/utils/win_reg.py on lines 530..535

        Duplicated Code

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

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

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

        Tuning

        This issue has a mass of 80.

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

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

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

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

        Refactorings

        Further Reading

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

        def __virtual__():
            '''
            Only works on Windows systems with the PyWin32
            '''
            if not salt.utils.platform.is_windows():
        Severity: Major
        Found in salt/utils/win_reg.py and 6 other locations - About 1 hr to fix
        salt/modules/win_lgpo.py on lines 4739..4747
        salt/modules/win_service.py on lines 93..103
        salt/modules/win_system.py on lines 50..60
        salt/modules/win_useradd.py on lines 65..75
        salt/utils/win_dacl.py on lines 157..167
        salt/utils/win_pdh.py on lines 60..70

        Duplicated Code

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

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

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

        Tuning

        This issue has a mass of 46.

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

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

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

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

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status