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
Branch master (88441b)
by thatsIch
01:31
created

folder_already_exists()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
1
# def find_
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 os
3
import re
4
import shutil
5
6
from ..path.skin_path_provider import get_cached_skin_path
7
8
9
def folder_already_exists(skin_folder):
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...
10
    skins_folder = get_cached_skin_path()
11
    inis = find_inis_in_folder(skin_folder)
12
    skin_name = os.path.basename(common_path(inis))
13
    target_skin_folder = os.path.join(skins_folder, skin_name)
14
15
    return os.path.exists(target_skin_folder)
16
17
18
def install_skin_folder_into_skins_folder(skin_folder):
0 ignored issues
show
Coding Style Naming introduced by
The name install_skin_folder_into_skins_folder 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...
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...
19
    skins_folder = get_cached_skin_path()
20
21
    inis = find_inis_in_folder(skin_folder)
22
    skin_name = os.path.basename(common_path(inis))
23
    resources_folders = find_resources_folders_in_folder(skin_folder)
24
25
    paths = []
26
    paths.extend(inis)
27
    paths.extend(resources_folders)
28
29
    target_skin_folder = os.path.join(skins_folder, skin_name)
30
31
    transposed_paths = transpose_paths(paths, target_skin_folder)
32
33
    return transposed_paths
34
35
36
# todo: problem because I mix files and folders -> easier to just transpose folders thus we need only copytree
37
def transpose_paths(paths, target):
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...
38
    commoner = common_path(paths)
39
40
    return shutil.copytree(commoner, target)
41
42
43
def common_path(paths):
44
    """
45
    Find skin root folder.
46
47
    The root folder is defined as the parent folder of the @Resources folder.
48
    Since this one is optional the next solution would be to use the least common parent from all inis
49
    """
50
    return os.path.dirname(os.path.commonprefix([p + os.path.sep for p in paths]))
51
52
53
def find_resources_folders_in_folder(folder):
0 ignored issues
show
Coding Style Naming introduced by
The name find_resources_folders_in_folder 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...
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...
54
    resources = []
55
    for root, directories, dummy_files in os.walk(folder):
56
        for directory in directories:
57
            if directory.lower() == "@resources":
58
                resources.append(os.path.join(os.path.abspath(root), directory))
59
60
    return resources
61
62
63
def find_resources_folder_in_folder(folder):
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...
64
    for root, directories, dummy_files in os.walk(folder):
65
        for directory in directories:
66
            if directory.lower() == "@resources":
67
                return os.path.join(os.path.abspath(root), directory)
68
69
70
NAME_PATTERN = re.compile(r"^\s*Name=(.+)$", re.IGNORECASE)
71
72
73
def find_skin_name_in_inis(inis):
74
    """
75
    Retrieve skin name in a configuration.
76
77
    A configuration can contain multiple skins.
78
    Each of them can contain a metadata with its real name,
79
    since due to the copying or zipping it could be skewed
80
    with informations like master or versioning.
81
    """
82
    for ini in inis:
83
        with open(ini, 'r') as ini_file_handler:
84
            for line in ini_file_handler:
85
                match = NAME_PATTERN.match(line)
86
                if match:
87
                    return match.group(1)
88
89
90
def find_inis_in_folder(folder):
91
    """
92
    Retrieve path of every file ending with .ini in folder.
93
94
    Returns the absolute path of each found file.
95
    """
96
    inis = []
97
98
    for root, dirs, files in os.walk(folder):
0 ignored issues
show
Unused Code introduced by
The variable dirs seems to be unused.
Loading history...
99
        for fil in files:
100
            if fil.endswith('.ini'):
101
                inis.append(os.path.join(os.path.abspath(root), fil))
102
103
    return inis
104