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 ( 8688ad...e355f5 )
by thatsIch
01:04
created

get_cached_skin_path()   F

Complexity

Conditions 10

Size

Total Lines 120

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
c 1
b 0
f 0
dl 0
loc 120
rs 3.1304

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like get_cached_skin_path() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import getpass
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 io
3
import os
4
import platform
5
import re
6
import winreg
0 ignored issues
show
Configuration introduced by
The import winreg could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
7
from functools import lru_cache
8
9
import sublime
0 ignored issues
show
Configuration introduced by
The import sublime could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
10
11
from .. import logger
1 ignored issue
show
Bug introduced by
The name logger does not seem to exist in module path.
Loading history...
12
13
from .program_path_provider import get_cached_program_path
14
from .setting_path_provider import get_cached_setting_path
15
16
17
@lru_cache(maxsize=None)
18
def get_cached_skin_path():
19
    """Get the value of the #SKINSPATH# variable"""
20
21
    # First try to load the value from the "rainmeter_skins_path" setting
22
    loaded_settings = sublime.load_settings("Rainmeter.sublime-settings")
23
    skinspath = loaded_settings.get("rainmeter_skins_path", None)
24
25
    # if it's found, return it
26
    # We trust the user to enter something meaningful here
27
    # and don't check anything.
28
    if skinspath:
29
        logger.info(__file__, "get_skins_path", "Skins path found in sublime-settings file.")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (93/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
30
        return os.path.normpath(skinspath) + "\\"
31
32
    # If it's not set, try to detect it automagically
33
34
    rainmeterpath = get_cached_program_path()
35
    if not rainmeterpath:
36
        return
37
38
    settingspath = get_cached_setting_path()
39
    if not settingspath:
40
        return
41
42
    # First, try to read the SkinPath setting from Rainmeter.ini
43
    fhnd = io.open(os.path.join(settingspath, "Rainmeter.ini"))
44
    lines = fhnd.read()
45
    fhnd.close()
46
47
    # Find the skinspath setting in the file
48
    match = re.search(r"""(?imsx)
49
50
                     # Find the first [Rainmeter] section
51
                     (^\s*\[\s*Rainmeter\s*\]\s*$)
52
                     (.*?
53
54
                         # Find the "SkinPath" and "="
55
                         (^\s*SkinPath\s*=\s*
56
57
                             # Read until the next line ending and store
58
                             # in named group
59
                             (?P<skinpath>[^$]+?)\s*?$
60
                         )
61
                     ).*?
62
63
                     # All of this needs to happen before the next section
64
                     (?:^\s*\[\s*[^\[\]\s]+\s*\]\s*$)
65
                     """, lines)
66
67
    # if skinspath setting was found, return it
68
    if match:
69
        logger.info(__file__, "get_skins_path", "Skins path found in Rainmeter.ini.")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
70
        return match.group("skinpath").strip().replace("/", "\\")
71
72
    # if it's not found in the settings file, try to guess it
73
74
    # If program path and setting path are equal, we have a portable
75
    # installation. In this case, the Skins folder is inside the rainmeter
76
    # path
77
    if os.path.samefile(rainmeterpath, settingspath):
78
        logger.info(__file__, "get_skins_path", "Skin path found in #PROGRAMPATH#" +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
79
                    " because portable installation")
80
        return os.path.join(rainmeterpath, "Skins") + "\\"
81
82
    # If it's not a portable installation, we try looking into the "My
83
    # Documents" folder Since it could be relocated by the user, we have to
84
    # query its value from the registry
85
    try:
86
        regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
87
                                r"Software\Microsoft\Windows" +
88
                                r"\CurrentVersion\Explorer" +
89
                                r"\User Shell Folders")
90
        keyval = winreg.QueryValueEx(regkey, "Personal")
91
92
        pathrep = keyval[0]
93
94
        # The path could (and most likely, will) contain environment
95
        # variables that have to be expanded first
96
        pathrep = os.path.expandvars(pathrep)
97
98
        logger.info(__file__, "get_skins_path", "Guessed Skin path from My Documents" +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (87/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
99
                    " location in registry")
100
        return os.path.join(pathrep, "Rainmeter\\Skins") + "\\"
101
102
    except OSError:
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
103
        pass
104
105
    # If the value could not be retrieved from the registry,
106
    # we try some educated guesses about default locations
107
    try:
108
        username = getpass.getuser()
109
    except Exception:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
110
        logger.info(__file__, "get_skins_path", "Skins path could not be located." +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
111
                    " Please set the \"skins_path\" setting in your Rainmeter" +
112
                    " settings file.")
113
        return
114
    else:
115
        # check if windows version is XP
116
        winversion = platform.version()
117
        if int(winversion[0]) < 6:
118
            mydocuments = os.path.join("C:\\Documents and Settings",
119
                                       username,
120
                                       "My Documents") + "\\"
121
122
            logger.info(__file__, "get_skins_path", "Found Windows XP or lower." +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
123
                        " Skins path assumed to be " + mydocuments +
124
                        "Rainmeter\\Skins\\")
125
        else:
126
            mydocuments = os.path.join("C:\\Users",
127
                                       username,
128
                                       "Documents") + "\\"
129
130
            logger.info(__file__, "get_skins_path", "Found Windows Vista or higher." +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (86/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
131
                        " Skins path assumed to be " + mydocuments +
132
                        "Rainmeter\\Skins\\")
133
134
        logger.info(__file__, "get_skins_path", "Skin path guessed from user name" +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (84/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
135
                    " and Windows version")
136
        return os.path.join(mydocuments, "Rainmeter\\Skins") + "\\"
137