saltstack/salt

View on GitHub
salt/utils/win_update.py

Summary

Maintainability
F
1 wk
Test Coverage

File win_update.py has 696 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Classes for working with Windows Update Agent
'''
# Import Python libs
Severity: Major
Found in salt/utils/win_update.py - About 1 day to fix

    Function uninstall has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
    Open

        def uninstall(self, updates):
            '''
            Uninstall the updates passed in the updates collection. Load the updates
            collection using the ``search`` or ``available`` functions.
    
    
    Severity: Minor
    Found in salt/utils/win_update.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 available has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        def available(self,
                      skip_hidden=True,
                      skip_installed=True,
                      skip_mandatory=False,
                      skip_reboot=False,
    Severity: Minor
    Found in salt/utils/win_update.py - About 4 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 summary has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def summary(self):
            '''
            Create a dictionary with a summary of the updates in the collection.
    
            Returns:
    Severity: Minor
    Found in salt/utils/win_update.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 search has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def search(self, search_string):
            '''
            Search for either a single update or a specific list of updates. GUIDs
            are searched first, then KB numbers, and finally Titles.
    
    
    Severity: Minor
    Found in salt/utils/win_update.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 download has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def download(self, updates):
            '''
            Download the updates passed in the updates collection. Load the updates
            collection using ``search`` or ``available``
    
    
    Severity: Minor
    Found in salt/utils/win_update.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 install has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def install(self, updates):
            '''
            Install the updates passed in the updates collection. Load the updates
            collection using the ``search`` or ``available`` functions. If the
            updates need to be downloaded, use the ``download`` function.
    Severity: Minor
    Found in salt/utils/win_update.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

    Avoid deeply nested control flow statements.
    Open

                                    if 'kb' + kb in item.lower():
                                        pkg = item.split(' : ')[1]
    
                                        ret['DismPackage'] = pkg
    
    
    Severity: Major
    Found in salt/utils/win_update.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                                  if not update.IsInstalled:
                                      ret['Updates'][uid]['Result'] = \
                                          'Uninstallation Succeeded'
                                  else:
                                      ret['Updates'][uid]['Result'] = \
      Severity: Major
      Found in salt/utils/win_update.py - About 45 mins to fix

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

                for i in range(install_list.Count):
                    uid = install_list.Item(i).Identity.UpdateID
                    ret['Updates'][uid]['Result'] = \
                        result_code[result.GetUpdateResult(i).ResultCode]
                    ret['Updates'][uid]['RebootBehavior'] = \
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 5 hrs to fix
        salt/utils/win_update.py on lines 960..965

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

                for i in range(uninstall_list.Count):
                    uid = uninstall_list.Item(i).Identity.UpdateID
                    ret['Updates'][uid]['Result'] = \
                        result_code[result.GetUpdateResult(i).ResultCode]
                    ret['Updates'][uid]['RebootBehavior'] = reboot[
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 5 hrs to fix
        salt/utils/win_update.py on lines 766..771

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

                try:
                    log.debug('Installing Updates')
                    result = installer.Install()
        
                except pywintypes.com_error as error:
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 5 hrs to fix
        salt/utils/win_update.py on lines 622..634

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

        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:
                    log.debug('Downloading Updates')
                    result = downloader.Download()
                except pywintypes.com_error as error:
                    # Something happened, raise an error
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 5 hrs to fix
        salt/utils/win_update.py on lines 728..741

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

        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 result.ResultCode in [2, 3]:
                    ret['Success'] = True
                    ret['NeedsReboot'] = result.RebootRequired
                    log.debug('NeedsReboot: %s', result.RebootRequired)
                else:
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 3 hrs to fix
        salt/utils/win_update.py on lines 949..955

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

        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 result.ResultCode in [2, 3]:
                    ret['Success'] = True
                    ret['NeedsReboot'] = result.RebootRequired
                    log.debug('NeedsReboot: %s', result.RebootRequired)
                else:
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 3 hrs to fix
        salt/utils/win_update.py on lines 755..761

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

        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

                    for category in update.Categories:
                        if category.Name in results['Categories']:
                            results['Categories'][category.Name] += 1
                        else:
                            results['Categories'][category.Name] = 1
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 2 hrs to fix
        salt/utils/win_update.py on lines 236..240

        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 update.MsrcSeverity:
                        if update.MsrcSeverity in results['Severity']:
                            results['Severity'][update.MsrcSeverity] += 1
                        else:
                            results['Severity'][update.MsrcSeverity] = 1
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 2 hrs to fix
        salt/utils/win_update.py on lines 229..233

        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 not salt.utils.data.is_true(update.IsInstalled):
                        log.debug('To Be Installed: %s', uid)
                        log.debug('\tTitle: %s', update.Title)
                        install_list.Add(update)
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 1 hr to fix
        salt/utils/win_update.py on lines 607..610

        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 not salt.utils.data.is_true(update.IsDownloaded):
                        log.debug('To Be Downloaded: %s', uid)
                        log.debug('\tTitle: %s', update.Title)
                        download_list.Add(update)
        Severity: Major
        Found in salt/utils/win_update.py and 1 other location - About 1 hr to fix
        salt/utils/win_update.py on lines 713..716

        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

        There are no issues that match your filters.

        Category
        Status