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 ( bc74d0...e48dde )
by thatsIch
01:00
created

_get_rainmeter_path_from_registry()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 8
rs 9.4285
1
import os
0 ignored issues
show
Coding Style introduced by
This module 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...
2
import winreg
3
4
from functools import lru_cache
5
6
import sublime
7
8
from .. import logger
1 ignored issue
show
Bug introduced by
The name logger does not seem to exist in module path.
Loading history...
9
10
11
def _get_rainmeter_path_from_default_path():
0 ignored issues
show
Coding Style Naming introduced by
The name _get_rainmeter_path_from_default_path does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
    """
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \P was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \R was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
13
    Default location is "C:\Program Files\Rainmeter" in windows
14
    we can get "C:\Program Files" through the environmental variables
15
    %PROGRAMFILES%
16
    """
17
    programfiles = os.getenv("PROGRAMFILES")
18
    rainmeterpath = os.path.join(programfiles, "Rainmeter")
19
20
    return rainmeterpath
21
22
23
def _get_rainmeter_registry_key():
24
    """
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \W was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \R was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
25
    throws FileNotFoundException if Software\WOW6432Node\Rainmeter does not exist
26
    not much we can do to handle that
27
    """
28
    return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Rainmeter")
29
30
31
def _get_rainmeter_path_from_registry():
0 ignored issues
show
Coding Style Naming introduced by
The name _get_rainmeter_path_from_registry does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
32
    """
33
    Registry
34
    """
35
    rainmeter_key = _get_rainmeter_registry_key()
36
    rainmeter_path = winreg.QueryValue(rainmeter_key, None)
37
38
    return rainmeter_path
39
40
41
@lru_cache(maxsize=None)
42
def get_cached_program_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...
43
    # Load setting
44
    settings = sublime.load_settings("Rainmeter.sublime-settings")
45
    rm_path = settings.get("rainmeter_path", None)
46
47
    # If setting is not set, try default location
48
    if not rm_path:
49
        logger.info(
50
            __file__,
51
            "get_cached_program_path()",
52
            "rainmeter_path not found in settings. Trying default location."
53
        )
54
        rm_path = _get_rainmeter_path_from_default_path()
55
56
    # if it is not even specified by default, try using the registry to retrieve the installation path
57
    if not os.path.isdir(rm_path):
58
        rm_path = _get_rainmeter_path_from_registry()
59
60
    # Check if path exists and contains Rainmeter.exe
61
    if not os.path.isdir(rm_path):
62
        message = "Path to Rainmeter.exe could neither be found in the standard directory nor via registry. Check your \"rainmeter_path\" setting."
63
        logger.info(__file__, "get_cached_program_path()", message)
64
        sublime.error_message(message)
65
        return
66
67
    # normalize path
68
    rainmeter_exe = os.path.join(rm_path, "Rainmeter.exe")
69
    if not os.path.exists(rainmeter_exe):
70
        message = "Rainmeter path was found, but no Rainmeter.exe found. Check if you have correctly installed Rainmeter."
71
        logger.error(__file__, "get_cached_program_path()", message)
72
        sublime.error_message(message)
73
        return
74
75
    logger.info(__file__, "get_cached_program_path()", "Rainmeter found in " + rm_path)
76
    return rm_path + "\\"
77