提交 6a550005 编写于 作者: A Alessio Sergi

Fix naming convention

Use CapWords convention for class names
Use new-style classes
Use lowercase with underscore for function and local variable names
(to be continued)
上级 441772b8
......@@ -32,10 +32,10 @@ except ImportError: # Python 2
# Import Glances libs
from glances.core.glances_globals import version
from glances.core.glances_stats import GlancesStatsClient
from glances.outputs.glances_curses import glancesCurses
from glances.outputs.glances_curses import GlancesCurses
class GlancesClient():
class GlancesClient(object):
"""
This class creates and manages the TCP client
"""
......@@ -126,7 +126,7 @@ class GlancesClient():
self.stats.load_limits(self.config)
# Init screen
self.screen = glancesCurses(args=self.args)
self.screen = GlancesCurses(args=self.args)
# Return result
return ret
......@@ -201,4 +201,3 @@ class GlancesClient():
End of the client session
"""
self.screen.end()
......@@ -60,9 +60,9 @@ else:
# ============================================
# glances_processes for processcount and processlist plugins
from glances.core.glances_processes import glancesProcesses
glances_processes = glancesProcesses()
from glances.core.glances_processes import GlancesProcesses
glances_processes = GlancesProcesses()
# The global instance for the logs
from glances.core.glances_logs import glancesLogs
glances_logs = glancesLogs()
from glances.core.glances_logs import GlancesLogs
glances_logs = GlancesLogs()
......@@ -25,7 +25,7 @@ from datetime import datetime
from glances.core.glances_globals import glances_processes
class glancesLogs:
class GlancesLogs(object):
"""
Manage logs inside the Glances software
Logs is a list of list (stored in the self.logs_list var)
......
......@@ -175,9 +175,9 @@ class GlancesMain(object):
"""
Hash a plain password and return the hashed one
"""
from glances.core.glances_password import glancesPassword
from glances.core.glances_password import GlancesPassword
password = glancesPassword()
password = GlancesPassword()
return password.hash_password(plain_password)
......@@ -187,9 +187,9 @@ class GlancesMain(object):
- with confirmation if confirm = True
- plain (clear password) if clear = True
"""
from glances.core.glances_password import glancesPassword
from glances.core.glances_password import GlancesPassword
password = glancesPassword()
password = GlancesPassword()
return password.get_password(description, confirm, clear)
......
......@@ -25,7 +25,7 @@ import subprocess
from glances.core.glances_globals import glances_processes
class monitorList:
class MonitorList(object):
"""
This class describes the optionnal monitored processes list
A list of 'important' processes to monitor.
......@@ -52,11 +52,11 @@ class monitorList:
if self.config is not None and self.config.has_section('monitor'):
# Process monitoring list
self.__setMonitorList('monitor', 'list')
self.__set_monitor_list('monitor', 'list')
else:
self.__monitor_list = []
def __setMonitorList(self, section, key):
def __set_monitor_list(self, section, key):
"""
Init the monitored processes list
The list is defined in the Glances configuration file
......
......@@ -40,7 +40,7 @@ except NameError:
pass
class glancesPassword:
class GlancesPassword(object):
"""
Manage password
"""
......
......@@ -17,14 +17,13 @@
# 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/>.
import psutil
# Import Glances lib
from glances.core.glances_globals import is_bsd, is_mac, is_windows
from glances.core.glances_timer import Timer, getTimeSinceLastUpdate
import psutil
class glancesProcesses:
class GlancesProcesses(object):
"""
Get processed stats using the PsUtil lib
"""
......
......@@ -65,22 +65,22 @@ class GlancesXMLRPCHandler(SimpleXMLRPCRequestHandler):
assert basic == 'Basic', 'Only basic authentication supported'
# Encoded portion of the header is a string
# Need to convert to bytestring
encodedByteString = encoded.encode()
encoded_byte_string = encoded.encode()
# Decode Base64 byte String to a decoded Byte String
decodedBytes = b64decode(encodedByteString)
decoded_bytes = b64decode(encoded_byte_string)
# Convert from byte string to a regular String
decodedString = decodedBytes.decode()
decoded_string = decoded_bytes.decode()
# Get the username and password from the string
(username, _, password) = decodedString.partition(':')
(username, _, password) = decoded_string.partition(':')
# Check that username and password match internal global dictionary
return self.check_user(username, password)
def check_user(self, username, password):
# Check username and password in the dictionnary
if username in self.server.user_dict:
from glances.core.glances_password import glancesPassword
from glances.core.glances_password import GlancesPassword
pwd = glancesPassword()
pwd = GlancesPassword()
return pwd.check_password(self.server.user_dict[username], password)
else:
......@@ -119,7 +119,7 @@ class GlancesXMLRPCServer(SimpleXMLRPCServer):
requestHandler)
class GlancesInstance():
class GlancesInstance(object):
"""
All the methods of this class are published as XML RPC methods
"""
......@@ -189,7 +189,7 @@ class GlancesInstance():
raise AttributeError(item)
class GlancesServer():
class GlancesServer(object):
"""
This class creates and manages the TCP server
"""
......
......@@ -19,10 +19,10 @@
# Import Glances libs
from glances.core.glances_stats import GlancesStats
from glances.outputs.glances_curses import glancesCurses
from glances.outputs.glances_curses import GlancesCurses
class GlancesStandalone():
class GlancesStandalone(object):
"""
This class creates and manages the Glances standalone session
"""
......@@ -37,15 +37,15 @@ class GlancesStandalone():
# Init CSV output
if args.output_csv is not None:
from glances.outputs.glances_csv import glancesCSV
from glances.outputs.glances_csv import GlancesCSV
self.csvoutput = glancesCSV(args=args)
self.csvoutput = GlancesCSV(args=args)
self.csv_tag = True
else:
self.csv_tag = False
# Init screen
self.screen = glancesCurses(args=args)
self.screen = GlancesCurses(args=args)
def serve_forever(self):
"""
......
......@@ -36,7 +36,7 @@ def getTimeSinceLastUpdate(IOType):
return time_since_update
class Timer:
class Timer(object):
"""
The timer class
A simple chrono
......@@ -57,4 +57,3 @@ class Timer:
def finished(self):
return time() > self.target
......@@ -22,10 +22,10 @@ Glances Web Interface (Bottle based)
# Import Glances libs
from glances.core.glances_stats import GlancesStats
from glances.outputs.glances_bottle import glancesBottle
from glances.outputs.glances_bottle import GlancesBottle
class GlancesWebServer():
class GlancesWebServer(object):
"""
This class creates and manages the Glances Web Server session
"""
......@@ -39,7 +39,7 @@ class GlancesWebServer():
self.stats.update()
# Init the Bottle Web server
self.web = glancesBottle(args=args)
self.web = GlancesBottle(args=args)
def serve_forever(self):
"""
......
......@@ -27,7 +27,7 @@ except ImportError:
sys.exit(1)
class glancesBottle:
class GlancesBottle(object):
"""
This class manage the Bottle Web Server
"""
......@@ -186,7 +186,7 @@ class glancesBottle:
if m['msg'].split(' ', 1)[0] != '':
tpl += '<span class="cell" id="%s">&nbsp;%s</span>' % \
(self.__style_list[m['decoration']],
m['msg'].split(' ', 1)[0].replace(' ', '&nbsp;')[:20])
m['msg'].split(' ', 1)[0].replace(' ', '&nbsp;')[:20])
elif m['optional']:
# Manage optional stats (responsive design)
tpl += '<span class="cell hide" id="%s">%s</span>' % \
......
......@@ -59,7 +59,7 @@ class ListenGetch(threading.Thread):
return default
class Screen():
class Screen(object):
COLOR_DEFAULT_WIN = '0F' # 07'#'0F'
COLOR_BK_DEFAULT = colorconsole.terminal.colors["BLACK"]
......@@ -116,7 +116,7 @@ class Screen():
return None
class WCurseLight():
class WCurseLight(object):
COLOR_WHITE = colorconsole.terminal.colors["WHITE"]
COLOR_RED = colorconsole.terminal.colors["RED"]
......
......@@ -28,7 +28,7 @@ from glances.core.glances_globals import is_py3
csv_stats_list = ['cpu', 'load', 'mem', 'memswap']
class glancesCSV:
class GlancesCSV(object):
"""
This class manages the CSV output
"""
......
......@@ -37,7 +37,7 @@ else:
curses = WCurseLight()
class glancesCurses:
class GlancesCurses(object):
"""
This class manage the curses display (and key pressed)
"""
......@@ -160,7 +160,7 @@ class glancesCurses:
self.term_window.nodelay(1)
self.pressedkey = -1
def __getkey(self, window):
def __get_key(self, window):
"""
A getKey function to catch ESC key AND Numlock key (issue #163)
"""
......@@ -174,10 +174,10 @@ class glancesCurses:
else:
return keycode[0]
def __catchKey(self):
def __catch_key(self):
# Get key
#~ self.pressedkey = self.term_window.getch()
self.pressedkey = self.__getkey(self.term_window)
# ~ self.pressedkey = self.term_window.getch()
self.pressedkey = self.__get_key(self.term_window)
# Actions...
if self.pressedkey == ord('\x1b') or self.pressedkey == ord('q'):
......@@ -456,7 +456,7 @@ class glancesCurses:
countdown = Timer(self.__refresh_time)
while (not countdown.finished()):
# Getkey
if self.__catchKey() > -1:
if self.__catch_key() > -1:
# flush display
self.flush(stats, cs_status=cs_status)
# Wait 100ms...
......
......@@ -41,7 +41,7 @@ class Plugin(GlancesPlugin):
GlancesPlugin.__init__(self, args=args)
# Init the sensor class
self.glancesgrabbat = glancesGrabBat()
self.glancesgrabbat = GlancesGrabBat()
# We do not want to display the stat in a dedicated area
# The HDD temp is displayed within the sensors plugin
......@@ -78,7 +78,7 @@ class Plugin(GlancesPlugin):
return self.stats
class glancesGrabBat:
class GlancesGrabBat(object):
"""
Get batteries stats using the Batinfo library
"""
......
......@@ -17,10 +17,10 @@
# 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/>.
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
class Plugin(GlancesPlugin):
"""
......
......@@ -20,10 +20,10 @@
Glances CPU plugin
"""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
# percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
......
......@@ -20,12 +20,12 @@
Glances DiskIO plugin
"""
import psutil
# Import Glances libs
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
class Plugin(GlancesPlugin):
"""
......
......@@ -17,10 +17,10 @@
# 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/>.
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# The snmpd.conf needs to be edited.
# Add the following to enable it on all disk
......
......@@ -35,7 +35,7 @@ class Plugin(GlancesPlugin):
GlancesPlugin.__init__(self, args=args)
# Init the sensor class
self.glancesgrabhddtemp = glancesGrabHDDTemp()
self.glancesgrabhddtemp = GlancesGrabHDDTemp()
# We do not want to display the stat in a dedicated area
# The HDD temp is displayed within the sensors plugin
......@@ -70,7 +70,7 @@ class Plugin(GlancesPlugin):
return self.stats
class glancesGrabHDDTemp:
class GlancesGrabHDDTemp(object):
"""
Get hddtemp stats using a socket connection
"""
......
......@@ -20,10 +20,10 @@
Glances virtual memory plugin
"""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
# Total RAM used: .1.3.6.1.4.1.2021.4.6.0
......
......@@ -20,10 +20,10 @@
Glances swap memory plugin
"""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
# Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
......
......@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import Glances lib
from glances.core.glances_monitor_list import monitorList as glancesMonitorList
from glances.core.glances_monitor_list import MonitorList as glancesMonitorList
from glances.plugins.glances_plugin import GlancesPlugin
......
......@@ -20,13 +20,11 @@
Glances Network interface plugin
"""
# Import system libs
import psutil
# Import Glances lib
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# http://www.net-snmp.org/docs/mibs/interfaces.html
# Dict key = interface_name
......@@ -169,7 +167,7 @@ class Plugin(GlancesPlugin):
Return the dict to displayoid in the curse interface
"""
#!!! TODO: Add alert on network interface bitrate
# !!! TODO: Add alert on network interface bitrate
# Init the return message
ret = []
......
......@@ -20,12 +20,12 @@
CPU stats (per cpu)
"""
# Check for psutil already done in the glances_core script
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
# Check for psutil already done in the glances_core script
import psutil
class Plugin(GlancesPlugin):
"""
......
......@@ -256,7 +256,7 @@ class GlancesPlugin(object):
def get_stats_display(self, args=None):
# Return a dict with all the information needed to display the stat
# key | description
#----------------------------
# ----------------------------
# display | Display the stat (True or False)
# msgdict | Message to display (list of dict [{ 'msg': msg, 'decoration': decoration } ... ])
# column | column number
......
......@@ -17,10 +17,10 @@
# 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/>.
from psutil import __version__ as __psutil_version
from glances.plugins.glances_plugin import GlancesPlugin
from psutil import __version__ as __psutil_version
class Plugin(GlancesPlugin):
"""
......
......@@ -44,7 +44,7 @@ class Plugin(GlancesPlugin):
GlancesPlugin.__init__(self, args=args)
# Init the sensor class
self.glancesgrabsensors = glancesGrabSensors()
self.glancesgrabsensors = GlancesGrabSensors()
# Instance for the HDDTemp Plugin in order to display the hard disks temperatures
self.hddtemp_plugin = HddTempPlugin()
......@@ -143,7 +143,7 @@ class Plugin(GlancesPlugin):
return ret
class glancesGrabSensors:
class GlancesGrabSensors(object):
"""
Get sensors stats using the PySensors library
"""
......
......@@ -31,6 +31,7 @@ from glances.plugins.glances_plugin import GlancesPlugin
snmp_oid = {'hostname': '1.3.6.1.2.1.1.5.0',
'os_name': '1.3.6.1.2.1.1.1.0'}
class Plugin(GlancesPlugin):
"""
Glances' Host/System Plugin
......
......@@ -20,15 +20,16 @@
# Import system libs
from datetime import datetime, timedelta
# Check for psutil already done in the glances_core script
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
# Check for psutil already done in the glances_core script
import psutil
# SNMP OID
snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'}
class Plugin(GlancesPlugin):
"""
Glances' Uptime Plugin
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册