Completed
Push — master ( 291ee9...9d841e )
by Matěj
20s queued 12s
created

ssg._products.map_name()   F

Complexity

Conditions 17

Size

Total Lines 44
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 38
nop 1
dl 0
loc 44
rs 2.7204
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like ssg._products.map_name() 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 re
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
3
# SSG Makefile to official product name mapping
4
CHROMIUM = 'Google Chromium Browser'
5
FEDORA = 'Fedora'
6
FIREFOX = 'Mozilla Firefox'
7
JRE = 'Java Runtime Environment'
8
RHEL = 'Red Hat Enterprise Linux'
9
DEBIAN = 'Debian'
10
UBUNTU = 'Ubuntu'
11
EAP = 'JBoss Enterprise Application Platform'
12
FUSE = 'JBoss Fuse'
13
OPENSUSE = 'openSUSE'
14
SUSE = 'SUSE Linux Enterprise'
15
WRLINUX = 'Wind River Linux'
16
OL = 'Oracle Linux'
17
OCP = 'Red Hat OpenShift Container Platform'
18
19
multi_list = ["rhel", "fedora", "rhel-osp", "debian", "ubuntu",
0 ignored issues
show
Coding Style Naming introduced by
The name multi_list does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

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...
20
              "wrlinux", "opensuse", "sle", "ol", "ocp"]
21
22
PRODUCT_NAME_PARSER = re.compile("([a-zA-Z\-]+)([0-9]+)")
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \- 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...
23
24
25
def parse_name(product):
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...
26
    product_version = None
27
    match = PRODUCT_NAME_PARSER.match(product)
28
29
    if match is not None:
30
        if isinstance(match.group(1), str) or \
0 ignored issues
show
Unused Code introduced by
Consider merging these isinstance calls to isinstance(match.group(1), (str, unicode))
Loading history...
31
                isinstance(match.group(1), unicode):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable unicode does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'unicode'
Loading history...
32
            product = match.group(1)
33
        if match.group(2).isdigit():
34
            product_version = match.group(2)
35
36
    return product, product_version
37
38
39
def map_name(version):
0 ignored issues
show
best-practice introduced by
Too many return statements (15/6)
Loading history...
40
    """Maps SSG Makefile internal product name to official product name"""
41
42
    if version.startswith("multi_platform_"):
43
        trimmed_version = version[len("multi_platform_"):]
44
        if trimmed_version not in multi_list:
45
            raise RuntimeError(
46
                "%s is an invalid product version. If it's multi_platform the "
47
                "suffix has to be from (%s)."
48
                % (version, ", ".join(multi_list))
49
            )
50
        return map_name(trimmed_version)
51
52
    if version.startswith("chromium"):
53
        return CHROMIUM
54
    if version.startswith("fedora"):
55
        return FEDORA
56
    if version.startswith("firefox"):
57
        return FIREFOX
58
    if version.startswith("jre"):
59
        return JRE
60
    if version.startswith("rhel"):
61
        return RHEL
62
    if version.startswith("debian"):
63
        return DEBIAN
64
    if version.startswith("ubuntu"):
65
        return UBUNTU
66
    if version.startswith("eap"):
67
        return EAP
68
    if version.startswith("fuse"):
69
        return FUSE
70
    if version.startswith("opensuse"):
71
        return OPENSUSE
72
    if version.startswith("sle"):
73
        return SUSE
74
    if version.startswith("wrlinux"):
75
        return WRLINUX
76
    if version.startswith("ol"):
77
        return OL
78
    if version.startswith("ocp"):
79
        return OCP
80
81
    raise RuntimeError("Can't map version '%s' to any known product!"
82
                       % (version))
83