Test Failed
Push — develop ( 66c9ff...e21229 )
by Nicolas
05:06
created

glances.globals.safe_makedirs()   A

Complexity

Conditions 4

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of Glances.
4
#
5
# Copyright (C) 2019 Nicolargo <[email protected]>
6
#
7
# Glances is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU Lesser General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Glances is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
16
#
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
"""Common objects shared by all Glances modules."""
21
22
import errno
0 ignored issues
show
introduced by
import missing from __future__ import absolute_import
Loading history...
23
import os
0 ignored issues
show
introduced by
import missing from __future__ import absolute_import
Loading history...
24
import sys
0 ignored issues
show
introduced by
import missing from __future__ import absolute_import
Loading history...
25
import platform
0 ignored issues
show
introduced by
import missing from __future__ import absolute_import
Loading history...
26
27
# OS constants (some libraries/features are OS-dependent)
28
BSD = sys.platform.find('bsd') != -1
29
LINUX = sys.platform.startswith('linux')
30
MACOS = sys.platform.startswith('darwin')
31
SUNOS = sys.platform.startswith('sunos')
32
WINDOWS = sys.platform.startswith('win')
33
WSL = "linux" in platform.system().lower() and "microsoft" in platform.uname()[3].lower()
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (89/80).

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

Loading history...
34
35
# Set the AMPs, plugins and export modules path
36
work_path = os.path.realpath(os.path.dirname(__file__))
0 ignored issues
show
Coding Style Naming introduced by
The name work_path 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...
37
amps_path = os.path.realpath(os.path.join(work_path, 'amps'))
0 ignored issues
show
Coding Style Naming introduced by
The name amps_path 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...
38
plugins_path = os.path.realpath(os.path.join(work_path, 'plugins'))
0 ignored issues
show
Coding Style Naming introduced by
The name plugins_path 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...
39
exports_path = os.path.realpath(os.path.join(work_path, 'exports'))
0 ignored issues
show
Coding Style Naming introduced by
The name exports_path 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...
40
sys_path = sys.path[:]
0 ignored issues
show
Coding Style Naming introduced by
The name sys_path 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...
41
sys.path.insert(1, exports_path)
42
sys.path.insert(1, plugins_path)
43
sys.path.insert(1, amps_path)
44
45
46
def safe_makedirs(path):
47
    """A safe function for creating a directory tree."""
48
    try:
49
        os.makedirs(path)
50
    except OSError as err:
51
        if err.errno == errno.EEXIST:
52
            if not os.path.isdir(path):
53
                raise
54
        else:
55
            raise
56