From 00386aa164e9fab7b192f0b1a2870f95fe76f9ff Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 15 Oct 2017 17:42:36 +0200 Subject: [PATCH] Docstings of plugins are now PEP 257 compliant --- glances/plugins/glances_alert.py | 9 +-- glances/plugins/glances_amps.py | 1 - glances/plugins/glances_batpercent.py | 2 - glances/plugins/glances_cloud.py | 18 +++--- glances/plugins/glances_core.py | 1 - glances/plugins/glances_cpu.py | 2 - glances/plugins/glances_diskio.py | 1 - glances/plugins/glances_docker.py | 28 ++++----- glances/plugins/glances_folders.py | 4 +- glances/plugins/glances_fs.py | 1 - glances/plugins/glances_gpu.py | 25 ++++---- glances/plugins/glances_hddtemp.py | 2 - glances/plugins/glances_help.py | 3 +- glances/plugins/glances_ip.py | 8 +-- glances/plugins/glances_irq.py | 29 ++++------ glances/plugins/glances_load.py | 1 - glances/plugins/glances_mem.py | 1 - glances/plugins/glances_memswap.py | 1 - glances/plugins/glances_network.py | 1 - glances/plugins/glances_now.py | 3 +- glances/plugins/glances_percpu.py | 1 - glances/plugins/glances_plugin.py | 74 ++++++++++++++---------- glances/plugins/glances_ports.py | 31 +++++----- glances/plugins/glances_processcount.py | 1 - glances/plugins/glances_processlist.py | 25 ++++---- glances/plugins/glances_psutilversion.py | 2 + glances/plugins/glances_quicklook.py | 5 +- glances/plugins/glances_raid.py | 1 - glances/plugins/glances_sensors.py | 5 +- glances/plugins/glances_uptime.py | 1 - glances/plugins/glances_wifi.py | 4 +- 31 files changed, 136 insertions(+), 155 deletions(-) diff --git a/glances/plugins/glances_alert.py b/glances/plugins/glances_alert.py index 1bafda9e..a6a59238 100644 --- a/glances/plugins/glances_alert.py +++ b/glances/plugins/glances_alert.py @@ -23,7 +23,7 @@ from datetime import datetime from glances.logs import glances_logs from glances.thresholds import glances_thresholds -from glances.logger import logger +# from glances.logger import logger from glances.plugins.glances_plugin import GlancesPlugin # Static decision tree for the global alert message @@ -61,8 +61,10 @@ tree = [{'msg': 'No warning or critical alert detected', def global_message(): - """Parse the decision tree and return the message - corresponding to the current threasholds values""" + """Parse the decision tree and return the message. + + Note: message corresponding to the current threasholds values + """ # Compute the weight for each item in the tree current_thresholds = glances_thresholds.get() for i in tree: @@ -76,7 +78,6 @@ def global_message(): class Plugin(GlancesPlugin): - """Glances alert plugin. Only for display. diff --git a/glances/plugins/glances_amps.py b/glances/plugins/glances_amps.py index afa218c1..6270864e 100644 --- a/glances/plugins/glances_amps.py +++ b/glances/plugins/glances_amps.py @@ -25,7 +25,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances AMPs plugin.""" def __init__(self, args=None, config=None): diff --git a/glances/plugins/glances_batpercent.py b/glances/plugins/glances_batpercent.py index 0891e8a6..161958be 100644 --- a/glances/plugins/glances_batpercent.py +++ b/glances/plugins/glances_batpercent.py @@ -42,7 +42,6 @@ except AttributeError: class Plugin(GlancesPlugin): - """Glances battery capacity plugin. stats is a list @@ -87,7 +86,6 @@ class Plugin(GlancesPlugin): class GlancesGrabBat(object): - """Get batteries stats using the batinfo library.""" def __init__(self): diff --git a/glances/plugins/glances_cloud.py b/glances/plugins/glances_cloud.py index 5a59764f..430fd01e 100644 --- a/glances/plugins/glances_cloud.py +++ b/glances/plugins/glances_cloud.py @@ -38,7 +38,6 @@ from glances.logger import logger class Plugin(GlancesPlugin): - """Glances' cloud plugin. The goal of this plugin is to retreive additional information @@ -70,7 +69,7 @@ class Plugin(GlancesPlugin): self.stats = {} def exit(self): - """Overwrite the exit method to close threads""" + """Overwrite the exit method to close threads.""" self.aws_ec2.stop() # Call the father class super(Plugin, self).exit() @@ -137,7 +136,7 @@ class ThreadAwsEc2Grabber(threading.Thread): 'region': 'placement/availability-zone'} def __init__(self): - """Init the class""" + """Init the class.""" logger.debug("cloud plugin - Create thread for AWS EC2") super(ThreadAwsEc2Grabber, self).__init__() # Event needed to stop properly the thread @@ -146,9 +145,10 @@ class ThreadAwsEc2Grabber(threading.Thread): self._stats = {} def run(self): - """Function called to grab stats. - Infinite loop, should be stopped by calling the stop() method""" + """Grab plugin's stats. + Infinite loop, should be stopped by calling the stop() method + """ if not cloud_tag: logger.debug("cloud plugin - Requests lib is not installed") self.stop() @@ -170,19 +170,19 @@ class ThreadAwsEc2Grabber(threading.Thread): @property def stats(self): - """Stats getter""" + """Stats getter.""" return self._stats @stats.setter def stats(self, value): - """Stats setter""" + """Stats setter.""" self._stats = value def stop(self, timeout=None): - """Stop the thread""" + """Stop the thread.""" logger.debug("cloud plugin - Close thread for AWS EC2") self._stopper.set() def stopped(self): - """Return True is the thread is stopped""" + """Return True is the thread is stopped.""" return self._stopper.isSet() diff --git a/glances/plugins/glances_core.py b/glances/plugins/glances_core.py index 7fefd3bf..98ec1383 100644 --- a/glances/plugins/glances_core.py +++ b/glances/plugins/glances_core.py @@ -25,7 +25,6 @@ import psutil class Plugin(GlancesPlugin): - """Glances CPU core plugin. Get stats about CPU core number. diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 5bdbb6d1..705e650d 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -57,7 +57,6 @@ items_history_list = [{'name': 'user', class Plugin(GlancesPlugin): - """Glances CPU plugin. 'stats' is a dictionary that contains the system-wide CPU utilization as a @@ -88,7 +87,6 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): """Update CPU stats using the input method.""" - # Reset stats self.reset() diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index 308d610d..f6ce21b2 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -41,7 +41,6 @@ items_history_list = [{'name': 'read_bytes', class Plugin(GlancesPlugin): - """Glances disks I/O plugin. stats is a list diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index 0e178b35..b88f4cd3 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -40,7 +40,6 @@ else: class Plugin(GlancesPlugin): - """Glances Docker plugin. stats is a dict: {'version': {...}, 'containers': [{}, {}]} @@ -68,7 +67,7 @@ class Plugin(GlancesPlugin): self.reset() def exit(self): - """Overwrite the exit method to close threads""" + """Overwrite the exit method to close threads.""" for t in itervalues(self.thread_list): t.stop() # Call the father class @@ -105,7 +104,7 @@ class Plugin(GlancesPlugin): self.stats = {} def _all_tag(self): - """Return the all tag of the Glances/Docker configuration file + """Return the all tag of the Glances/Docker configuration file. # By default, Glances only display running containers # Set the following key to True to display all containers @@ -121,7 +120,6 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): """Update Docker stats using the input method.""" - # Reset stats self.reset() @@ -410,8 +408,10 @@ class Plugin(GlancesPlugin): return os.sysconf(os.sysconf_names['SC_CLK_TCK']) def get_stats_action(self): - """Return stats for the action - Docker will return self.stats['containers']""" + """Return stats for the action. + + Docker will return self.stats['containers'] + """ return self.stats['containers'] def update_views(self): @@ -587,7 +587,8 @@ class ThreadDockerGrabber(threading.Thread): """ def __init__(self, container): - """Init the class: + """Init the class. + container: instance of Docker-py Container """ super(ThreadDockerGrabber, self).__init__() @@ -601,9 +602,10 @@ class ThreadDockerGrabber(threading.Thread): logger.debug("docker plugin - Create thread for container {}".format(self._container.name)) def run(self): - """Function called to grab stats. - Infinite loop, should be stopped by calling the stop() method""" + """Grab the stats. + Infinite loop, should be stopped by calling the stop() method + """ for i in self._stats_stream: self._stats = i time.sleep(0.1) @@ -612,19 +614,19 @@ class ThreadDockerGrabber(threading.Thread): @property def stats(self): - """Stats getter""" + """Stats getter.""" return self._stats @stats.setter def stats(self, value): - """Stats setter""" + """Stats setter.""" self._stats = value def stop(self, timeout=None): - """Stop the thread""" + """Stop the thread.""" logger.debug("docker plugin - Close thread for container {}".format(self._container.name)) self._stopper.set() def stopped(self): - """Return True is the thread is stopped""" + """Return True is the thread is stopped.""" return self._stopper.isSet() diff --git a/glances/plugins/glances_folders.py b/glances/plugins/glances_folders.py index 3b17a227..2704a74c 100644 --- a/glances/plugins/glances_folders.py +++ b/glances/plugins/glances_folders.py @@ -26,7 +26,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances folder plugin.""" def __init__(self, args=None): @@ -76,8 +75,7 @@ class Plugin(GlancesPlugin): return self.stats def get_alert(self, stat): - """Manage limits of the folder list""" - + """Manage limits of the folder list.""" if not isinstance(stat['size'], numbers.Number): return 'DEFAULT' else: diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py index ce86d9bb..cb3d7459 100644 --- a/glances/plugins/glances_fs.py +++ b/glances/plugins/glances_fs.py @@ -66,7 +66,6 @@ items_history_list = [{'name': 'percent', class Plugin(GlancesPlugin): - """Glances file system plugin. stats is a list diff --git a/glances/plugins/glances_gpu.py b/glances/plugins/glances_gpu.py index 24a3c989..33518f28 100644 --- a/glances/plugins/glances_gpu.py +++ b/glances/plugins/glances_gpu.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -"""GPU plugin (limited to NVIDIA chipsets)""" +"""GPU plugin (limited to NVIDIA chipsets).""" from glances.compat import nativestr from glances.logger import logger @@ -34,14 +34,13 @@ else: class Plugin(GlancesPlugin): - """Glances GPU plugin (limited to NVIDIA chipsets). stats is a list of dictionaries with one entry per GPU """ def __init__(self, args=None): - """Init the plugin""" + """Init the plugin.""" super(Plugin, self).__init__(args=args) # Init the NVidia API @@ -58,7 +57,7 @@ class Plugin(GlancesPlugin): self.stats = [] def init_nvidia(self): - """Init the NVIDIA API""" + """Init the NVIDIA API.""" if not gpu_nvidia_tag: self.nvml_ready = False @@ -79,8 +78,7 @@ class Plugin(GlancesPlugin): @GlancesPlugin._check_decorator @GlancesPlugin._log_result_decorator def update(self): - """Update the GPU stats""" - + """Update the GPU stats.""" self.reset() # !!! JUST FOR TEST @@ -212,7 +210,7 @@ class Plugin(GlancesPlugin): return ret def get_device_stats(self): - """Get GPU stats""" + """Get GPU stats.""" stats = [] for index, device_handle in enumerate(self.device_handles): @@ -232,7 +230,7 @@ class Plugin(GlancesPlugin): return stats def exit(self): - """Overwrite the exit method to close the GPU API""" + """Overwrite the exit method to close the GPU API.""" if self.nvml_ready: try: pynvml.nvmlShutdown() @@ -244,14 +242,15 @@ class Plugin(GlancesPlugin): def get_device_handles(): - """ - Returns a list of NVML device handles, one per device. Can throw NVMLError. + """Get a list of NVML device handles, one per device. + + Can throw NVMLError. """ return [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(pynvml.nvmlDeviceGetCount())] def get_device_name(device_handle): - """Get GPU device name""" + """Get GPU device name.""" try: return nativestr(pynvml.nvmlDeviceGetName(device_handle)) except pynvml.NVMlError: @@ -259,7 +258,7 @@ def get_device_name(device_handle): def get_mem(device_handle): - """Get GPU device memory consumption in percent""" + """Get GPU device memory consumption in percent.""" try: memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle) return memory_info.used * 100.0 / memory_info.total @@ -268,7 +267,7 @@ def get_mem(device_handle): def get_proc(device_handle): - """Get GPU device CPU consumption in percent""" + """Get GPU device CPU consumption in percent.""" try: return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu except pynvml.NVMLError: diff --git a/glances/plugins/glances_hddtemp.py b/glances/plugins/glances_hddtemp.py index eabe5af6..dccf67b4 100644 --- a/glances/plugins/glances_hddtemp.py +++ b/glances/plugins/glances_hddtemp.py @@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances HDD temperature sensors plugin. stats is a list @@ -72,7 +71,6 @@ class Plugin(GlancesPlugin): class GlancesGrabHDDTemp(object): - """Get hddtemp stats using a socket connection.""" def __init__(self, host='127.0.0.1', port=7634, args=None): diff --git a/glances/plugins/glances_help.py b/glances/plugins/glances_help.py index 91032512..c7701445 100644 --- a/glances/plugins/glances_help.py +++ b/glances/plugins/glances_help.py @@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances help plugin.""" def __init__(self, args=None, config=None): @@ -54,6 +53,7 @@ class Plugin(GlancesPlugin): pass def generate_view_data(self): + """Generate the views.""" self.view_data['version'] = '{} {}'.format('Glances', __version__) self.view_data['psutil_version'] = ' with PSutil {}'.format(psutil_version) @@ -103,6 +103,7 @@ class Plugin(GlancesPlugin): self.view_data['edit_pattern_filter'] = 'ENTER: Edit the process filter pattern' def get_view_data(self, args=None): + """Return the view.""" return self.view_data def msg_curse(self, args=None): diff --git a/glances/plugins/glances_ip.py b/glances/plugins/glances_ip.py index 160baa57..12657c81 100644 --- a/glances/plugins/glances_ip.py +++ b/glances/plugins/glances_ip.py @@ -52,7 +52,6 @@ urls = [('http://ip.42.pl/raw', False, None), class Plugin(GlancesPlugin): - """Glances IP Plugin. stats is a dict @@ -159,13 +158,14 @@ class Plugin(GlancesPlugin): class PublicIpAddress(object): - """Get public IP address from online services""" + """Get public IP address from online services.""" def __init__(self, timeout=2): + """Init the class.""" self.timeout = timeout def get(self): - """Get the first public IP address returned by one of the online services""" + """Get the first public IP address returned by one of the online services.""" q = queue.Queue() for u, j, k in urls: @@ -182,7 +182,7 @@ class PublicIpAddress(object): return ip def _get_ip_public(self, queue_target, url, json=False, key=None): - """Request the url service and put the result in the queue_target""" + """Request the url service and put the result in the queue_target.""" try: response = urlopen(url, timeout=self.timeout).read().decode('utf-8') except Exception as e: diff --git a/glances/plugins/glances_irq.py b/glances/plugins/glances_irq.py index 606c7a1a..1ade5b35 100644 --- a/glances/plugins/glances_irq.py +++ b/glances/plugins/glances_irq.py @@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances IRQ plugin. stats is a list @@ -56,8 +55,7 @@ class Plugin(GlancesPlugin): @GlancesPlugin._check_decorator @GlancesPlugin._log_result_decorator def update(self): - """Update the IRQ stats""" - + """Update the IRQ stats.""" # Reset the list self.reset() @@ -117,27 +115,25 @@ class Plugin(GlancesPlugin): class GlancesIRQ(object): - """ - This class manages the IRQ file - """ + """This class manages the IRQ file.""" IRQ_FILE = '/proc/interrupts' def __init__(self): - """ - Init the class + """Init the class. + The stat are stored in a internal list of dict """ self.lasts = {} self.reset() def reset(self): - """Reset the stats""" + """Reset the stats.""" self.stats = [] self.cpu_number = 0 def get(self): - """Return the current IRQ stats""" + """Return the current IRQ stats.""" return self.__update() def get_key(self): @@ -145,7 +141,7 @@ class GlancesIRQ(object): return 'irq_line' def __header(self, line): - """The header contain the number of CPU + """Build the header (contain the number of CPU). CPU0 CPU1 CPU2 CPU3 0: 21 0 0 0 IO-APIC 2-edge timer @@ -154,8 +150,7 @@ class GlancesIRQ(object): return self.cpu_number def __humanname(self, line): - """Get a line and - Return the IRQ name, alias or number (choose the best for human) + """Return the IRQ name, alias or number (choose the best for human). IRQ line samples: 1: 44487 341 44 72 IO-APIC 1-edge i8042 @@ -169,8 +164,7 @@ class GlancesIRQ(object): return irq_line def __sum(self, line): - """Get a line and - Return the IRQ sum number + """Return the IRQ sum number. IRQ line samples: 1: 44487 341 44 72 IO-APIC 1-edge i8042 @@ -186,10 +180,7 @@ class GlancesIRQ(object): return ret def __update(self): - """ - Load the IRQ file and update the internal dict - """ - + """Load the IRQ file and update the internal dict.""" self.reset() if not os.path.exists(self.IRQ_FILE): diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py index b1e0d0ea..9246894c 100644 --- a/glances/plugins/glances_load.py +++ b/glances/plugins/glances_load.py @@ -48,7 +48,6 @@ items_history_list = [{'name': 'min1', class Plugin(GlancesPlugin): - """Glances load plugin. stats is a dict diff --git a/glances/plugins/glances_mem.py b/glances/plugins/glances_mem.py index eaebfa97..d6bf6a4c 100644 --- a/glances/plugins/glances_mem.py +++ b/glances/plugins/glances_mem.py @@ -56,7 +56,6 @@ items_history_list = [{'name': 'percent', class Plugin(GlancesPlugin): - """Glances' memory plugin. stats is a dict diff --git a/glances/plugins/glances_memswap.py b/glances/plugins/glances_memswap.py index ec8f7bee..4ba1849d 100644 --- a/glances/plugins/glances_memswap.py +++ b/glances/plugins/glances_memswap.py @@ -44,7 +44,6 @@ items_history_list = [{'name': 'percent', class Plugin(GlancesPlugin): - """Glances swap memory plugin. stats is a dict diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index d6fef25d..d05f54e1 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -48,7 +48,6 @@ items_history_list = [{'name': 'rx', class Plugin(GlancesPlugin): - """Glances network plugin. stats is a list diff --git a/glances/plugins/glances_now.py b/glances/plugins/glances_now.py index 52c6b362..9818247c 100644 --- a/glances/plugins/glances_now.py +++ b/glances/plugins/glances_now.py @@ -17,13 +17,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +"""Now (current date) plugin.""" + from datetime import datetime from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Plugin to get the current date/time. stats is (string) diff --git a/glances/plugins/glances_percpu.py b/glances/plugins/glances_percpu.py index 3bc4e558..c9c4f330 100644 --- a/glances/plugins/glances_percpu.py +++ b/glances/plugins/glances_percpu.py @@ -24,7 +24,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances per-CPU plugin. 'stats' is a list of dictionaries that contain the utilization percentages diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index ffeb7a17..5dbf28ec 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -36,7 +36,6 @@ from glances.thresholds import glances_thresholds class GlancesPlugin(object): - """Main class for Glances plugin.""" def __init__(self, args=None, items_history_list=None): @@ -61,7 +60,6 @@ class GlancesPlugin(object): :args: args parameters :items_history_list: list of items to store in the history """ - # Plugin name (= module name without glances_) self.plugin_name = self.__class__.__module__[len('glances_'):] # logger.debug("Init plugin %s" % self.plugin_name) @@ -103,11 +101,13 @@ class GlancesPlugin(object): def reset(self): """Reset the stats. - This method should be overwrited by childs' classes""" + + This method should be overwrited by childs' classes. + """ self.stats = None def exit(self): - """Method to be called when Glances exit""" + """Just log an event when Glances exit.""" logger.debug("Stop the {} plugin".format(self.plugin_name)) def get_key(self): @@ -115,7 +115,7 @@ class GlancesPlugin(object): return None def is_enable(self): - """Return true if plugin is enabled""" + """Return true if plugin is enabled.""" try: d = getattr(self.args, 'disable_' + self.plugin_name) except AttributeError: @@ -124,12 +124,14 @@ class GlancesPlugin(object): return d is False def is_disable(self): - """Return true if plugin is disabled""" + """Return true if plugin is disabled.""" return not self.is_enable() def _json_dumps(self, d): - """Return the object 'd' in a JSON format - Manage the issue #815 for Windows OS""" + """Return the object 'd' in a JSON format. + + Manage the issue #815 for Windows OS + """ try: return json.dumps(d) except UnicodeDecodeError: @@ -185,11 +187,13 @@ class GlancesPlugin(object): return self.items_history_list def get_raw_history(self, item=None, nb=0): - """Return + """Return the history (RAW format). + - the stats history (dict of list) if item is None - the stats history for the given item (list) instead - None if item did not exist in the history - Limit to lasts nb items (all if nb=0)""" + Limit to lasts nb items (all if nb=0) + """ s = self.stats_history.get(nb=nb) if item is None: return s @@ -200,11 +204,13 @@ class GlancesPlugin(object): return None def get_json_history(self, item=None, nb=0): - """Return: + """Return the history (JSON format). + - the stats history (dict of list) if item is None - the stats history for the given item (list) instead - None if item did not exist in the history - Limit to lasts nb items (all if nb=0)""" + Limit to lasts nb items (all if nb=0) + """ s = self.stats_history.get_json(nb=nb) if item is None: return s @@ -216,12 +222,16 @@ class GlancesPlugin(object): def get_export_history(self, item=None): """Return the stats history object to export. - See get_raw_history for a full description""" + + See get_raw_history for a full description + """ return self.get_raw_history(item=item) def get_stats_history(self, item=None, nb=0): - """Return the stats history as a JSON object (dict or None). - Limit to lasts nb items (all if nb=0)""" + """Return the stats history (JSON format). + + Limit to lasts nb items (all if nb=0) + """ s = self.get_json_history(nb=nb) if item is None: @@ -245,7 +255,8 @@ class GlancesPlugin(object): return None def get_trend(self, item, nb=6): - """Get the trend regarding to the last nb values + """Get the trend regarding to the last nb values. + The trend is the diff between the mean of the last nb values and the current one. """ @@ -391,7 +402,7 @@ class GlancesPlugin(object): return None def update_views(self): - """Default builder fo the stats views. + """Update the stats views. The V of MVC A dict of dict with the needed information to display the stats. @@ -458,12 +469,11 @@ class GlancesPlugin(object): return 'DEFAULT' def get_json_views(self, item=None, key=None, option=None): - """Return views in JSON""" + """Return the views (in JSON).""" return self._json_dumps(self.get_views(item, key, option)) def load_limits(self, config): """Load limits from the configuration file, if it exists.""" - # By default set the history length to 3 points per second during one day self._limits['history_size'] = 28800 @@ -499,10 +509,12 @@ class GlancesPlugin(object): self._limits = input_limits def get_stats_action(self): - """Return stats for the action + """Return stats for the action. + By default return all the stats. Can be overwrite by plugins implementation. - For example, Docker will return self.stats['containers']""" + For example, Docker will return self.stats['containers'] + """ return self.stats def get_alert(self, @@ -589,7 +601,7 @@ class GlancesPlugin(object): def manage_threshold(self, stat_name, trigger): - """Manage the threshold for the current stat""" + """Manage the threshold for the current stat.""" glances_thresholds.add(stat_name, trigger) # logger.info(glances_thresholds.get()) @@ -598,7 +610,7 @@ class GlancesPlugin(object): trigger, header, action_key): - """Manage the action for the current stat""" + """Manage the action for the current stat.""" # Here is a command line for the current trigger ? try: command, repeat = self.get_limit_action(trigger, stat_name=stat_name) @@ -661,8 +673,10 @@ class GlancesPlugin(object): def get_limit_action(self, criticity, stat_name=""): """Return the tuple (action, repeat) for the alert. + - action is a command line - - repeat is a bool""" + - repeat is a bool + """ # Get the action for stat + header # Exemple: network_wlan0_rx_careful_action # Action key available ? @@ -714,8 +728,8 @@ class GlancesPlugin(object): return [] def is_hide(self, value, header=""): - """ - Return True if the value is in the hide configuration list. + """Return True if the value is in the hide configuration list. + The hide configuration list is defined in the glances.conf file. It is a comma separed list of regexp. Example for diskio: @@ -818,8 +832,6 @@ class GlancesPlugin(object): """Make a nice human-readable string out of number. Number of decimal places increases as quantity approaches 1. - - examples: CASE: 613421788 RESULT: 585M low_precision: 585M CASE: 5307033647 RESULT: 4.94G low_precision: 4.9G CASE: 44968414685 RESULT: 41.9G low_precision: 41.9G @@ -866,8 +878,10 @@ class GlancesPlugin(object): return '{!s}'.format(number) def trend_msg(self, trend, significant=1): - """Return the trend message - Do not take into account if trend < significant""" + """Return the trend message. + + Do not take into account if trend < significant + """ ret = '-' if trend is None: ret = ' ' diff --git a/glances/plugins/glances_ports.py b/glances/plugins/glances_ports.py index 2e3202af..c1495165 100644 --- a/glances/plugins/glances_ports.py +++ b/glances/plugins/glances_ports.py @@ -42,7 +42,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances ports scanner plugin.""" def __init__(self, args=None, config=None): @@ -64,7 +63,7 @@ class Plugin(GlancesPlugin): self._thread = None def exit(self): - """Overwrite the exit method to close threads""" + """Overwrite the exit method to close threads.""" if self._thread is not None: self._thread.stop() # Call the father class @@ -77,7 +76,6 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): """Update the ports list.""" - if self.input_method == 'local': # Only refresh: # * if there is not other scanning thread @@ -103,7 +101,6 @@ class Plugin(GlancesPlugin): def get_ports_alert(self, port, header="", log=False): """Return the alert status relative to the port scan return value.""" - if port['status'] is None: return 'CAREFUL' elif port['status'] == 0: @@ -117,7 +114,6 @@ class Plugin(GlancesPlugin): def get_web_alert(self, web, header="", log=False): """Return the alert status relative to the web/url scan return value.""" - if web['status'] is None: return 'CAREFUL' elif web['status'] not in [200, 301, 302]: @@ -186,7 +182,7 @@ class ThreadScanner(threading.Thread): """ def __init__(self, stats): - """Init the class""" + """Init the class.""" logger.debug("ports plugin - Create thread for scan list {}".format(stats)) super(ThreadScanner, self).__init__() # Event needed to stop properly the thread @@ -197,9 +193,10 @@ class ThreadScanner(threading.Thread): self.plugin_name = "ports" def run(self): - """Function called to grab stats. - Infinite loop, should be stopped by calling the stop() method""" + """Grab the stats. + Infinite loop, should be stopped by calling the stop() method. + """ for p in self._stats: # End of the thread has been asked if self.stopped(): @@ -216,25 +213,25 @@ class ThreadScanner(threading.Thread): @property def stats(self): - """Stats getter""" + """Stats getter.""" return self._stats @stats.setter def stats(self, value): - """Stats setter""" + """Stats setter.""" self._stats = value def stop(self, timeout=None): - """Stop the thread""" + """Stop the thread.""" logger.debug("ports plugin - Close thread for scan list {}".format(self._stats)) self._stopper.set() def stopped(self): - """Return True is the thread is stopped""" + """Return True is the thread is stopped.""" return self._stopper.isSet() def _web_scan(self, web): - """Scan the Web/URL (dict) and update the status key""" + """Scan the Web/URL (dict) and update the status key.""" try: req = requests.head(web['url'], allow_redirects=True, @@ -249,14 +246,14 @@ class ThreadScanner(threading.Thread): return web def _port_scan(self, port): - """Scan the port structure (dict) and update the status key""" + """Scan the port structure (dict) and update the status key.""" if int(port['port']) == 0: return self._port_scan_icmp(port) else: return self._port_scan_tcp(port) def _resolv_name(self, hostname): - """Convert hostname to IP address""" + """Convert hostname to IP address.""" ip = hostname try: ip = socket.gethostbyname(hostname) @@ -265,7 +262,7 @@ class ThreadScanner(threading.Thread): return ip def _port_scan_icmp(self, port): - """Scan the (ICMP) port structure (dict) and update the status key""" + """Scan the (ICMP) port structure (dict) and update the status key.""" ret = None # Create the ping command @@ -305,7 +302,7 @@ class ThreadScanner(threading.Thread): return ret def _port_scan_tcp(self, port): - """Scan the (TCP) port structure (dict) and update the status key""" + """Scan the (TCP) port structure (dict) and update the status key.""" ret = None # Create and configure the scanning socket diff --git a/glances/plugins/glances_processcount.py b/glances/plugins/glances_processcount.py index 2ffd18b7..03620c82 100644 --- a/glances/plugins/glances_processcount.py +++ b/glances/plugins/glances_processcount.py @@ -27,7 +27,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances process count plugin. stats is a list diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index f10b5130..c059e57a 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -57,7 +57,6 @@ def split_cmdline(cmdline): class Plugin(GlancesPlugin): - """Glances' processes plugin. stats is a list @@ -202,6 +201,7 @@ class Plugin(GlancesPlugin): def get_process_curses_data(self, p, first, args): """Get curses data to display for a process. + - p is the process to display - first is a tag=True if the process is the first on the list """ @@ -466,9 +466,7 @@ class Plugin(GlancesPlugin): return ret def __msg_curse_header(self, ret, process_sort_key, args=None): - """ - Build the header and add it to the ret dict - """ + """Build the header and add it to the ret dict.""" sort_style = 'SORT' if args.disable_irix and 0 < self.nb_log_core < 10: @@ -503,7 +501,8 @@ class Plugin(GlancesPlugin): def __msg_curse_sum(self, ret, sep_char='_', mmm=None, args=None): """ - Build the sum message (only when filter is on) and add it to the ret dict + Build the sum message (only when filter is on) and add it to the ret dict. + * ret: list of string where the message is added * sep_char: define the line separation char * mmm: display min, max, mean or current (if mmm=None) @@ -586,24 +585,20 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg, optional=True)) def __mmm_deco(self, mmm): - """ - Return the decoration string for the current mmm status - """ + """Return the decoration string for the current mmm status.""" if mmm is not None: return 'DEFAULT' else: return 'FILTER' def __mmm_reset(self): - """ - Reset the MMM stats - """ + """Reset the MMM stats.""" self.mmm_min = {} self.mmm_max = {} def __sum_stats(self, key, indice=None, mmm=None): - """ - Return the sum of the stats value for the given key + """Return the sum of the stats value for the given key. + * indice: If indice is set, get the p[key][indice] * mmm: display min, max, mean or current (if mmm=None) """ @@ -647,13 +642,13 @@ class Plugin(GlancesPlugin): return ret def __sort_stats(self, sortedby=None): - """Return the stats (dict) sorted by (sortedby)""" + """Return the stats (dict) sorted by (sortedby).""" return sort_stats(self.stats, sortedby, tree=glances_processes.is_tree_enabled(), reverse=glances_processes.sort_reverse) def __max_pid_size(self): - """Return the maximum PID size in number of char""" + """Return the maximum PID size in number of char.""" if self.pid_max is not None: return len(str(self.pid_max)) else: diff --git a/glances/plugins/glances_psutilversion.py b/glances/plugins/glances_psutilversion.py index 7945ac26..bffa4808 100644 --- a/glances/plugins/glances_psutilversion.py +++ b/glances/plugins/glances_psutilversion.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 . +"""PsUtil plugin.""" + from glances import psutil_version_info from glances.plugins.glances_plugin import GlancesPlugin diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index eca3c7a6..2a1b5b63 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -37,7 +37,6 @@ else: class Plugin(GlancesPlugin): - """Glances quicklook plugin. 'stats' is a dictionary. @@ -143,7 +142,7 @@ class Plugin(GlancesPlugin): return ret def _msg_create_line(self, msg, bar, key): - """Create a new line to the Quickview""" + """Create a new line to the Quickview.""" ret = [] ret.append(self.curse_add_line(msg)) @@ -155,5 +154,5 @@ class Plugin(GlancesPlugin): return ret def _hz_to_ghz(self, hz): - """Convert Hz to Ghz""" + """Convert Hz to Ghz.""" return hz / 1000000000.0 diff --git a/glances/plugins/glances_raid.py b/glances/plugins/glances_raid.py index 910dc23e..3579232a 100644 --- a/glances/plugins/glances_raid.py +++ b/glances/plugins/glances_raid.py @@ -31,7 +31,6 @@ except ImportError: class Plugin(GlancesPlugin): - """Glances RAID plugin. stats is a dict (see pymdstat documentation) diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index 4db1ada5..37f8dbba 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -37,7 +37,6 @@ def to_fahrenheit(celsius): class Plugin(GlancesPlugin): - """Glances sensors plugin. The stats list includes both sensors and hard disks stats, if any. @@ -218,7 +217,6 @@ class Plugin(GlancesPlugin): class GlancesGrabSensors(object): - """Get sensors stats.""" def __init__(self): @@ -282,7 +280,8 @@ class GlancesGrabSensors(object): type: SENSOR_TEMP_UNIT or SENSOR_FAN_UNIT - output: a list""" + output: a list + """ ret = [] if type == SENSOR_TEMP_UNIT and self.init_temp: input_list = self.stemps diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py index e57818da..6639fc33 100644 --- a/glances/plugins/glances_uptime.py +++ b/glances/plugins/glances_uptime.py @@ -30,7 +30,6 @@ snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'} class Plugin(GlancesPlugin): - """Glances uptime plugin. stats is date (string) diff --git a/glances/plugins/glances_wifi.py b/glances/plugins/glances_wifi.py index 2138af81..8504ec26 100644 --- a/glances/plugins/glances_wifi.py +++ b/glances/plugins/glances_wifi.py @@ -38,8 +38,8 @@ else: class Plugin(GlancesPlugin): - """Glances Wifi plugin. + Get stats of the current Wifi hotspots. """ @@ -130,11 +130,11 @@ class Plugin(GlancesPlugin): def get_alert(self, value): """Overwrite the default get_alert method. + Alert is on signal quality where lower is better... :returns: string -- Signal alert """ - ret = 'OK' try: if value <= self.get_limit('critical', stat_name=self.plugin_name):