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)
This commit is contained in:
Alessio Sergi 2014-06-09 19:19:19 +02:00
parent 441772b897
commit 6a55000547
31 changed files with 80 additions and 83 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -40,7 +40,7 @@ except NameError:
pass
class glancesPassword:
class GlancesPassword(object):
"""
Manage password
"""

View File

@ -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
"""

View File

@ -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
"""

View File

@ -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):
"""

View File

@ -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

View File

@ -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):
"""

View File

@ -27,7 +27,7 @@ except ImportError:
sys.exit(1)
class glancesBottle:
class GlancesBottle(object):
"""
This class manage the Bottle Web Server
"""

View File

@ -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"]

View File

@ -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
"""

View File

@ -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.__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...

View File

@ -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
"""

View File

@ -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):
"""

View File

@ -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

View File

@ -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):
"""

View File

@ -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

View File

@ -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
"""

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):
"""

View File

@ -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):
"""

View File

@ -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
"""

View File

@ -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

View File

@ -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