saltstack/salt

View on GitHub
salt/modules/mac_power.py

Summary

Maintainability
F
3 days
Test Coverage

File mac_power.py has 359 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Module for editing power settings on macOS

 .. versionadded:: 2016.3.0
Severity: Minor
Found in salt/modules/mac_power.py - About 4 hrs to fix

    Function _validate_sleep has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def _validate_sleep(minutes):
        '''
        Helper function that validates the minutes parameter. Can be any number
        between 1 and 180. Can also be the string values "Never" and "Off".
    
    
    Severity: Minor
    Found in salt/modules/mac_power.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

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

    def set_wake_on_modem(enabled):
        '''
        Set whether or not the computer will wake from sleep when modem activity is
        detected.
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 3 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 332..356
    salt/modules/mac_power.py on lines 379..403
    salt/modules/mac_power.py on lines 479..502

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

    def set_wake_on_network(enabled):
        '''
        Set whether or not the computer will wake from sleep when network activity
        is detected.
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 3 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 285..309
    salt/modules/mac_power.py on lines 379..403
    salt/modules/mac_power.py on lines 479..502

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

    def set_restart_power_failure(enabled):
        '''
        Set whether or not the computer will automatically restart after a power
        failure.
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 3 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 285..309
    salt/modules/mac_power.py on lines 332..356
    salt/modules/mac_power.py on lines 479..502

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

    def set_sleep_on_power_button(enabled):
        '''
        Set whether or not the power button can sleep the computer.
    
        :param bool enabled: True to enable, False to disable. "On" and "Off" are
    Severity: Major
    Found in salt/modules/mac_power.py and 3 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 285..309
    salt/modules/mac_power.py on lines 332..356
    salt/modules/mac_power.py on lines 379..403

    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

    def set_harddisk_sleep(minutes):
        '''
        Set the amount of idle time until the harddisk sleeps. Pass "Never" of "Off"
        to never sleep.
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 2 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 146..170
    salt/modules/mac_power.py on lines 192..216

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

    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 set_display_sleep(minutes):
        '''
        Set the amount of idle time until the display sleeps. Pass "Never" of "Off"
        to never sleep.
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 2 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 146..170
    salt/modules/mac_power.py on lines 238..262

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

    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 set_computer_sleep(minutes):
        '''
        Set the amount of idle time until the computer sleeps. Pass "Never" of "Off"
        to never sleep.
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 2 other locations - About 2 hrs to fix
    salt/modules/mac_power.py on lines 192..216
    salt/modules/mac_power.py on lines 238..262

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

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

    def get_sleep_on_power_button():
        '''
        Displays whether 'allow power button to sleep computer' is on or off if
        supported
    
    
    Severity: Major
    Found in salt/modules/mac_power.py and 5 other locations - About 1 hr to fix
    salt/modules/mac_power.py on lines 266..282
    salt/modules/mac_power.py on lines 313..329
    salt/modules/mac_power.py on lines 360..376
    salt/modules/mac_power.py on lines 407..423
    salt/modules/mac_timezone.py on lines 266..283

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

    def get_wake_on_modem():
        '''
        Displays whether 'wake on modem' is on or off if supported
    
        :return: A string value representing the "wake on modem" settings
    Severity: Major
    Found in salt/modules/mac_power.py and 5 other locations - About 1 hr to fix
    salt/modules/mac_power.py on lines 313..329
    salt/modules/mac_power.py on lines 360..376
    salt/modules/mac_power.py on lines 407..423
    salt/modules/mac_power.py on lines 457..476
    salt/modules/mac_timezone.py on lines 266..283

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

    def get_wake_on_network():
        '''
        Displays whether 'wake on network' is on or off if supported
    
        :return: A string value representing the "wake on network" settings
    Severity: Major
    Found in salt/modules/mac_power.py and 5 other locations - About 1 hr to fix
    salt/modules/mac_power.py on lines 266..282
    salt/modules/mac_power.py on lines 360..376
    salt/modules/mac_power.py on lines 407..423
    salt/modules/mac_power.py on lines 457..476
    salt/modules/mac_timezone.py on lines 266..283

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

    def get_restart_power_failure():
        '''
        Displays whether 'restart on power failure' is on or off if supported
    
        :return: A string value representing the "restart on power failure" settings
    Severity: Major
    Found in salt/modules/mac_power.py and 5 other locations - About 1 hr to fix
    salt/modules/mac_power.py on lines 266..282
    salt/modules/mac_power.py on lines 313..329
    salt/modules/mac_power.py on lines 407..423
    salt/modules/mac_power.py on lines 457..476
    salt/modules/mac_timezone.py on lines 266..283

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

    def get_restart_freeze():
        '''
        Displays whether 'restart on freeze' is on or off if supported
    
        :return: A string value representing the "restart on freeze" settings
    Severity: Major
    Found in salt/modules/mac_power.py and 5 other locations - About 1 hr to fix
    salt/modules/mac_power.py on lines 266..282
    salt/modules/mac_power.py on lines 313..329
    salt/modules/mac_power.py on lines 360..376
    salt/modules/mac_power.py on lines 457..476
    salt/modules/mac_timezone.py on lines 266..283

    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