summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessio Sergi <al3hex@gmail.com>2014-06-13 19:00:00 +0200
committerAlessio Sergi <al3hex@gmail.com>2014-06-13 19:02:21 +0200
commitb5cac27e99b8f899e39ba9b0826cbcf35eda3bc3 (patch)
tree6fa0c925fa0f11ec2fd306c023df49069d0e20ee
parent51611928b9c99a75259bd440d450205a1614264e (diff)
PEP 257
One-line docstring should not occupy 3 lines Expected 1 blank line *before* class docstring First line should end with '.' Blank line missing between one-line summary and description No blank lines allowed *after* method docstring Use r""" if any backslashes in a docstring
-rw-r--r--glances/__init__.py16
-rw-r--r--glances/core/glances_client.py49
-rw-r--r--glances/core/glances_config.py32
-rw-r--r--glances/core/glances_globals.py2
-rw-r--r--glances/core/glances_logs.py50
-rw-r--r--glances/core/glances_main.py53
-rw-r--r--glances/core/glances_monitor_list.py70
-rw-r--r--glances/core/glances_password.py50
-rw-r--r--glances/core/glances_processes.py43
-rw-r--r--glances/core/glances_server.py57
-rw-r--r--glances/core/glances_snmp.py33
-rw-r--r--glances/core/glances_standalone.py16
-rw-r--r--glances/core/glances_stats.py92
-rw-r--r--glances/core/glances_timer.py9
-rw-r--r--glances/core/glances_webserver.py19
-rw-r--r--glances/outputs/glances_bottle.py37
-rw-r--r--glances/outputs/glances_csv.py12
-rw-r--r--glances/outputs/glances_curses.py50
-rw-r--r--glances/plugins/glances_alert.py22
-rw-r--r--glances/plugins/glances_batpercent.py36
-rw-r--r--glances/plugins/glances_core.py21
-rw-r--r--glances/plugins/glances_cpu.py23
-rw-r--r--glances/plugins/glances_diskio.py24
-rw-r--r--glances/plugins/glances_fs.py20
-rw-r--r--glances/plugins/glances_hddtemp.py43
-rw-r--r--glances/plugins/glances_help.py27
-rw-r--r--glances/plugins/glances_load.py24
-rw-r--r--glances/plugins/glances_mem.py23
-rw-r--r--glances/plugins/glances_memswap.py23
-rw-r--r--glances/plugins/glances_monitor.py23
-rw-r--r--glances/plugins/glances_network.py24
-rw-r--r--glances/plugins/glances_now.py15
-rw-r--r--glances/plugins/glances_percpu.py24
-rw-r--r--glances/plugins/glances_plugin.py119
-rw-r--r--glances/plugins/glances_processcount.py21
-rw-r--r--glances/plugins/glances_processlist.py25
-rw-r--r--glances/plugins/glances_psutilversion.py14
-rw-r--r--glances/plugins/glances_sensors.py50
-rw-r--r--glances/plugins/glances_system.py24
-rw-r--r--glances/plugins/glances_uptime.py22
-rwxr-xr-xunitest.py80
41 files changed, 544 insertions, 873 deletions
diff --git a/glances/__init__.py b/glances/__init__.py
index 28b22ebd..1337f13d 100644
--- a/glances/__init__.py
+++ b/glances/__init__.py
@@ -17,9 +17,7 @@
# 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/>.
-"""
-Init the Glances software
-"""
+"""Init the Glances software."""
__appname__ = 'glances'
__version__ = '2.0_RC4'
@@ -54,17 +52,12 @@ from glances.core.glances_main import GlancesMain
def __signal_handler(signal, frame):
- """
- Call back for CTRL-C
- """
+ """Callback for CTRL-C."""
end()
def end():
- """
- Stop Glances
- """
-
+ """Stop Glances."""
if core.is_standalone():
# Stop the standalone (CLI)
standalone.end()
@@ -80,8 +73,7 @@ def end():
def main():
- """
- Main entry point for Glances
+ """Main entry point for Glances.
Select the mode (standalone, client or server)
Run it...
diff --git a/glances/core/glances_client.py b/glances/core/glances_client.py
index 5e3f2c71..d2b05d97 100644
--- a/glances/core/glances_client.py
+++ b/glances/core/glances_client.py
@@ -16,9 +16,8 @@
#
# 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/>.
-"""
-Manage the Glances' client
-"""
+
+"""Manage the Glances client."""
# Import system libs
import json
@@ -36,9 +35,8 @@ from glances.outputs.glances_curses import GlancesCurses
class GlancesClient(object):
- """
- This class creates and manages the TCP client
- """
+
+ """This class creates and manages the TCP client."""
def __init__(self, config=None, args=None):
# Store the arg/config
@@ -63,8 +61,8 @@ class GlancesClient(object):
sys.exit(2)
def set_mode(self, mode='glances'):
- """
- Set the client mode
+ """Set the client mode.
+
- 'glances' = Glances server (default)
- 'snmp' = SNMP (fallback)
"""
@@ -72,18 +70,15 @@ class GlancesClient(object):
return self.mode
def get_mode(self):
- """
- Return the client mode
+ """Get the client mode.
+
- 'glances' = Glances server (default)
- 'snmp' = SNMP (fallback)
"""
return self.mode
def login(self):
- """
- Logon to the server
- """
-
+ """Logon to the server."""
ret = True
# First of all, trying to connect to a Glances server
@@ -132,13 +127,7 @@ class GlancesClient(object):
return ret
def update(self):
- """
- Get stats from server
- Return the client/server connection status:
- - Connected: Connection OK
- - Disconnected: Connection NOK
- """
- # Update the stats
+ """Update stats from Glances/SNMP server."""
if self.get_mode() == 'glances':
return self.update_glances()
elif self.get_mode() == 'snmp':
@@ -148,8 +137,8 @@ class GlancesClient(object):
sys.exit(2)
def update_glances(self):
- """
- Get stats from Glances server
+ """Get stats from Glances server.
+
Return the client/server connection status:
- Connected: Connection OK
- Disconnected: Connection NOK
@@ -159,7 +148,7 @@ class GlancesClient(object):
server_stats = json.loads(self.client.getAll())
server_stats['monitor'] = json.loads(self.client.getAllMonitored())
except socket.error:
- # Client can not get server stats
+ # Client cannot get server stats
return "Disconnected"
else:
# Put it in the internal dict
@@ -167,8 +156,8 @@ class GlancesClient(object):
return "Connected"
def update_snmp(self):
- """
- Get stats from SNMP server
+ """Get stats from SNMP server.
+
Return the client/server connection status:
- SNMP: Connection with SNMP server OK
- Disconnected: Connection NOK
@@ -184,9 +173,7 @@ class GlancesClient(object):
return "SNMP"
def serve_forever(self):
- """
- Main client loop
- """
+ """Main client loop."""
while True:
# Update the stats
cs_status = self.update()
@@ -197,7 +184,5 @@ class GlancesClient(object):
# print self.stats.getAll()
def end(self):
- """
- End of the client session
- """
+ """End of the client session."""
self.screen.end()
diff --git a/glances/core/glances_config.py b/glances/core/glances_config.py
index 030f3571..6db373ea 100644
--- a/glances/core/glances_config.py
+++ b/glances/core/glances_config.py
@@ -17,6 +17,8 @@
# 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/>.
+"""Manage the configuration file."""
+
# Import system libs
import os
import sys
@@ -41,8 +43,8 @@ from glances.core.glances_globals import (
class Config(object):
- """
- This class is used to access/read config file, if it exists
+
+ """This class is used to access/read config file, if it exists.
:param location: the custom path to search for config file
:type location: str or None
@@ -56,9 +58,7 @@ class Config(object):
self.load()
def load(self):
- """
- Load a config file from the list of paths, if it exists
- """
+ """Load a config file from the list of paths, if it exists."""
for config_file in self.get_config_paths():
if os.path.isfile(config_file) and os.path.getsize(config_file) > 0:
try:
@@ -73,9 +73,9 @@ class Config(object):
break
def get_config_paths(self):
- """
- Get a list of config file paths, taking into account of the OS,
- priority and location.
+ r"""Get a list of config file paths.
+
+ The list is built taking into account of the OS, priority and location.
* running from source: /path/to/glances/conf
* Linux: ~/.config/glances, /etc/glances
@@ -119,21 +119,15 @@ class Config(object):
return paths
def items(self, section):
- """
- Return the items list of a section
- """
+ """Return the items list of a section."""
return self.parser.items(section)
def has_section(self, section):
- """
- Return info about the existence of a section
- """
+ """Return info about the existence of a section."""
return self.parser.has_section(section)
def get_option(self, section, option):
- """
- Get the float value of an option, if it exists
- """
+ """Get the float value of an option, if it exists."""
try:
value = self.parser.getfloat(section, option)
except NoOptionError:
@@ -142,9 +136,7 @@ class Config(object):
return value
def get_raw_option(self, section, option):
- """
- Get the raw value of an option, if it exists
- """
+ """Get the raw value of an option, if it exists."""
try:
value = self.parser.get(section, option)
except NoOptionError:
diff --git a/glances/core/glances_globals.py b/glances/core/glances_globals.py
index 5b46cee4..3601adb9 100644
--- a/glances/core/glances_globals.py
+++ b/glances/core/glances_globals.py
@@ -17,6 +17,8 @@
# 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/>.
+"""Common objects shared by all Glances modules."""
+
import os
import sys
diff --git a/glances/core/glances_logs.py b/glances/core/glances_logs.py
index 99f97cc0..393ef626 100644
--- a/glances/core/glances_logs.py
+++ b/glances/core/glances_logs.py
@@ -17,6 +17,8 @@
# 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/>.
+"""Manage logs."""
+
# Import system libs
import time
from datetime import datetime
@@ -26,13 +28,14 @@ from glances.core.glances_globals import glances_processes
class GlancesLogs(object):
- """
- Manage logs inside the Glances software
- Logs is a list of list (stored in the self.logs_list var)
+ """This class manages logs inside the Glances software.
+
+ Logs is a list of list (stored in the self.logs_list var)
item_state = "OK|CAREFUL|WARNING|CRITICAL"
item_type = "CPU*|LOAD|MEM|MON"
item_value = value
+
Item is defined by:
["begin",
"end",
@@ -44,10 +47,7 @@ class GlancesLogs(object):
"""
def __init__(self):
- """
- Init the logs class
- """
-
+ """Init the logs class."""
# Maximum size of the logs list
self.logs_max = 10
@@ -55,24 +55,20 @@ class GlancesLogs(object):
self.logs_list = []
def get(self):
- """
- Return the logs list (RAW)
- """
+ """Return the raw logs list."""
return self.logs_list
def len(self):
- """
- Return the number of item in the log list
- """
+ """Return the number of item in the logs list."""
return self.logs_list.__len__()
def __itemexist__(self, item_type):
- """
+ """Return the item position, if it exists.
+
An item exist in the list if:
* end is < 0
* item_type is matching
- Return the item position if exist
- -1 if the item is not found
+ Return -1 if the item is not found.
"""
for i in range(self.len()):
if self.logs_list[i][1] < 0 and self.logs_list[i][3] == item_type:
@@ -80,9 +76,7 @@ class GlancesLogs(object):
return -1
def set_process_sort(self, item_type):
- """
- Define the process auto sort key from the alert type
- """
+ """Define the process auto sort key from the alert type."""
# Process sort depending on alert type
if item_type.startswith("MEM"):
# Sort TOP process by memory_percent
@@ -99,9 +93,7 @@ class GlancesLogs(object):
return process_auto_by
def reset_process_sort(self):
- """
- Reset the process_auto_by variable
- """
+ """Reset the process_auto_by variable."""
# Default sort is...
process_auto_by = 'cpu_percent'
@@ -110,11 +102,11 @@ class GlancesLogs(object):
return process_auto_by
def add(self, item_state, item_type, item_value, proc_list=[], proc_desc=""):
- """
- If item is a 'new one':
- Add the new item at the beginning of the logs list
- Else:
- Update the existing item
+ """Add a new item to the logs list.
+
+ If 'item' is a 'new one', add the new item at the beginning of the logs
+ list.
+ If 'item' is not a 'new one', update the existing item.
"""
# Add or update the log
item_index = self.__itemexist__(item_type)
@@ -190,8 +182,8 @@ class GlancesLogs(object):
return self.len()
def clean(self, critical=False):
- """
- Clean the log list by deleting finished item
+ """Clean the logs list by deleting finished items.
+
By default, only delete WARNING message
If critical = True, also delete CRITICAL message
"""
diff --git a/glances/core/glances_main.py b/glances/core/glances_main.py
index 50c49482..4d866b2d 100644
--- a/glances/core/glances_main.py
+++ b/glances/core/glances_main.py
@@ -16,26 +16,20 @@
#
# 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/>.
-"""
-Main Glances script
-"""
+
+"""Glances main class."""
# Import system libs
import argparse
# Import Glances libs
from glances.core.glances_config import Config
-from glances.core.glances_globals import (
- appname,
- psutil_version,
- version
-)
+from glances.core.glances_globals import appname, psutil_version, version
class GlancesMain(object):
- """
- Main class to manage Glances instance
- """
+
+ """Main class to manage Glances instance."""
# Default stats' refresh time is 3 seconds
refresh_time = 3
@@ -161,7 +155,6 @@ class GlancesMain(object):
self.server_ip = args.client
# /!!!
- # Interactive cmds like CLI args?
# By default help is hidden
args.help_tag = False
@@ -172,9 +165,7 @@ class GlancesMain(object):
return args
def __hash_password(self, plain_password):
- """
- Hash a plain password and return the hashed one
- """
+ """Hash a plain password and return the hashed one."""
from glances.core.glances_password import GlancesPassword
password = GlancesPassword()
@@ -182,10 +173,10 @@ class GlancesMain(object):
return password.hash_password(plain_password)
def __get_password(self, description='', confirm=False, clear=False):
- """
- Read a password from the command line
- - with confirmation if confirm = True
- - plain (clear password) if clear = True
+ """Read a password from the command line.
+
+ - if confirm = True, with confirmation
+ - if clear = True, plain (clear password)
"""
from glances.core.glances_password import GlancesPassword
@@ -194,37 +185,25 @@ class GlancesMain(object):
return password.get_password(description, confirm, clear)
def is_standalone(self):
- """
- Return True if Glances is running in standalone mode
- """
+ """Return True if Glances is running in standalone mode."""
return not self.client_tag and not self.server_tag and not self.webserver_tag
def is_client(self):
- """
- Return True if Glances is running in client mode
- """
+ """Return True if Glances is running in client mode."""
return self.client_tag and not self.server_tag
def is_server(self):
- """
- Return True if Glances is running in server mode
- """
+ """Return True if Glances is running in server mode."""
return not self.client_tag and self.server_tag
def is_webserver(self):
- """
- Return True if Glances is running in Web server mode
- """
+ """Return True if Glances is running in Web server mode."""
return not self.client_tag and self.webserver_tag
def get_config(self):
- """
- Return configuration file object
- """
+ """Return configuration file object."""
return self.config
def get_args(self):
- """
- Return the arguments
- """
+ """Return the arguments."""
return self.args
diff --git a/glances/core/glances_monitor_list.py b/glances/core/glances_monitor_list.py
index 33ce74c2..d3329407 100644
--- a/glances/core/glances_monitor_list.py
+++ b/glances/core/glances_monitor_list.py
@@ -17,6 +17,8 @@
# 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/>.
+"""Manage the monitor list."""
+
# Import system lib
import re
import subprocess
@@ -26,28 +28,27 @@ from glances.core.glances_globals import glances_processes
class MonitorList(object):
- """
- This class describes the optionnal monitored processes list
- A list of 'important' processes to monitor.
- The list (Python list) is composed of items (Python dict)
- An item is defined (Dict keys'):
+ """This class describes the optional monitored processes list.
+
+ The monitored list is a list of 'important' processes to monitor.
+
+ The list (Python list) is composed of items (Python dict).
+ An item is defined (dict keys):
* description: Description of the processes (max 16 chars)
* regex: regular expression of the processes to monitor
* command: (optional) shell command for extended stat
* countmin: (optional) minimal number of processes
* countmax: (optional) maximum number of processes
"""
+
# Maximum number of items in the list
__monitor_list_max_size = 10
# The list
__monitor_list = []
def __init__(self, config):
- """
- Init the monitoring list from the configuration file
- """
-
+ """Init the monitoring list from the configuration file."""
self.config = config
if self.config is not None and self.config.has_section('monitor'):
@@ -57,9 +58,9 @@ class MonitorList(object):
self.__monitor_list = []
def __set_monitor_list(self, section, key):
- """
- Init the monitored processes list
- The list is defined in the Glances configuration file
+ """Init the monitored processes list.
+
+ The list is defined in the Glances configuration file.
"""
for l in range(1, self.__monitor_list_max_size + 1):
value = {}
@@ -99,9 +100,9 @@ class MonitorList(object):
return len(self.__monitor_list)
def __get__(self, item, key):
- """
- Meta function to return key value of item
- None if not defined or item > len(list)
+ """Meta function to return key value of item.
+
+ Return None if not defined or item > len(list)
"""
if item < len(self.__monitor_list):
try:
@@ -112,15 +113,12 @@ class MonitorList(object):
return None
def update(self):
- """
- Update the command result attributed
- """
-
+ """Update the command result attributed."""
# Only continue if monitor list is not empty
if len(self.__monitor_list) == 0:
return self.__monitor_list
- # Iter uppon the monitored list
+ # Iter upon the monitored list
for i in range(0, len(self.get())):
# Search monitored processes by a regular expression
processlist = glances_processes.getlist()
@@ -147,15 +145,11 @@ class MonitorList(object):
return self.__monitor_list
def get(self):
- """
- Return the monitored list (list of dict)
- """
+ """Return the monitored list (list of dict)."""
return self.__monitor_list
def set(self, newlist):
- """
- Set the monitored list (list of dict)
- """
+ """Set the monitored list (list of dict)."""
self.__monitor_list = newlist
def getAll(self):
@@ -167,37 +161,25 @@ class MonitorList(object):
self.set(newlist)
def description(self, item):
- """
- Return the description of the item number (item)
- """
+ """Return the description of the item number (item)."""
return self.__get__(item, "description")
def regex(self, item):
- """
- Return the regular expression of the item number (item)
- """
+ """Return the regular expression of the item number (item)."""
return self.__get__(item, "regex")
def command(self, item):
- """
- Return the stats command of the item number (item)
- """
+ """Return the stat command of the item number (item)."""
return self.__get__(item, "command")
def result(self, item):
- """
- Return the reult command of the item number (item)
- """
+ """Return the reult command of the item number (item)."""
return self.__get__(item, "result")
def countmin(self, item):
- """
- Return the minimum number of processes of the item number (item)
- """
+ """Return the minimum number of processes of the item number (item)."""
return self.__get__(item, "countmin")
def countmax(self, item):
- """
- Return the maximum number of processes of the item number (item)
- """
+ """Return the maximum number of processes of the item number (item)."""
return self.__get__(item, "countmax")
diff --git a/glances/core/glances_password.py b/glances/core/glances_password.py
index 96b1bd6b..b1a906be 100644
--- a/glances/core/glances_password.py
+++ b/glances/core/glances_password.py
@@ -17,6 +17,8 @@
# 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/>.
+"""Manage password."""
+
# Import system libs
import getpass
import hashlib
@@ -41,9 +43,8 @@ except NameError:
class GlancesPassword(object):
- """
- Manage password
- """
+
+ """This class contains all the methods relating to password."""
def __init__(self):
self.password_path = self.get_password_path()
@@ -51,8 +52,8 @@ class GlancesPassword(object):
self.password_filepath = os.path.join(self.password_path, self.password_filename)
def get_password_path(self):
- """
- Get the path where the password file will be stored
+ r"""Get the path where the password file will be stored.
+
* Linux and BSD: ~/.config/glances
* OS X: ~/Library/glances