GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8b7fe1...f5fa7f )
by thatsIch
01:23
created

__executable_exists()   A

Complexity

Conditions 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
1
"""This module is about path resolving for the program path.
2
3
This is required to execute Rainmeter.exe for example to refresh the current skin.
4
"""
5
6
import os
7
import winreg
8
9
from functools import lru_cache
10
11
import sublime
12
13
from .. import logger
1 ignored issue
show
Bug introduced by
The name logger does not seem to exist in module path.
Loading history...
14
15
16
def _get_rm_path_from_default_path():
17
    r"""
18
    Default location is "C:\Program Files\Rainmeter" in windows.
19
20
    We can get "C:\Program Files" through the environmental variables
21
    %PROGRAMFILES%
22
    """
23
    programfiles = os.getenv("PROGRAMFILES")
24
    rainmeterpath = os.path.join(programfiles, "Rainmeter")
25
26
    return rainmeterpath
27
28
29
def _get_rainmeter_registry_key():
30
    r"""
31
    Throw FileNotFoundException if Software\WOW6432Node\Rainmeter does not exist.
32
33
    not much we can do to handle that
34
    """
35
    return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Rainmeter")
36
37
38
def _get_rm_path_from_registry():
39
    """Registry."""
40
    rainmeter_key = _get_rainmeter_registry_key()
41
    rainmeter_path = winreg.QueryValue(rainmeter_key, None)
42
43
    return rainmeter_path
44
45
46
def __executable_exists(rm_path):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
47
    # normalize path
48
    rainmeter_exe = os.path.join(rm_path, "Rainmeter.exe")
49
    if not os.path.exists(rainmeter_exe):
50
        message = """Rainmeter path was found, but no Rainmeter.exe found.
51
                     Check if you have installed Rainmeter correctly."""
52
        logger.error(__file__, "get_cached_program_path()", message)
53
        sublime.error_message(message)
54
        return False
55
56
    return True
57
58
@lru_cache(maxsize=None)
59
def get_cached_program_path():
60
    """Try to retrieve the program path of RM through magic.
61
62
    Possible options are:
63
64
    * It is given through settings
65
    * It is in the default installation path
66
    * It is registered in the registry
67
    * Ask the user for the path
68
    """
69
    # Load setting
70
    settings = sublime.load_settings("Rainmeter.sublime-settings")
71
    rm_path = settings.get("rainmeter_path", None)
72
73
    # If setting is not set, try default location
74
    if not rm_path:
75
        logger.info(
76
            __file__,
77
            "get_cached_program_path()",
78
            "rainmeter_path not found in settings. Trying default location."
79
        )
80
        rm_path = _get_rm_path_from_default_path()
81
82
    # if it is not even specified by default,
83
    # try using the registry to retrieve the installation path
84
    if not os.path.isdir(rm_path):
85
        rm_path = _get_rm_path_from_registry()
86
87
    # Check if path exists and contains Rainmeter.exe
88
    if not os.path.isdir(rm_path):
89
        message = """Path to Rainmeter.exe could neither be found:
90
                     
91
                     * in the settings,
92
                     * in the standard directory,
93
                     * nor via registry.
94
95
                     Check your \"rainmeter_path\" setting."""
96
        logger.info(__file__, "get_cached_program_path()", message)
97
        sublime.error_message(message)
98
        return
99
100
    if not __executable_exists(rm_path):
101
        return
102
103
    logger.info(__file__, "get_cached_program_path()", "Rainmeter found in " + rm_path)
104
    return rm_path + "\\"
105