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 |
|
|
|
|
23
|
|
|
import os |
|
|
|
|
24
|
|
|
import sys |
|
|
|
|
25
|
|
|
import platform |
|
|
|
|
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() |
|
|
|
|
34
|
|
|
|
35
|
|
|
# Set the AMPs, plugins and export modules path |
36
|
|
|
work_path = os.path.realpath(os.path.dirname(__file__)) |
|
|
|
|
37
|
|
|
amps_path = os.path.realpath(os.path.join(work_path, 'amps')) |
|
|
|
|
38
|
|
|
plugins_path = os.path.realpath(os.path.join(work_path, 'plugins')) |
|
|
|
|
39
|
|
|
exports_path = os.path.realpath(os.path.join(work_path, 'exports')) |
|
|
|
|
40
|
|
|
sys_path = sys.path[:] |
|
|
|
|
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
|
|
|
|