mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-13 10:07:36 +03:00
Merge compat into globals
This commit is contained in:
parent
76ea71f256
commit
cb68d216d2
@ -8,7 +8,6 @@ https://glances.readthedocs.io/en/stable/
|
||||
__init__.py Global module init
|
||||
__main__.py Entry point for Glances module
|
||||
config.py Manage the configuration file
|
||||
compat.py Python2/3 compatibility shims module
|
||||
globals.py Share variables upon modules
|
||||
main.py Main script to rule them up...
|
||||
client.py Glances client
|
||||
|
@ -32,7 +32,7 @@ The return string is a string with one or more line (\n between lines).
|
||||
If the *one_line* var is true then the AMP will be displayed in one line.
|
||||
"""
|
||||
|
||||
from glances.compat import u, b, n, nativestr
|
||||
from glances.globals import u, b, n, nativestr
|
||||
from glances.timer import Timer
|
||||
from glances.logger import logger
|
||||
|
||||
|
@ -37,7 +37,7 @@ command=foo status
|
||||
|
||||
from subprocess import check_output, STDOUT, CalledProcessError
|
||||
|
||||
from glances.compat import u, to_ascii
|
||||
from glances.globals import u, to_ascii
|
||||
from glances.logger import logger
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
|
||||
|
@ -48,7 +48,7 @@ systemctl_cmd=/usr/bin/systemctl --plain
|
||||
from subprocess import check_output, CalledProcessError
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iteritems, to_ascii
|
||||
from glances.globals import iteritems, to_ascii
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
|
||||
|
||||
|
@ -47,7 +47,7 @@ service_cmd=/usr/bin/service --status-all
|
||||
from subprocess import check_output, STDOUT
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
from glances.amps.glances_amp import GlancesAmp
|
||||
|
||||
|
||||
|
@ -23,9 +23,8 @@ import os
|
||||
import re
|
||||
import threading
|
||||
|
||||
from glances.compat import listkeys, iteritems
|
||||
from glances.globals import listkeys, iteritems, amps_path
|
||||
from glances.logger import logger
|
||||
from glances.globals import amps_path
|
||||
from glances.processes import glances_processes
|
||||
|
||||
|
||||
@ -112,7 +111,7 @@ class AmpsList(object):
|
||||
if not v.enable():
|
||||
# Do not update if the enable tag is set
|
||||
continue
|
||||
|
||||
|
||||
if v.regex() is None:
|
||||
# If there is no regex, execute anyway (see issue #1690)
|
||||
v.set_count(0)
|
||||
|
@ -24,7 +24,7 @@ import socket
|
||||
import sys
|
||||
|
||||
from glances import __version__
|
||||
from glances.compat import Fault, ProtocolError, ServerProxy, Transport
|
||||
from glances.globals import Fault, ProtocolError, ServerProxy, Transport
|
||||
from glances.logger import logger
|
||||
from glances.stats_client import GlancesStatsClient
|
||||
from glances.outputs.glances_curses import GlancesCursesClient
|
||||
|
@ -23,7 +23,7 @@ import json
|
||||
import socket
|
||||
import threading
|
||||
|
||||
from glances.compat import Fault, ProtocolError, ServerProxy
|
||||
from glances.globals import Fault, ProtocolError, ServerProxy
|
||||
from glances.client import GlancesClient, GlancesClientTransport
|
||||
from glances.logger import logger, LOG_FILENAME
|
||||
from glances.password_list import GlancesPasswordList as GlancesPassword
|
||||
|
@ -1,212 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Glances.
|
||||
#
|
||||
# Copyright (C) 2021 Nicolargo <nicolas@nicolargo.com>
|
||||
#
|
||||
# Glances is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Glances is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# flake8: noqa
|
||||
# pylint: skip-file
|
||||
|
||||
# TODO: merge this file with the globals.py
|
||||
# Not needed anymore because only Python 3 is supported.
|
||||
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import operator
|
||||
import sys
|
||||
import unicodedata
|
||||
import types
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
from glances.logger import logger
|
||||
|
||||
import queue
|
||||
from configparser import ConfigParser, NoOptionError, NoSectionError
|
||||
from statistics import mean
|
||||
from xmlrpc.client import Fault, ProtocolError, ServerProxy, Transport, Server
|
||||
from xmlrpc.server import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
||||
from urllib.request import urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
# Correct issue #1025 by monkey path the xmlrpc lib
|
||||
from defusedxml.xmlrpc import monkey_patch
|
||||
monkey_patch()
|
||||
|
||||
input = input
|
||||
range = range
|
||||
map = map
|
||||
|
||||
text_type = str
|
||||
binary_type = bytes
|
||||
bool_type = bool
|
||||
long = int
|
||||
|
||||
PermissionError = OSError
|
||||
|
||||
viewkeys = operator.methodcaller('keys')
|
||||
viewvalues = operator.methodcaller('values')
|
||||
viewitems = operator.methodcaller('items')
|
||||
|
||||
def printandflush(string):
|
||||
"""Print and flush (used by stdout* outputs modules)"""
|
||||
print(string, flush=True)
|
||||
|
||||
def to_ascii(s):
|
||||
"""Convert the bytes string to a ASCII string
|
||||
Usefull to remove accent (diacritics)"""
|
||||
if isinstance(s, binary_type):
|
||||
return s.decode()
|
||||
return s.encode('ascii', 'ignore').decode()
|
||||
|
||||
def listitems(d):
|
||||
return list(d.items())
|
||||
|
||||
def listkeys(d):
|
||||
return list(d.keys())
|
||||
|
||||
def listvalues(d):
|
||||
return list(d.values())
|
||||
|
||||
def iteritems(d):
|
||||
return iter(d.items())
|
||||
|
||||
def iterkeys(d):
|
||||
return iter(d.keys())
|
||||
|
||||
def itervalues(d):
|
||||
return iter(d.values())
|
||||
|
||||
def u(s, errors='replace'):
|
||||
if isinstance(s, text_type):
|
||||
return s
|
||||
return s.decode('utf-8', errors=errors)
|
||||
|
||||
def b(s, errors='replace'):
|
||||
if isinstance(s, binary_type):
|
||||
return s
|
||||
return s.encode('utf-8', errors=errors)
|
||||
|
||||
def n(s):
|
||||
'''Only in Python 2...
|
||||
from future.utils import bytes_to_native_str as n
|
||||
'''
|
||||
return s
|
||||
|
||||
def nativestr(s, errors='replace'):
|
||||
if isinstance(s, text_type):
|
||||
return s
|
||||
elif isinstance(s, (int, float)):
|
||||
return s.__str__()
|
||||
else:
|
||||
return s.decode('utf-8', errors=errors)
|
||||
|
||||
def system_exec(command):
|
||||
"""Execute a system command and return the result as a str"""
|
||||
try:
|
||||
res = subprocess.run(command.split(' '),
|
||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||
except Exception as e:
|
||||
logger.debug('Can not evaluate command {} ({})'.format(command, e))
|
||||
res = ''
|
||||
return res.rstrip()
|
||||
|
||||
|
||||
def subsample(data, sampling):
|
||||
"""Compute a simple mean subsampling.
|
||||
|
||||
Data should be a list of numerical itervalues
|
||||
|
||||
Return a subsampled list of sampling lenght
|
||||
"""
|
||||
if len(data) <= sampling:
|
||||
return data
|
||||
sampling_length = int(round(len(data) / float(sampling)))
|
||||
return [mean(data[s * sampling_length:(s + 1) * sampling_length]) for s in range(0, sampling)]
|
||||
|
||||
|
||||
def time_serie_subsample(data, sampling):
|
||||
"""Compute a simple mean subsampling.
|
||||
|
||||
Data should be a list of set (time, value)
|
||||
|
||||
Return a subsampled list of sampling length
|
||||
"""
|
||||
if len(data) <= sampling:
|
||||
return data
|
||||
t = [t[0] for t in data]
|
||||
v = [t[1] for t in data]
|
||||
sampling_length = int(round(len(data) / float(sampling)))
|
||||
t_subsampled = [t[s * sampling_length:(s + 1) * sampling_length][0] for s in range(0, sampling)]
|
||||
v_subsampled = [mean(v[s * sampling_length:(s + 1) * sampling_length]) for s in range(0, sampling)]
|
||||
return list(zip(t_subsampled, v_subsampled))
|
||||
|
||||
|
||||
def to_fahrenheit(celsius):
|
||||
"""Convert Celsius to Fahrenheit."""
|
||||
return celsius * 1.8 + 32
|
||||
|
||||
|
||||
def is_admin():
|
||||
"""
|
||||
https://stackoverflow.com/a/19719292
|
||||
@return: True if the current user is an 'Admin' whatever that
|
||||
means (root on Unix), otherwise False.
|
||||
Warning: The inner function fails unless you have Windows XP SP2 or
|
||||
higher. The failure causes a traceback to be printed and this
|
||||
function to return False.
|
||||
"""
|
||||
|
||||
if os.name == 'nt':
|
||||
import ctypes
|
||||
import traceback
|
||||
# WARNING: requires Windows XP SP2 or higher!
|
||||
try:
|
||||
return ctypes.windll.shell32.IsUserAnAdmin()
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return False
|
||||
else:
|
||||
# Check for root on Posix
|
||||
return os.getuid() == 0
|
||||
|
||||
|
||||
def key_exist_value_not_none(k, d):
|
||||
# Return True if:
|
||||
# - key k exists
|
||||
# - d[k] is not None
|
||||
return k in d and d[k] is not None
|
||||
|
||||
|
||||
def key_exist_value_not_none_not_v(k, d, v=''):
|
||||
# Return True if:
|
||||
# - key k exists
|
||||
# - d[k] is not None
|
||||
# - d[k] != v
|
||||
return k in d and d[k] is not None and d[k] != v
|
||||
|
||||
|
||||
def disable(class_name, var):
|
||||
"""Set disable_<var> to True in the class class_name."""
|
||||
setattr(class_name, 'enable_' + var, False)
|
||||
setattr(class_name, 'disable_' + var, True)
|
||||
|
||||
|
||||
def enable(class_name, var):
|
||||
"""Set disable_<var> to False in the class class_name."""
|
||||
setattr(class_name, 'enable_' + var, True)
|
||||
setattr(class_name, 'disable_' + var, False)
|
@ -25,8 +25,7 @@ import multiprocessing
|
||||
from io import open
|
||||
import re
|
||||
|
||||
from glances.compat import ConfigParser, NoOptionError, NoSectionError, system_exec
|
||||
from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS
|
||||
from glances.globals import ConfigParser, NoOptionError, NoSectionError, system_exec, BSD, LINUX, MACOS, SUNOS, WINDOWS
|
||||
from glances.logger import logger
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file is part of Glances.
|
||||
#
|
||||
# Copyright (C) 2019 Nicolargo <nicolas@nicolargo.com>
|
||||
# Copyright (C) 2021 Nicolargo <nicolas@nicolargo.com>
|
||||
#
|
||||
# Glances is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -22,7 +22,6 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from glances.compat import range
|
||||
from glances.processes import glances_processes, sort_stats
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ from numbers import Number
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
|
||||
from cassandra.auth import PlainTextAuthProvider
|
||||
from cassandra.cluster import Cluster
|
||||
|
@ -24,7 +24,7 @@ import csv
|
||||
import sys
|
||||
import time
|
||||
|
||||
from glances.compat import PY3, iterkeys, itervalues
|
||||
from glances.globals import PY3, iterkeys, itervalues
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -25,7 +25,7 @@ I am your father...
|
||||
|
||||
import json
|
||||
|
||||
from glances.compat import NoOptionError, NoSectionError, iteritems, iterkeys
|
||||
from glances.globals import NoOptionError, NoSectionError, iteritems, iterkeys
|
||||
from glances.logger import logger
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ import errno
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.timer import Timer
|
||||
from glances.compat import iteritems, time_serie_subsample
|
||||
from glances.globals import iteritems, time_serie_subsample
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
import sys
|
||||
from numbers import Number
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
from glances.compat import PY3, listkeys
|
||||
from glances.globals import PY3, listkeys
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import sys
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
from kafka import KafkaProducer
|
||||
|
@ -22,7 +22,6 @@
|
||||
import sys
|
||||
from numbers import Number
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -24,7 +24,7 @@ from numbers import Number
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
from glances.compat import iteritems, listkeys
|
||||
from glances.globals import iteritems, listkeys
|
||||
|
||||
from prometheus_client import start_http_server, Gauge
|
||||
|
||||
|
@ -24,7 +24,6 @@ import socket
|
||||
import sys
|
||||
from numbers import Number
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
from glances.compat import listkeys
|
||||
from glances.globals import listkeys
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -23,7 +23,6 @@ import socket
|
||||
import sys
|
||||
from numbers import Number
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
import sys
|
||||
from numbers import Number
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
from glances.compat import b
|
||||
from glances.globals import b
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
|
@ -23,7 +23,7 @@ from __future__ import unicode_literals
|
||||
import os
|
||||
|
||||
from glances.timer import Timer
|
||||
from glances.compat import range, nativestr
|
||||
from glances.globals import nativestr
|
||||
from glances.logger import logger
|
||||
|
||||
# Use the built-in version of scandir/walk if possible, otherwise
|
||||
|
@ -19,10 +19,36 @@
|
||||
|
||||
"""Common objects shared by all Glances modules."""
|
||||
|
||||
################
|
||||
# GLOBAL IMPORTS
|
||||
################
|
||||
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
import operator
|
||||
import unicodedata
|
||||
import types
|
||||
import subprocess
|
||||
|
||||
import queue
|
||||
from configparser import ConfigParser, NoOptionError, NoSectionError
|
||||
from statistics import mean
|
||||
from xmlrpc.client import Fault, ProtocolError, ServerProxy, Transport, Server
|
||||
from xmlrpc.server import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
||||
from urllib.request import urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
# Correct issue #1025 by monkey path the xmlrpc lib
|
||||
from defusedxml.xmlrpc import monkey_patch
|
||||
monkey_patch()
|
||||
|
||||
|
||||
##############
|
||||
# GLOBALS VARS
|
||||
##############
|
||||
|
||||
# OS constants (some libraries/features are OS-dependent)
|
||||
BSD = sys.platform.find('bsd') != -1
|
||||
@ -42,6 +68,186 @@ sys.path.insert(1, exports_path)
|
||||
sys.path.insert(1, plugins_path)
|
||||
sys.path.insert(1, amps_path)
|
||||
|
||||
# Types
|
||||
text_type = str
|
||||
binary_type = bytes
|
||||
bool_type = bool
|
||||
long = int
|
||||
|
||||
# Alias errors
|
||||
PermissionError = OSError
|
||||
|
||||
# Alias methods
|
||||
viewkeys = operator.methodcaller('keys')
|
||||
viewvalues = operator.methodcaller('values')
|
||||
viewitems = operator.methodcaller('items')
|
||||
|
||||
|
||||
###################
|
||||
# GLOBALS FUNCTIONS
|
||||
###################
|
||||
|
||||
|
||||
def printandflush(string):
|
||||
"""Print and flush (used by stdout* outputs modules)"""
|
||||
print(string, flush=True)
|
||||
|
||||
|
||||
def to_ascii(s):
|
||||
"""Convert the bytes string to a ASCII string
|
||||
Usefull to remove accent (diacritics)"""
|
||||
if isinstance(s, binary_type):
|
||||
return s.decode()
|
||||
return s.encode('ascii', 'ignore').decode()
|
||||
|
||||
|
||||
def listitems(d):
|
||||
return list(d.items())
|
||||
|
||||
|
||||
def listkeys(d):
|
||||
return list(d.keys())
|
||||
|
||||
|
||||
def listvalues(d):
|
||||
return list(d.values())
|
||||
|
||||
|
||||
def iteritems(d):
|
||||
return iter(d.items())
|
||||
|
||||
|
||||
def iterkeys(d):
|
||||
return iter(d.keys())
|
||||
|
||||
|
||||
def itervalues(d):
|
||||
return iter(d.values())
|
||||
|
||||
|
||||
def u(s, errors='replace'):
|
||||
if isinstance(s, text_type):
|
||||
return s
|
||||
return s.decode('utf-8', errors=errors)
|
||||
|
||||
|
||||
def b(s, errors='replace'):
|
||||
if isinstance(s, binary_type):
|
||||
return s
|
||||
return s.encode('utf-8', errors=errors)
|
||||
|
||||
|
||||
def n(s):
|
||||
'''Only in Python 2...
|
||||
from future.utils import bytes_to_native_str as n
|
||||
'''
|
||||
return s
|
||||
|
||||
|
||||
def nativestr(s, errors='replace'):
|
||||
if isinstance(s, text_type):
|
||||
return s
|
||||
elif isinstance(s, (int, float)):
|
||||
return s.__str__()
|
||||
else:
|
||||
return s.decode('utf-8', errors=errors)
|
||||
|
||||
|
||||
def system_exec(command):
|
||||
"""Execute a system command and return the result as a str"""
|
||||
try:
|
||||
res = subprocess.run(command.split(' '),
|
||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||
except Exception as e:
|
||||
res = 'ERROR: {}'.format(e)
|
||||
return res.rstrip()
|
||||
|
||||
|
||||
def subsample(data, sampling):
|
||||
"""Compute a simple mean subsampling.
|
||||
|
||||
Data should be a list of numerical itervalues
|
||||
|
||||
Return a subsampled list of sampling lenght
|
||||
"""
|
||||
if len(data) <= sampling:
|
||||
return data
|
||||
sampling_length = int(round(len(data) / float(sampling)))
|
||||
return [mean(data[s * sampling_length:(s + 1) * sampling_length]) for s in range(0, sampling)]
|
||||
|
||||
|
||||
def time_serie_subsample(data, sampling):
|
||||
"""Compute a simple mean subsampling.
|
||||
|
||||
Data should be a list of set (time, value)
|
||||
|
||||
Return a subsampled list of sampling length
|
||||
"""
|
||||
if len(data) <= sampling:
|
||||
return data
|
||||
t = [t[0] for t in data]
|
||||
v = [t[1] for t in data]
|
||||
sampling_length = int(round(len(data) / float(sampling)))
|
||||
t_subsampled = [t[s * sampling_length:(s + 1) * sampling_length][0] for s in range(0, sampling)]
|
||||
v_subsampled = [mean(v[s * sampling_length:(s + 1) * sampling_length]) for s in range(0, sampling)]
|
||||
return list(zip(t_subsampled, v_subsampled))
|
||||
|
||||
|
||||
def to_fahrenheit(celsius):
|
||||
"""Convert Celsius to Fahrenheit."""
|
||||
return celsius * 1.8 + 32
|
||||
|
||||
|
||||
def is_admin():
|
||||
"""
|
||||
https://stackoverflow.com/a/19719292
|
||||
@return: True if the current user is an 'Admin' whatever that
|
||||
means (root on Unix), otherwise False.
|
||||
Warning: The inner function fails unless you have Windows XP SP2 or
|
||||
higher. The failure causes a traceback to be printed and this
|
||||
function to return False.
|
||||
"""
|
||||
|
||||
if os.name == 'nt':
|
||||
import ctypes
|
||||
import traceback
|
||||
# WARNING: requires Windows XP SP2 or higher!
|
||||
try:
|
||||
return ctypes.windll.shell32.IsUserAnAdmin()
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return False
|
||||
else:
|
||||
# Check for root on Posix
|
||||
return os.getuid() == 0
|
||||
|
||||
|
||||
def key_exist_value_not_none(k, d):
|
||||
# Return True if:
|
||||
# - key k exists
|
||||
# - d[k] is not None
|
||||
return k in d and d[k] is not None
|
||||
|
||||
|
||||
def key_exist_value_not_none_not_v(k, d, v=''):
|
||||
# Return True if:
|
||||
# - key k exists
|
||||
# - d[k] is not None
|
||||
# - d[k] != v
|
||||
return k in d and d[k] is not None and d[k] != v
|
||||
|
||||
|
||||
def disable(class_name, var):
|
||||
"""Set disable_<var> to True in the class class_name."""
|
||||
setattr(class_name, 'enable_' + var, False)
|
||||
setattr(class_name, 'disable_' + var, True)
|
||||
|
||||
|
||||
def enable(class_name, var):
|
||||
"""Set disable_<var> to False in the class class_name."""
|
||||
setattr(class_name, 'enable_' + var, True)
|
||||
setattr(class_name, 'disable_' + var, False)
|
||||
|
||||
|
||||
def safe_makedirs(path):
|
||||
"""A safe function for creating a directory tree."""
|
||||
|
@ -27,8 +27,7 @@ import tempfile
|
||||
import logging
|
||||
import logging.config
|
||||
|
||||
from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS, WSL
|
||||
from glances.globals import safe_makedirs
|
||||
from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS, WSL, safe_makedirs
|
||||
|
||||
# Choose the good place for the log file (see issue #1575)
|
||||
# Default root path
|
||||
|
@ -24,9 +24,8 @@ import sys
|
||||
import tempfile
|
||||
|
||||
from glances import __version__, psutil_version
|
||||
from glances.compat import input, disable, enable
|
||||
from glances.globals import WINDOWS, disable, enable
|
||||
from glances.config import Config
|
||||
from glances.globals import WINDOWS
|
||||
from glances.processes import sort_processes_key_list
|
||||
from glances.logger import logger, LOG_FILENAME
|
||||
|
||||
|
@ -28,9 +28,8 @@ import os
|
||||
from ssl import CertificateError
|
||||
|
||||
from glances import __version__
|
||||
from glances.compat import nativestr, urlopen, HTTPError, URLError
|
||||
from glances.globals import nativestr, urlopen, HTTPError, URLError, safe_makedirs
|
||||
from glances.config import user_cache_dir
|
||||
from glances.globals import safe_makedirs
|
||||
from glances.logger import logger
|
||||
|
||||
PYPI_API_URL = 'https://pypi.python.org/pypi/Glances/json'
|
||||
|
@ -28,7 +28,7 @@ import webbrowser
|
||||
import zlib
|
||||
import socket
|
||||
|
||||
from glances.compat import b
|
||||
from glances.globals import b
|
||||
from glances.timer import Timer
|
||||
from glances.logger import logger
|
||||
|
||||
|
@ -22,8 +22,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from glances.compat import nativestr, u, itervalues, enable, disable
|
||||
from glances.globals import MACOS, WINDOWS
|
||||
from glances.globals import MACOS, WINDOWS, nativestr, u, itervalues, enable, disable
|
||||
from glances.logger import logger
|
||||
from glances.events import glances_events
|
||||
from glances.processes import glances_processes, sort_processes_key_list
|
||||
|
@ -24,7 +24,7 @@ from __future__ import division
|
||||
import sys
|
||||
from math import modf
|
||||
from glances.logger import logger
|
||||
from glances.compat import nativestr
|
||||
from glances.globals import nativestr
|
||||
|
||||
sparklines_module = True
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import time
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import printandflush
|
||||
from glances.globals import printandflush
|
||||
|
||||
|
||||
class GlancesStdout(object):
|
||||
|
@ -24,7 +24,7 @@ import json
|
||||
import time
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
|
||||
API_URL = "http://localhost:61208/api/3"
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import time
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import printandflush
|
||||
from glances.globals import printandflush
|
||||
|
||||
|
||||
class GlancesStdoutCsv(object):
|
||||
|
@ -24,7 +24,7 @@ import sys
|
||||
import shutil
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import printandflush
|
||||
from glances.globals import printandflush
|
||||
from glances.timer import Counter
|
||||
from glances import __version__, psutil_version
|
||||
|
||||
|
@ -26,9 +26,8 @@ import sys
|
||||
import uuid
|
||||
from io import open
|
||||
|
||||
from glances.compat import b, input
|
||||
from glances.globals import b, safe_makedirs
|
||||
from glances.config import user_config_dir
|
||||
from glances.globals import safe_makedirs
|
||||
from glances.logger import logger
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""Monitor plugin."""
|
||||
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
from glances.amps_list import AmpsList as glancesAmpsList
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -25,7 +25,7 @@ Supported Cloud API:
|
||||
|
||||
import threading
|
||||
|
||||
from glances.compat import iteritems, to_ascii
|
||||
from glances.globals import iteritems, to_ascii
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.logger import logger
|
||||
|
||||
|
@ -22,7 +22,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.compat import nativestr
|
||||
from glances.globals import nativestr
|
||||
|
||||
import psutil
|
||||
|
||||
|
@ -21,9 +21,8 @@
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.compat import iterkeys
|
||||
from glances.globals import LINUX, iterkeys
|
||||
from glances.cpu_percent import cpu_percent
|
||||
from glances.globals import LINUX
|
||||
from glances.plugins.core import Plugin as CorePlugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
"""Disk I/O plugin."""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from glances.compat import nativestr, n
|
||||
from glances.globals import nativestr, n
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.logger import logger
|
||||
|
@ -25,7 +25,7 @@ import time
|
||||
from copy import deepcopy
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iterkeys, itervalues, nativestr
|
||||
from glances.globals import iterkeys, itervalues, nativestr
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.processes import sort_stats as sort_stats_processes, weighted, glances_processes
|
||||
|
@ -22,7 +22,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import numbers
|
||||
|
||||
from glances.compat import nativestr
|
||||
from glances.globals import nativestr
|
||||
from glances.folder_list import FolderList as glancesFolderList
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.logger import logger
|
||||
|
@ -22,7 +22,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import operator
|
||||
|
||||
from glances.compat import u, nativestr, PermissionError
|
||||
from glances.globals import u, nativestr, PermissionError
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
import psutil
|
||||
|
@ -28,7 +28,7 @@ import json
|
||||
import copy
|
||||
from operator import itemgetter
|
||||
|
||||
from glances.compat import iterkeys, itervalues, listkeys, map, mean, nativestr
|
||||
from glances.globals import iterkeys, itervalues, listkeys, mean, nativestr
|
||||
from glances.actions import GlancesActions
|
||||
from glances.history import GlancesHistory
|
||||
from glances.logger import logger
|
||||
|
@ -23,7 +23,7 @@ import psutil
|
||||
import warnings
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iteritems, to_fahrenheit
|
||||
from glances.globals import iteritems, to_fahrenheit
|
||||
from glances.timer import Counter
|
||||
from glances.plugins.sensors.glances_batpercent import Plugin as BatPercentPlugin
|
||||
from glances.plugins.sensors.glances_hddtemp import Plugin as HddTempPlugin
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""GPU plugin (limited to NVIDIA chipsets)."""
|
||||
|
||||
from glances.compat import nativestr, to_fahrenheit
|
||||
from glances.globals import nativestr, to_fahrenheit
|
||||
from glances.logger import logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import threading
|
||||
from json import loads
|
||||
|
||||
from glances.compat import iterkeys, urlopen, queue
|
||||
from glances.globals import iterkeys, urlopen, queue
|
||||
from glances.logger import logger
|
||||
from glances.timer import Timer
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
@ -22,7 +22,7 @@
|
||||
import os
|
||||
import psutil
|
||||
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
from glances.plugins.core import Plugin as CorePlugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.logger import logger
|
||||
|
@ -20,7 +20,7 @@
|
||||
"""Virtual memory plugin."""
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iterkeys
|
||||
from glances.globals import iterkeys
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
import psutil
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""Swap memory plugin."""
|
||||
|
||||
from glances.compat import iterkeys
|
||||
from glances.globals import iterkeys
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -24,7 +24,7 @@ import base64
|
||||
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.compat import n
|
||||
from glances.globals import n
|
||||
from glances.logger import logger
|
||||
|
||||
import psutil
|
||||
|
@ -26,11 +26,10 @@ import socket
|
||||
import time
|
||||
import numbers
|
||||
|
||||
from glances.globals import WINDOWS, MACOS, BSD
|
||||
from glances.globals import WINDOWS, MACOS, BSD, bool_type
|
||||
from glances.ports_list import GlancesPortsList
|
||||
from glances.web_list import GlancesWebList
|
||||
from glances.timer import Timer, Counter
|
||||
from glances.compat import bool_type
|
||||
from glances.logger import logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -23,8 +23,7 @@ import os
|
||||
import copy
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.globals import WINDOWS
|
||||
from glances.compat import key_exist_value_not_none_not_v
|
||||
from glances.globals import WINDOWS, key_exist_value_not_none_not_v
|
||||
from glances.processes import glances_processes, sort_stats
|
||||
from glances.plugins.core import Plugin as CorePlugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""RAID plugin."""
|
||||
|
||||
from glances.compat import iterkeys
|
||||
from glances.globals import iterkeys
|
||||
from glances.logger import logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import os
|
||||
import socket
|
||||
|
||||
from glances.compat import nativestr, range
|
||||
from glances.globals import nativestr
|
||||
from glances.logger import logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -47,7 +47,7 @@ If smartmontools is not installed, we should catch the error upstream in plugin
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.logger import logger
|
||||
from glances.main import disable
|
||||
from glances.compat import is_admin
|
||||
from glances.globals import is_admin
|
||||
|
||||
# Import plugin specific dependency
|
||||
try:
|
||||
|
@ -25,7 +25,7 @@ import re
|
||||
from io import open
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
# SNMP OID
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
import operator
|
||||
|
||||
from glances.compat import nativestr
|
||||
from glances.globals import nativestr
|
||||
from glances.logger import logger
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
"""Manage the Glances ports list (Ports plugin)."""
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.globals import BSD
|
||||
|
||||
|
@ -19,8 +19,7 @@
|
||||
|
||||
import os
|
||||
|
||||
from glances.compat import iterkeys
|
||||
from glances.globals import BSD, LINUX, MACOS, WINDOWS
|
||||
from glances.globals import BSD, LINUX, MACOS, WINDOWS, iterkeys
|
||||
from glances.timer import Timer, getTimeSinceLastUpdate
|
||||
from glances.filter import GlancesFilter
|
||||
from glances.logger import logger
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""Secures functions for Glances"""
|
||||
|
||||
from glances.compat import nativestr
|
||||
from glances.globals import nativestr
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ import sys
|
||||
from base64 import b64decode
|
||||
|
||||
from glances import __version__
|
||||
from glances.compat import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer, Server
|
||||
from glances.globals import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer, Server
|
||||
from glances.autodiscover import GlancesAutoDiscoverClient
|
||||
from glances.logger import logger
|
||||
from glances.stats_server import GlancesStatsServer
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
from socket import gaierror, gethostbyname
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
import re
|
||||
|
||||
from glances.stats import GlancesStats
|
||||
from glances.compat import iteritems
|
||||
from glances.globals import iteritems
|
||||
from glances.logger import logger
|
||||
|
||||
# SNMP OID regexp pattern to short system name dict
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""Manage the Glances web/url list (Ports plugin)."""
|
||||
|
||||
from glances.compat import range, urlparse
|
||||
from glances.globals import urlparse
|
||||
from glances.logger import logger
|
||||
|
||||
|
||||
@ -97,17 +97,17 @@ class GlancesWebList(object):
|
||||
|
||||
# Indice
|
||||
new_web['indice'] = 'web_' + str(i)
|
||||
|
||||
|
||||
# ssl_verify
|
||||
new_web['ssl_verify'] = config.get_value(self._section,
|
||||
new_web['ssl_verify'] = config.get_value(self._section,
|
||||
'%sssl_verify' % postfix,
|
||||
default=True)
|
||||
# Proxy
|
||||
http_proxy = config.get_value(self._section,
|
||||
http_proxy = config.get_value(self._section,
|
||||
'%shttp_proxy' % postfix,
|
||||
default=None)
|
||||
|
||||
https_proxy = config.get_value(self._section,
|
||||
|
||||
https_proxy = config.get_value(self._section,
|
||||
'%shttps_proxy' % postfix,
|
||||
default=None)
|
||||
|
||||
|
@ -28,7 +28,7 @@ import numbers
|
||||
import unittest
|
||||
|
||||
from glances import __version__
|
||||
from glances.compat import text_type
|
||||
from glances.globals import text_type
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -28,7 +28,7 @@ import time
|
||||
import unittest
|
||||
|
||||
from glances import __version__
|
||||
from glances.compat import ServerProxy
|
||||
from glances.globals import ServerProxy
|
||||
|
||||
SERVER_PORT = 61234
|
||||
URL = "http://localhost:%s" % SERVER_PORT
|
||||
|
@ -26,7 +26,7 @@ import unittest
|
||||
from glances.main import GlancesMain
|
||||
from glances.stats import GlancesStats
|
||||
from glances import __version__
|
||||
from glances.globals import WINDOWS, LINUX
|
||||
from glances.globals import WINDOWS, LINUX, subsample
|
||||
from glances.outputs.glances_bars import Bar
|
||||
from glances.thresholds import GlancesThresholdOk
|
||||
from glances.thresholds import GlancesThresholdCareful
|
||||
@ -34,7 +34,6 @@ from glances.thresholds import GlancesThresholdWarning
|
||||
from glances.thresholds import GlancesThresholdCritical
|
||||
from glances.thresholds import GlancesThresholds
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
from glances.compat import subsample, range
|
||||
from glances.secure import secure_popen
|
||||
|
||||
# Global variables
|
||||
@ -257,7 +256,7 @@ class TestGlances(unittest.TestCase):
|
||||
def test_016_hddsmart(self):
|
||||
"""Check hard disk SMART data plugin."""
|
||||
try:
|
||||
from glances.compat import is_admin
|
||||
from glances.globals import is_admin
|
||||
except ImportError:
|
||||
print("INFO: [TEST_016] pySMART not found, not running SMART plugin test")
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user