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 ( a7aed0...aa197c )
by thatsIch
01:06
created

_get_rainmeter_registry_key()   A

Complexity

Conditions 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 19
rs 9.2
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():
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...
24
    try:
25
        return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Rainmeter")
26
    except FileNotFoundError:
27
        import sys
28
29
        is_64bits = sys.maxsize > 2**32
30
        if is_64bits:
31
            other_view_flag = winreg.KEY_WOW64_32KEY
32
        else:
33
            other_view_flag = winreg.KEY_WOW64_64KEY
34
35
        try:
36
            return winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Rainmeter", access=winreg.KEY_READ | other_view_flag)
37
        except FileNotFoundError:
38
            '''
39
            We really could not find the key in both views.
40
            '''
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...
41
            return None
42
43
44
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...
45
    """
46
    Registry
47
    """
48
    regkey = __get_rainmeter_registry_key()
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable '__get_rainmeter_registry_key'
Loading history...
49
    if regkey:
50
        keyval = winreg.QueryValueEx(regkey, "Personal")
51
52
        for i in range(1024):
53
            try:
54
                asubkey_name = winreg.EnumKey(keyval, i)
55
                asubkey = winreg.OpenKey(keyval, asubkey_name)
56
                rainmeterpath = winreg.QueryValueEx(asubkey, "DisplayName")
57
                logger.info(__file__, "get_cached_program_path()", "found rainmeter path through registry: " + rainmeterpath)
58
                if rainmeterpath:
59
                    return rainmeterpath
60
            except EnvironmentError:
61
                break
62
63
    return None
64
65
66
@lru_cache(maxsize=None)
67
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...
68
    # Load setting
69
    settings = sublime.load_settings("Rainmeter.sublime-settings")
70
    rainmeterpath = settings.get("rainmeter_path", None)
71
72
    # If setting is not set, try default location
73
    if not rainmeterpath:
74
        logger.info(
75
            __file__,
76
            "get_cached_program_path()",
77
            "rainmeter_path not found in settings. Trying default location."
78
        )
79
        rainmeterpath = _get_rainmeter_path_from_default_path()
80
81
    # if it is not even specified by default, try using the registry to retrieve the installation path
82
    if not os.path.isdir(rainmeterpath):
83
        rainmeterpath = _get_rainmeter_path_from_registry()
84
85
    # Check if path exists and contains Rainmeter.exe
86
    if not os.path.isdir(rainmeterpath):
87
        message = "Path to Rainmeter.exe could neither be found in the standard directory nor via registry. Check your \"rainmeter_path\" setting."
88
        logger.info(__file__, "get_cached_program_path()", message)
89
        sublime.error_message(message)
90
        return
91
92
    # normalize path
93
    rainmeter_exe = os.path.join(rainmeterpath, "Rainmeter.exe")
94
    if not os.path.exists(rainmeter_exe):
95
        message = "Rainmeter path was found, but no Rainmeter.exe found. Check if you have correctly installed Rainmeter."
96
        logger.error(__file__, "get_cached_program_path()", message)
97
        sublime.error_message(message)
98
        return
99
100
    logger.info(__file__, "get_cached_program_path()", "Rainmeter found in " + rainmeterpath)
101
    return rainmeterpath + "\\"
102