diff --git a/glances/core/glances_actions.py b/glances/core/glances_actions.py index 1a762b70bdbedd1ac75761ed9325f227ebc47659..f7e6f7e2495cc4ff89772d8cb53218e4cd79923c 100644 --- a/glances/core/glances_actions.py +++ b/glances/core/glances_actions.py @@ -35,11 +35,10 @@ else: class GlancesActions(object): - """This class manage action if an alert is reached""" + """This class manage action if an alert is reached.""" def __init__(self): - """Init GlancesActions class""" - + """Init GlancesActions class.""" # Dict with the criticity status # - key: stat_name # - value: criticity @@ -47,25 +46,26 @@ class GlancesActions(object): self.status = {} def get(self, stat_name): - """Get the stat_name criticity""" + """Get the stat_name criticity.""" try: return self.status[stat_name] except KeyError: return None def set(self, stat_name, criticity): - """Set the stat_name to criticity""" + """Set the stat_name to criticity.""" self.status[stat_name] = criticity def run(self, stat_name, criticity, commands, mustache_dict=None): - """Run the commands (in background) + """Run the commands (in background). + - stats_name: plugin_name (+ header) - criticity: criticity of the trigger - commands: a list of command line with optional {{mustache}} - mustache_dict: Plugin stats (can be use within {{mustache}}) - Return True if the commands have been ran""" - + Return True if the commands have been ran. + """ if self.get(stat_name) == criticity: # Action already executed => Exit return False diff --git a/glances/core/glances_autodiscover.py b/glances/core/glances_autodiscover.py index 2e5de4dbea8af5e35a9cf0d0aef54138b9bf1f7b..9643021e88f62c2b6dc2f53f261905a0c1696661 100644 --- a/glances/core/glances_autodiscover.py +++ b/glances/core/glances_autodiscover.py @@ -53,7 +53,7 @@ zeroconf_type = "_%s._tcp." % appname class AutoDiscovered(object): - """Class to manage the auto discovered servers dict""" + """Class to manage the auto discovered servers dict.""" def __init__(self): # server_dict is a list of dict (JSON compliant) @@ -61,15 +61,15 @@ class AutoDiscovered(object): self._server_list = [] def get_servers_list(self): - """Return the current server list (list of dict)""" + """Return the current server list (list of dict).""" return self._server_list def set_server(self, server_pos, key, value): - """Set the key to the value for the server_pos (position in the list)""" + """Set the key to the value for the server_pos (position in the list).""" self._server_list[server_pos][key] = value def add_server(self, name, ip, port): - """Add a new server to the list""" + """Add a new server to the list.""" new_server = {'key': name, # Zeroconf name with both hostname and port 'name': name.split(':')[0], # Short name 'ip': ip, # IP address seen by the client @@ -84,7 +84,7 @@ class AutoDiscovered(object): (len(self._server_list), self._server_list)) def remove_server(self, name): - """Remove a server from the dict""" + """Remove a server from the dict.""" for i in self._server_list: if i['key'] == name: try: @@ -99,22 +99,23 @@ class AutoDiscovered(object): class GlancesAutoDiscoverListener(object): - """Zeroconf listener for Glances server""" + """Zeroconf listener for Glances server.""" def __init__(self): # Create an instance of the servers list self.servers = AutoDiscovered() def get_servers_list(self): - """Return the current server list (list of dict)""" + """Return the current server list (list of dict).""" return self.servers.get_servers_list() def set_server(self, server_pos, key, value): - """Set the key to the value for the server_pos (position in the list)""" + """Set the key to the value for the server_pos (position in the list).""" self.servers.set_server(server_pos, key, value) def add_service(self, zeroconf, srv_type, srv_name): - """Method called when a new Zeroconf client is detected + """Method called when a new Zeroconf client is detected. + Return True if the zeroconf client is a Glances server Note: the return code will never be used """ @@ -137,7 +138,7 @@ class GlancesAutoDiscoverListener(object): return True def remove_service(self, zeroconf, srv_type, srv_name): - # Remove the server from the list + """Remove the server from the list.""" self.servers.remove_server(srv_name) logger.info( "Glances server %s removed from the autodetect list" % srv_name) @@ -145,7 +146,7 @@ class GlancesAutoDiscoverListener(object): class GlancesAutoDiscoverServer(object): - """Implementation of the Zeroconf protocol (server side for the Glances client)""" + """Implementation of the Zeroconf protocol (server side for the Glances client).""" def __init__(self, args=None): if zeroconf_tag: @@ -165,14 +166,14 @@ class GlancesAutoDiscoverServer(object): self.zeroconf_enable_tag = False def get_servers_list(self): - """Return the current server list (dict of dict)""" + """Return the current server list (dict of dict).""" if zeroconf_tag and self.zeroconf_enable_tag: return self.listener.get_servers_list() else: return [] def set_server(self, server_pos, key, value): - """Set the key to the value for the server_pos (position in the list)""" + """Set the key to the value for the server_pos (position in the list).""" if zeroconf_tag and self.zeroconf_enable_tag: self.listener.set_server(server_pos, key, value) diff --git a/glances/core/glances_client.py b/glances/core/glances_client.py index 23d7d44d575b346a39285b81ac4288a35257d6be..1b1ce176353bdd9648451fd632cef496be6449a3 100644 --- a/glances/core/glances_client.py +++ b/glances/core/glances_client.py @@ -38,7 +38,7 @@ from glances.outputs.glances_curses import GlancesCursesClient class GlancesClientTransport(Transport): - """This class overwrite the default XML-RPC transport and manage timeout""" + """This class overwrite the default XML-RPC transport and manage timeout.""" def set_timeout(self, timeout): self.timeout = timeout @@ -77,7 +77,7 @@ class GlancesClient(object): self.log_and_exit("Client couldn't create socket {0}: {1}".format(uri, e)) def log_and_exit(self, msg=''): - """Log and (exit)""" + """Log and exit.""" if not self.return_to_browser: logger.critical(msg) sys.exit(2) @@ -216,9 +216,7 @@ class GlancesClient(object): def serve_forever(self): """Main client loop.""" - exitkey = False - try: while True and not exitkey: # Update the stats diff --git a/glances/core/glances_client_browser.py b/glances/core/glances_client_browser.py index aff5750839578df5e452ce6da6dabb0126c0cb6e..804b29de179325a3cda88a2de9857c3bc3f2c57b 100644 --- a/glances/core/glances_client_browser.py +++ b/glances/core/glances_client_browser.py @@ -38,7 +38,7 @@ from glances.outputs.glances_curses import GlancesCursesBrowser class GlancesClientBrowser(object): - """This class creates and manages the TCP client browser (servers' list).""" + """This class creates and manages the TCP client browser (servers list).""" def __init__(self, config=None, args=None): # Store the arg/config @@ -58,9 +58,9 @@ class GlancesClientBrowser(object): self.screen = GlancesCursesBrowser(args=self.args) def get_servers_list(self): - """ - Return the current server list (list of dict) - Merge of static + autodiscover servers list + """Return the current server list (list of dict). + + Merge of static + autodiscover servers list. """ ret = [] @@ -72,7 +72,7 @@ class GlancesClientBrowser(object): return ret def __get_uri(self, server): - """Return the URI for the given server dict""" + """Return the URI for the given server dict.""" # Select the connection mode (with or without password) if server['password'] != "": return 'http://{0}:{1}@{2}:{3}'.format(server['username'], server['password'], @@ -218,9 +218,11 @@ class GlancesClientBrowser(object): self.screen.active_server = None def serve_forever(self): - """Wrapper to the serve_forever function - this function will restore the terminal to a sane state - before re-raising the exception and generating a traceback""" + """Wrapper to the serve_forever function. + + This function will restore the terminal to a sane state + before re-raising the exception and generating a traceback. + """ try: return self.__serve_forever() finally: diff --git a/glances/core/glances_cpu_percent.py b/glances/core/glances_cpu_percent.py index 88882f456773f7f822d90b17ff16396f9e06742d..c55b7f8632c80280cd554480b252e79fc5bbbc9b 100644 --- a/glances/core/glances_cpu_percent.py +++ b/glances/core/glances_cpu_percent.py @@ -25,7 +25,8 @@ from glances.core.glances_timer import Timer class CpuPercent(object): - """Get and strore the CPU percent""" + + """Get and store the CPU percent.""" def __init__(self, cached_time=1): self.cpu_percent = 0 @@ -36,7 +37,7 @@ class CpuPercent(object): self.cached_time = cached_time def get(self): - """Update and/or return the CPU using the PSUtil lib""" + """Update and/or return the CPU using the psutil library.""" # Never update more than 1 time per cached_time if self.timer.finished(): self.cpu_percent = psutil.cpu_percent(interval=0.0) diff --git a/glances/core/glances_logs.py b/glances/core/glances_logs.py index 108613f33aeb86ab4863d508141053b352b1c62b..14c6ee4dac573f5187eaf9daffa1d3cea135eaef 100644 --- a/glances/core/glances_logs.py +++ b/glances/core/glances_logs.py @@ -100,10 +100,10 @@ class GlancesLogs(object): proc_list=None, proc_desc="", peak_time=6): """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 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. - If event < peak_time the the alert is not setoff + If event < peak_time the the alert is not setoff. """ proc_list = proc_list or [] @@ -186,8 +186,8 @@ class GlancesLogs(object): def clean(self, critical=False): """Clean the logs list by deleting finished items. - By default, only delete WARNING message - If critical = True, also delete CRITICAL message + By default, only delete WARNING message. + If critical = True, also delete CRITICAL message. """ # Create a new clean list clean_logs_list = [] diff --git a/glances/core/glances_processes.py b/glances/core/glances_processes.py index 06ef056fd1a99014369f370b32f1117670472474..6c001be5df12a733da929bca691230d87ef01399 100644 --- a/glances/core/glances_processes.py +++ b/glances/core/glances_processes.py @@ -32,7 +32,7 @@ from glances.core.glances_timer import getTimeSinceLastUpdate, Timer def is_kernel_thread(proc): - """ Return True if proc is a kernel thread, False instead. """ + """Return True if proc is a kernel thread, False instead.""" try: return os.getpgid(proc.pid) == 0 # Python >= 3.3 raises ProcessLookupError, which inherits OSError @@ -43,10 +43,10 @@ def is_kernel_thread(proc): class ProcessTreeNode(object): - """ - Represent a process tree. + """Represent a process tree. - We avoid recursive algorithm to manipulate the tree because function calls are expensive with CPython. + We avoid recursive algorithm to manipulate the tree because function + calls are expensive with CPython. """ def __init__(self, process=None, stats=None, sort_key=None, sort_reverse=True, root=False): @@ -59,7 +59,7 @@ class ProcessTreeNode(object): self.is_root = root def __str__(self): - """ Return the tree as a string for debugging. """ + """Return the tree as a string for debugging.""" lines = [] nodes_to_print = collections.deque([collections.deque([("#", self)])]) while nodes_to_print: @@ -85,7 +85,10 @@ class ProcessTreeNode(object): return "\n".join(lines) def set_sorting(self, key, reverse): - """ Set sorting key or func for user with __iter__ (affects the whole tree from this node). """ + """Set sorting key or func for use with __iter__. + + This affects the whole tree from this node. + """ if self.sort_key != key or self.sort_reverse != reverse: nodes_to_flag_unsorted = collections.deque([self]) while nodes_to_flag_unsorted: @@ -96,7 +99,7 @@ class ProcessTreeNode(object): nodes_to_flag_unsorted.extend(current_node.children) def get_weight(self): - """ Return "weight" of a process and all its children for sorting. """ + """Return 'weight' of a process and all its children for sorting.""" if self.sort_key == 'name' or self.sort_key == 'username': return self.stats[self.sort_key] @@ -130,7 +133,7 @@ class ProcessTreeNode(object): return total def __iter__(self): - """ Iterator returning ProcessTreeNode in sorted order, recursively. """ + """Iterator returning ProcessTreeNode in sorted order, recursively.""" if not self.is_root: yield self if not self.children_sorted: @@ -144,12 +147,14 @@ class ProcessTreeNode(object): yield n def iter_children(self, exclude_incomplete_stats=True): - """ - Iterator returning ProcessTreeNode in sorted order (only children of this node, non recursive). + """Iterator returning ProcessTreeNode in sorted order. + + Return only children of this node, non recursive. - If exclude_incomplete_stats is True, exclude processes not having full statistics. - It can happen after a resort (change of sort key) because process stats are not grabbed immediately, - but only at next full update. + If exclude_incomplete_stats is True, exclude processes not + having full statistics. It can happen after a resort (change of + sort key) because process stats are not grabbed immediately, but + only at next full update. """ if not self.children_sorted: # optimization to avoid sorting twice (once when limiting the maximum processes to grab stats for, @@ -162,7 +167,10 @@ class ProcessTreeNode(object): yield child def find_process(self, process): - """ Search in tree for the ProcessTreeNode owning process, return it or None if not found. """ + """Search in tree for the ProcessTreeNode owning process. + + Return it or None if not found. + """ nodes_to_search = collections.deque([self]) while nodes_to_search: current_node = nodes_to_search.pop() @@ -172,7 +180,10 @@ class ProcessTreeNode(object): @staticmethod def build_tree(process_dict, sort_key, sort_reverse, hide_kernel_threads): - """ Build a process tree using using parent/child relationships, and return the tree root node. """ + """Build a process tree using using parent/child relationships. + + Return the tree root node. + """ tree_root = ProcessTreeNode(root=True) nodes_to_add_last = collections.deque() @@ -326,7 +337,7 @@ class GlancesProcesses(object): return self._process_filter_re def is_filtered(self, value): - """Return True if the value should be filtered""" + """Return True if the value should be filtered.""" if self.process_filter is None: # No filter => Not filtered return False @@ -335,15 +346,15 @@ class GlancesProcesses(object): return self.process_filter_re.match(value) is None def disable_kernel_threads(self): - """ Ignore kernel threads in process list. """ + """Ignore kernel threads in process list.""" self.no_kernel_threads = True def enable_tree(self): - """ Enable process tree. """ + """Enable process tree.""" self._enable_tree = True def is_tree_enabled(self): - """ Return True if process tree is enabled, False instead. """ + """Return True if process tree is enabled, False instead.""" return self._enable_tree @property @@ -356,7 +367,8 @@ class GlancesProcesses(object): def __get_mandatory_stats(self, proc, procstat): """ - Get mandatory_stats: need for the sorting/filter step + Get mandatory_stats: need for the sorting/filter step. + => cpu_percent, memory_percent, io_counters, name, cmdline """ procstat['mandatory_stats'] = True @@ -419,7 +431,8 @@ class GlancesProcesses(object): def __get_standard_stats(self, proc, procstat): """ - Get standard_stats: for all the displayed processes + Get standard_stats: for all the displayed processes. + => username, status, memory_info, cpu_times """ procstat['standard_stats'] = True @@ -452,7 +465,8 @@ class GlancesProcesses(object): def __get_extended_stats(self, proc, procstat): """ - Get extended_stats: only for top processes (see issue #403) + Get extended_stats: only for top processes (see issue #403). + => connections (UDP/TCP), memory_swap... """ procstat['extended_stats'] = True @@ -540,10 +554,7 @@ class GlancesProcesses(object): mandatory_stats=True, standard_stats=True, extended_stats=False): - """ - Get process stats of the proc processes (proc is returned psutil.process_iter()) - """ - + """Get stats of running processes.""" # Process ID (always) procstat = proc.as_dict(attrs=['pid']) @@ -559,9 +570,7 @@ class GlancesProcesses(object): return procstat def update(self): - """ - Update the processes stats - """ + """Update the processes stats.""" # Reset the stats self.processlist = [] self.processcount = {'total': 0, 'running': 0, 'sleeping': 0, 'thread': 0} diff --git a/glances/core/glances_snmp.py b/glances/core/glances_snmp.py index 95e1e602741bf02bad95ce608025f46017047672..20569a551c5fbba055d488fcf1cd850bf860b7da 100644 --- a/glances/core/glances_snmp.py +++ b/glances/core/glances_snmp.py @@ -50,7 +50,7 @@ class GlancesSNMPClient(object): self.auth = auth def __buid_result(self, varBinds): - """Build the results""" + """Build the results.""" ret = {} for name, val in varBinds: if str(val) == '': diff --git a/glances/core/glances_standalone.py b/glances/core/glances_standalone.py index 0e04f8c1a713c9f982403284cba46b236cac5613..e5cca2d97296c260b25fd30b915f60bae2ea73d0 100644 --- a/glances/core/glances_standalone.py +++ b/glances/core/glances_standalone.py @@ -99,9 +99,11 @@ class GlancesStandalone(object): self.stats.export(self.stats) def serve_forever(self): - """Wrapper to the serve_forever function - this function will restore the terminal to a sane state - before re-raising the exception and generating a traceback""" + """Wrapper to the serve_forever function. + + This function will restore the terminal to a sane state + before re-raising the exception and generating a traceback. + """ try: return self.__serve_forever() finally: diff --git a/glances/core/glances_staticlist.py b/glances/core/glances_staticlist.py index 58db7eb978109596bd86e0f1c0ca428f5a4b9f8d..e754552e1fa387bd95573e1a4205ce76dcef484a 100644 --- a/glances/core/glances_staticlist.py +++ b/glances/core/glances_staticlist.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 . -"""Manage the Glances server static list """ +"""Manage the Glances server static list.""" # System lib from socket import gaierror, gethostbyname @@ -28,7 +28,7 @@ from glances.core.glances_logging import logger class GlancesStaticServer(object): - """Manage the static servers list for the client browser""" + """Manage the static servers list for the client browser.""" _section = "serverlist" @@ -39,8 +39,7 @@ class GlancesStaticServer(object): self._server_list = self.load(config) def load(self, config): - """Load the server list from the configuration file""" - + """Load the server list from the configuration file.""" server_list = [] if config is None: @@ -85,9 +84,9 @@ class GlancesStaticServer(object): return server_list def get_servers_list(self): - """Return the current server list (dict of dict)""" + """Return the current server list (dict of dict).""" return self._server_list def set_server(self, server_pos, key, value): - """Set the key to the value for the server_pos (position in the list)""" + """Set the key to the value for the server_pos (position in the list).""" self._server_list[server_pos][key] = value diff --git a/glances/core/glances_stats.py b/glances/core/glances_stats.py index 100d7cfd4195b8772f67bc73c3679cde4007371f..61cbc90babf023bde8d195da712f7c735648b047 100644 --- a/glances/core/glances_stats.py +++ b/glances/core/glances_stats.py @@ -157,7 +157,9 @@ class GlancesStats(object): def export(self, input_stats=None): """Export all the stats. - Each export module is ran in a dedicated thread.""" + + Each export module is ran in a dedicated thread. + """ # threads = [] input_stats = input_stats or {} @@ -169,11 +171,11 @@ class GlancesStats(object): thread.start() def getAll(self): - """Return all the stats (list)""" + """Return all the stats (list).""" return [self._plugins[p].get_raw() for p in self._plugins] def getAllAsDict(self): - """Return all the stats (dict)""" + """Return all the stats (dict).""" # Python > 2.6 # {p: self._plugins[p].get_raw() for p in self._plugins} ret = {} @@ -186,18 +188,18 @@ class GlancesStats(object): return [self._plugins[p].limits for p in self._plugins] def getAllLimitsAsDict(self): - """Return all the stats limits (dict)""" + """Return all the stats limits (dict).""" ret = {} for p in self._plugins: ret[p] = self._plugins[p].limits return ret def getAllViews(self): - """Return the plugins views""" + """Return the plugins views.""" return [self._plugins[p].get_views() for p in self._plugins] def getAllViewsAsDict(self): - """Return all the stats views (dict)""" + """Return all the stats views (dict).""" ret = {} for p in self._plugins: ret[p] = self._plugins[p].get_views() @@ -215,7 +217,7 @@ class GlancesStats(object): return None def end(self): - """End of the Glances stats""" + """End of the Glances stats.""" # Close the export module for e in self._exports: self._exports[e].exit() @@ -244,7 +246,7 @@ class GlancesStatsServer(GlancesStats): self.all_stats = self._set_stats(input_stats) def _set_stats(self, input_stats): - """Set the stats to the input_stats one""" + """Set the stats to the input_stats one.""" # Build the all_stats with the get_raw() method of the plugins ret = collections.defaultdict(dict) for p in self._plugins: @@ -252,11 +254,11 @@ class GlancesStatsServer(GlancesStats): return ret def getAll(self): - """Return the stats as a list""" + """Return the stats as a list.""" return self.all_stats def getAllAsDict(self): - """Return the stats as a dict""" + """Return the stats as a dict.""" # Python > 2.6 # return {p: self.all_stats[p] for p in self._plugins} ret = {} @@ -363,7 +365,7 @@ class GlancesStatsClientSNMP(GlancesStats): return ret def get_system_name(self, oid_system_name): - """Get the short os name from the OS name OID string""" + """Get the short os name from the OS name OID string.""" short_system_name = None if oid_system_name == '': diff --git a/glances/exports/glances_export.py b/glances/exports/glances_export.py index 0319281f53b2a703127032ba8a853d7130e6e665..5943ad57fabe17811c1861d9b2fab639d247be1d 100644 --- a/glances/exports/glances_export.py +++ b/glances/exports/glances_export.py @@ -32,7 +32,7 @@ from glances.core.glances_logging import logger class GlancesExport(object): - """Main class for Glances' export IF.""" + """Main class for Glances export IF.""" def __init__(self, config=None, args=None): """Init the export class.""" @@ -53,7 +53,7 @@ class GlancesExport(object): logger.debug("Finalise export interface %s" % self.export_name) def plugins_to_export(self): - """Return the list of plugins to export""" + """Return the list of plugins to export.""" return ['cpu', 'percpu', 'load', diff --git a/glances/exports/glances_history.py b/glances/exports/glances_history.py index 411a985605bc398bb9029668079e1cacf499d214..6caaf353660f715f19ac1960018119e11e52877e 100644 --- a/glances/exports/glances_history.py +++ b/glances/exports/glances_history.py @@ -39,23 +39,21 @@ else: class GlancesHistory(object): - """This class define the object to manage stats history""" + """This class define the object to manage stats history.""" def __init__(self, output_folder): self.output_folder = output_folder def get_output_folder(self): - """Return the output folder where the graph are generated""" + """Return the output folder where the graph are generated.""" return self.output_folder def graph_enabled(self): - """Return True if Glances can generaate history graphs""" + """Return True if Glances can generate history graphs.""" return matplotlib_check def reset(self, stats): - """ - Reset all the history - """ + """Reset all the history.""" if not self.graph_enabled(): return False for p in stats.getAllPlugins(): @@ -65,9 +63,7 @@ class GlancesHistory(object): return True def get_graph_color(self, item): - """ - Get the item's color - """ + """Get the item's color.""" try: ret = item['color'] except KeyError: @@ -76,15 +72,11 @@ class GlancesHistory(object): return ret def get_graph_legend(self, item): - """ - Get the item's legend - """ + """Get the item's legend.""" return item['name'] def get_graph_yunit(self, item, pre_label=''): - """ - Get the item's Y unit - """ + """Get the item's Y unit.""" try: unit = " (%s)" % item['y_unit'] except KeyError: @@ -96,9 +88,9 @@ class GlancesHistory(object): return "%s%s" % (label, unit) def generate_graph(self, stats): - """ - Generate graphs from plugins history - Return the number of output files generated by the function + """Generate graphs from plugins history. + + Return the number of output files generated by the function. """ if not self.graph_enabled(): return 0 diff --git a/glances/exports/glances_influxdb.py b/glances/exports/glances_influxdb.py index 4b0ab60b3f42ad480ca06846dfb9748c52db5fc3..bab01bdcf5901a61221497ac7ebab00b2ba2f943 100644 --- a/glances/exports/glances_influxdb.py +++ b/glances/exports/glances_influxdb.py @@ -57,7 +57,7 @@ class Export(GlancesExport): self.client = self.init() def load_conf(self, section="influxdb"): - """Load the InfluxDb configuration in the Glances configuration file""" + """Load the InfluxDb configuration in the Glances configuration file.""" if self.config is None: return False try: @@ -82,7 +82,7 @@ class Export(GlancesExport): return True def init(self): - """Init the connection to the InfluxDB server""" + """Init the connection to the InfluxDB server.""" if not self.export_enable: return None @@ -116,7 +116,7 @@ class Export(GlancesExport): return db def export(self, name, columns, points): - """Write the points to the InfluxDB server""" + """Write the points to the InfluxDB server.""" # Manage prefix if self.prefix is not None: name = self.prefix + '.' + name diff --git a/glances/exports/glances_rabbitmq.py b/glances/exports/glances_rabbitmq.py index c428008008740974ffef2f0f72b2ec1f6810469d..c0400883602acc48d5d91c464f0624d8bbbcbadb 100644 --- a/glances/exports/glances_rabbitmq.py +++ b/glances/exports/glances_rabbitmq.py @@ -58,7 +58,7 @@ class Export(GlancesExport): self.client = self.init() def load_conf(self, section="rabbitmq"): - """Load the rabbitmq configuration in the Glances configuration file""" + """Load the rabbitmq configuration in the Glances configuration file.""" if self.config is None: return False try: @@ -78,7 +78,7 @@ class Export(GlancesExport): return True def init(self): - """Init the connection to the rabbitmq server""" + """Init the connection to the rabbitmq server.""" if not self.export_enable: return None try: @@ -91,7 +91,7 @@ class Export(GlancesExport): return None def export(self, name, columns, points): - """Write the points in RabbitMQ""" + """Write the points in RabbitMQ.""" data = "hostname="+self.hostname+", name="+name+", dateinfo="+datetime.datetime.utcnow().isoformat() for i in range(0, len(columns)): if not isinstance(points[i], Number): diff --git a/glances/exports/glances_statsd.py b/glances/exports/glances_statsd.py index c83fc254e570f0eb042d5958c6b7752be5de101b..596d3ebe9878affc45aa872263281309b867cd24 100644 --- a/glances/exports/glances_statsd.py +++ b/glances/exports/glances_statsd.py @@ -60,7 +60,7 @@ class Export(GlancesExport): prefix=self.prefix) def load_conf(self, section="statsd"): - """Load the Statsd configuration in the Glances configuration file""" + """Load the Statsd configuration in the Glances configuration file.""" if self.config is None: return False try: @@ -82,7 +82,7 @@ class Export(GlancesExport): return True def init(self, prefix='glances'): - """Init the connection to the Statsd server""" + """Init the connection to the Statsd server.""" if not self.export_enable: return None return StatsClient(self.host, @@ -90,7 +90,7 @@ class Export(GlancesExport): prefix=prefix) def export(self, name, columns, points): - """Export the stats to the Statsd server""" + """Export the stats to the Statsd server.""" for i in range(0, len(columns)): if not isinstance(points[i], Number): continue diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py index 2d3d297440d2b549b5bd358236a5d11d5cbe1774..e9a9d98e6788a32d61f384cd386a32aa414b6d7e 100644 --- a/glances/outputs/glances_bars.py +++ b/glances/outputs/glances_bars.py @@ -25,7 +25,8 @@ import locale class Bar(object): - """Manage bar (progression or status) + + r"""Manage bar (progression or status). import sys import time @@ -35,7 +36,6 @@ class Bar(object): print("\r%s" % b), time.sleep(0.1) sys.stdout.flush() - """ def __init__(self, size, diff --git a/glances/outputs/glances_bottle.py b/glances/outputs/glances_bottle.py index c5529685ba37abec75242c764826bd09b3954463..7d205cfe0364b412508a78ca0ad788b51f137a45 100644 --- a/glances/outputs/glances_bottle.py +++ b/glances/outputs/glances_bottle.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 . + """Web interface class.""" -# Import Glances libs -# Import mandatory Bottle lib import json import os @@ -27,7 +26,6 @@ import sys from glances.core.glances_globals import is_windows from glances.core.glances_logging import logger - try: from bottle import Bottle, static_file, abort, response, request except ImportError: @@ -143,10 +141,9 @@ class GlancesBottle(object): return static_file('favicon.ico', root=self.STATIC_PATH) def _api_help(self): - """ - Glances API RESTFul implementation - Return the help data - or 404 error + """Glances API RESTFul implementation. + + Return the help data or 404 error. """ response.content_type = 'application/json' @@ -195,8 +192,8 @@ class GlancesBottle(object): return plist def _api_all(self): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON representation of all the plugins HTTP/200 if OK HTTP/400 if plugin is not found @@ -224,8 +221,8 @@ class GlancesBottle(object): return f.read() def _api_all_limits(self): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON representation of all the plugins limits HTTP/200 if OK HTTP/400 if plugin is not found @@ -241,8 +238,8 @@ class GlancesBottle(object): return limits def _api_all_views(self): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON representation of all the plugins views HTTP/200 if OK HTTP/400 if plugin is not found @@ -258,8 +255,8 @@ class GlancesBottle(object): return limits def _api(self, plugin): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON representation of a given plugin HTTP/200 if OK HTTP/400 if plugin is not found @@ -281,8 +278,8 @@ class GlancesBottle(object): return statval def _api_limits(self, plugin): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON limits of a given plugin HTTP/200 if OK HTTP/400 if plugin is not found @@ -304,8 +301,8 @@ class GlancesBottle(object): return ret def _api_views(self, plugin): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON views of a given plugin HTTP/200 if OK HTTP/400 if plugin is not found @@ -327,8 +324,8 @@ class GlancesBottle(object): return ret def _api_item(self, plugin, item): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the JSON represenation of the couple plugin/item HTTP/200 if OK HTTP/400 if plugin is not found @@ -351,8 +348,8 @@ class GlancesBottle(object): return plist def _api_value(self, plugin, item, value): - """ - Glances API RESTFul implementation + """Glances API RESTFul implementation. + Return the process stats (dict) for the given item=value HTTP/200 if OK HTTP/400 if plugin is not found diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index c844450915e38165c0213daabcab911ac6f37612..1cea00985c62c3f51478573df3dcad96af1e19cc 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -47,9 +47,9 @@ else: class _GlancesCurses(object): - """ - This class manages the curses display (and key pressed). - Note: It is a private class, use GlancesCursesClient or GlancesCursesBrowser + """This class manages the curses display (and key pressed). + + Note: It is a private class, use GlancesCursesClient or GlancesCursesBrowser. """ def __init__(self, args=None): @@ -202,11 +202,12 @@ class _GlancesCurses(object): 'Stats history disabled because MatPlotLib is not installed') def set_cursor(self, value): - """Configure the curse cursor apparence - 0: invisible - 1: visible - 2: very visible - """ + """Configure the curse cursor apparence. + + 0: invisible + 1: visible + 2: very visible + """ if hasattr(curses, 'curs_set'): try: curses.curs_set(value) @@ -369,26 +370,26 @@ class _GlancesCurses(object): curses.endwin() def init_line_column(self): - """Init the line and column position for the curses inteface""" + """Init the line and column position for the curses inteface.""" self.init_line() self.init_column() def init_line(self): - """Init the line position for the curses inteface""" + """Init the line position for the curses inteface.""" self.line = 0 self.next_line = 0 def init_column(self): - """Init the column position for the curses inteface""" + """Init the column position for the curses inteface.""" self.column = 0 self.next_column = 0 def new_line(self): - """New line in the curses interface""" + """New line in the curses interface.""" self.line = self.next_line def new_column(self): - """New column in the curses interface""" + """New column in the curses interface.""" self.column = self.next_column def display(self, stats, cs_status=None): @@ -656,18 +657,20 @@ class _GlancesCurses(object): input_size=30, input_value=None): """ + Display a centered popup. + If is_input is False: Display a centered popup with the given message during duration seconds If size_x and size_y: set the popup size else set it automatically Return True if the popup could be displayed + If is_input is True: Display a centered popup with the given message and a input field If size_x and size_y: set the popup size else set it automatically Return the input string or None if the field is empty """ - # Center the popup sentence_list = message.split('\n') if size_x is None: @@ -898,21 +901,21 @@ class _GlancesCurses(object): class GlancesCursesStandalone(_GlancesCurses): - """Class for the Glances' curse standalone""" + """Class for the Glances curse standalone.""" pass class GlancesCursesClient(_GlancesCurses): - """Class for the Glances' curse client""" + """Class for the Glances curse client.""" pass class GlancesCursesBrowser(_GlancesCurses): - """Class for the Glances' curse client browser""" + """Class for the Glances curse client browser.""" def __init__(self, args=None): # Init the father class @@ -961,14 +964,14 @@ class GlancesCursesBrowser(_GlancesCurses): self.cursor_position = position def cursor_up(self, servers_list): - """Set the cursor to position N-1 in the list""" + """Set the cursor to position N-1 in the list.""" if self.cursor_position > 0: self.cursor_position -= 1 else: self.cursor_position = len(servers_list) - 1 def cursor_down(self, servers_list): - """Set the cursor to position N-1 in the list""" + """Set the cursor to position N-1 in the list.""" if self.cursor_position < len(servers_list) - 1: self.cursor_position += 1 else: @@ -1028,13 +1031,15 @@ class GlancesCursesBrowser(_GlancesCurses): def flush(self, servers_list): """Update the servers' list screen. + servers_list: List of dict with servers stats """ self.erase() self.display(servers_list) def display(self, servers_list): - """Display the servers list + """Display the servers list. + Return: True if the stats have been displayed False if the stats have not been displayed (no server available) diff --git a/glances/plugins/glances_alert.py b/glances/plugins/glances_alert.py index 629a93f7ddac24838160687d53e63b4638ae15c5..660ba01a8bebc8e727029b2a7df5e4a003c45a2b 100644 --- a/glances/plugins/glances_alert.py +++ b/glances/plugins/glances_alert.py @@ -29,7 +29,7 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances' alert plugin. + """Glances alert plugin. Only for display. """ @@ -123,9 +123,7 @@ class Plugin(GlancesPlugin): return ret def approx_equal(self, a, b, tolerance=0.0): - """ - Compare a with b using the tolerance (if numerical) - """ + """Compare a with b using the tolerance (if numerical).""" if str(int(a)).isdigit() and str(int(b)).isdigit(): return abs(a - b) <= max(abs(a), abs(b)) * tolerance else: diff --git a/glances/plugins/glances_batpercent.py b/glances/plugins/glances_batpercent.py index c971ee6b9a12a236b9b56eac53f9a99bdef27083..1778ff958a994a61ba1cca43df5ba3f3ba384c77 100644 --- a/glances/plugins/glances_batpercent.py +++ b/glances/plugins/glances_batpercent.py @@ -32,7 +32,7 @@ except ImportError: class Plugin(GlancesPlugin): - """Glances' battery capacity plugin. + """Glances battery capacity plugin. stats is a list """ diff --git a/glances/plugins/glances_core.py b/glances/plugins/glances_core.py index d90575ef9b156446c61c56cc9faef4594d654229..5a91c5b2d47a1c1beb41b84bc2924aae1a739783 100644 --- a/glances/plugins/glances_core.py +++ b/glances/plugins/glances_core.py @@ -26,7 +26,7 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances' CPU core plugin. + """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 fcd915e4c928ace12172b6f91c937ce06b0fb15b..06750eebbcc76f802204dc40d7aee71f57a0857a 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -141,7 +141,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) @@ -160,7 +160,7 @@ class Plugin(GlancesPlugin): self.views[key]['optional'] = True def msg_curse(self, args=None): - """Return the list to display in the UI""" + """Return the list to display in the UI.""" # Init the return message ret = [] diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index 465560d73871c2e38b22177d82905194fa148519..bb45cb1ab386a7851a03613e869c90b17a924d93 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -36,7 +36,7 @@ items_history_list = [{'name': 'read_bytes', 'color': '#00FF00', 'y_unit': 'B/s' class Plugin(GlancesPlugin): - """Glances' disks I/O plugin. + """Glances disks I/O plugin. stats is a list """ @@ -53,7 +53,7 @@ class Plugin(GlancesPlugin): self.reset() def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return 'disk_name' def reset(self): @@ -127,7 +127,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index f80e70097de0a9377e7b408b22d0c40752391908..4ea1203f6caf5b157d8872bc19f8c6f26df730e2 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -42,7 +42,7 @@ else: class Plugin(GlancesPlugin): - """Glances' Docker plugin. + """Glances Docker plugin. stats is a list """ @@ -61,7 +61,7 @@ class Plugin(GlancesPlugin): self.docker_client = False def connect(self, version=None): - """Connect to the Docker server""" + """Connect to the Docker server.""" # Init connection to the Docker API try: if version is None: @@ -113,8 +113,7 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): - """Update Docker stats using the input method. - """ + """Update Docker stats using the input method.""" # Reset stats self.reset() @@ -188,9 +187,11 @@ class Plugin(GlancesPlugin): return self.stats def get_docker_cpu_old(self, container_id): - """Return the container CPU usage by reading /sys/fs/cgroup/... + """Return the container CPU usage by reading /sys/fs/cgroup/. + Input: id is the full container id - Output: a dict {'total': 1.49, 'user': 0.65, 'system': 0.84}""" + Output: a dict {'total': 1.49, 'user': 0.65, 'system': 0.84} + """ ret = {} # Read the stats try: @@ -208,11 +209,12 @@ class Plugin(GlancesPlugin): return ret def get_docker_cpu(self, container_id, all_stats): - """Return the container CPU usage + """Return the container CPU usage. + Input: id is the full container id all_stats is the output of the stats method of the Docker API - Output: a dict {'total': 1.49}""" - + Output: a dict {'total': 1.49} + """ cpu_new = {} ret = {'total': 0.0} @@ -263,9 +265,11 @@ class Plugin(GlancesPlugin): return ret def get_docker_memory_old(self, container_id): - """Return the container MEMORY usage by reading /sys/fs/cgroup/... + """Return the container MEMORY usage by reading /sys/fs/cgroup/. + Input: id is the full container id - Output: a dict {'rss': 1015808, 'cache': 356352}""" + Output: a dict {'rss': 1015808, 'cache': 356352} + """ ret = {} # Read the stats try: @@ -281,10 +285,12 @@ class Plugin(GlancesPlugin): return ret def get_docker_memory(self, container_id, all_stats): - """Return the container MEMORY + """Return the container MEMORY. + Input: id is the full container id all_stats is the output of the stats method of the Docker API - Output: a dict {'rss': 1015808, 'cache': 356352, 'usage': ..., 'max_usage': ...}""" + Output: a dict {'rss': 1015808, 'cache': 356352, 'usage': ..., 'max_usage': ...} + """ ret = {} # Read the stats try: @@ -301,10 +307,11 @@ class Plugin(GlancesPlugin): return ret def get_docker_network(self, container_id, all_stats): - """Return the container network usage using the Docker API (v1.0 or higher) - Input: id is the full container id - Output: a dict {'time_since_update': 3000, 'rx': 10, 'tx': 65}""" + """Return the container network usage using the Docker API (v1.0 or higher). + Input: id is the full container id + Output: a dict {'time_since_update': 3000, 'rx': 10, 'tx': 65}. + """ # Init the returned dict network_new = {} @@ -348,7 +355,7 @@ class Plugin(GlancesPlugin): return network_new def get_user_ticks(self): - """return the user ticks by reading the environment variable""" + """Return the user ticks by reading the environment variable.""" return os.sysconf(os.sysconf_names['SC_CLK_TCK']) def msg_curse(self, args=None): @@ -434,7 +441,7 @@ class Plugin(GlancesPlugin): return ret def container_alert(self, status): - """Analyse the container status""" + """Analyse the container status.""" if "Paused" in status: return 'CAREFUL' else: diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py index c18220cccdac940937251c2b2f003dafba71d9b4..b06e8225890290ce55a46d88d76ed66083cd86ac 100644 --- a/glances/plugins/glances_fs.py +++ b/glances/plugins/glances_fs.py @@ -63,7 +63,7 @@ items_history_list = [{'name': 'percent', 'color': '#00FF00'}] class Plugin(GlancesPlugin): - """Glances' file system plugin. + """Glances file system plugin. stats is a list """ @@ -80,7 +80,7 @@ class Plugin(GlancesPlugin): self.reset() def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return 'mnt_point' def reset(self): @@ -183,7 +183,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) diff --git a/glances/plugins/glances_hddtemp.py b/glances/plugins/glances_hddtemp.py index 27a4740dc2ccb64fc5c91a5769111dd60d1c9830..f697efa9b5836a3347ffb3da77abed32590e4f61 100644 --- a/glances/plugins/glances_hddtemp.py +++ b/glances/plugins/glances_hddtemp.py @@ -30,7 +30,7 @@ from glances.core.glances_logging import logger class Plugin(GlancesPlugin): - """Glances' HDD temperature sensors plugin. + """Glances HDD temperature sensors plugin. stats is a list """ diff --git a/glances/plugins/glances_help.py b/glances/plugins/glances_help.py index 73cdf4cc36ef5f30ac0d45c15efc5f98943b186a..ef9db5c00a8709f7a08baf581ae62de415f65d93 100644 --- a/glances/plugins/glances_help.py +++ b/glances/plugins/glances_help.py @@ -30,7 +30,7 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances' help plugin.""" + """Glances help plugin.""" def __init__(self, args=None, config=None): """Init the plugin.""" diff --git a/glances/plugins/glances_ip.py b/glances/plugins/glances_ip.py index 18685589d342032d7da2ff3c162f4ce71002da65..e3491ac7c881975b62f8823f801a456f2062fdd5 100644 --- a/glances/plugins/glances_ip.py +++ b/glances/plugins/glances_ip.py @@ -33,7 +33,7 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances' IP Plugin. + """Glances IP Plugin. stats is a dict """ @@ -86,7 +86,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) @@ -97,7 +97,6 @@ class Plugin(GlancesPlugin): def msg_curse(self, args=None): """Return the dict to display in the curse interface.""" - # Init the return message ret = [] @@ -117,6 +116,8 @@ class Plugin(GlancesPlugin): @staticmethod def ip_to_cidr(ip): - # Convert IP address to CIDR - # Exemple: '255.255.255.0' will return 24 + """Convert IP address to CIDR. + + Example: '255.255.255.0' will return 24 + """ return sum(map(lambda x: int(x) << 8, ip.split('.'))) // 8128 diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py index 960147b260a7f899cdb7ac5c5eee2d9092077c44..8f7ea2e0de8889244e1a67daaac6dc1bae985bf2 100644 --- a/glances/plugins/glances_load.py +++ b/glances/plugins/glances_load.py @@ -44,7 +44,7 @@ items_history_list = [{'name': 'min1', 'color': '#0000FF'}, class Plugin(GlancesPlugin): - """Glances' load plugin. + """Glances load plugin. stats is a dict """ @@ -117,7 +117,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) diff --git a/glances/plugins/glances_mem.py b/glances/plugins/glances_mem.py index fa5f985d2832177d5141b560d0756a7cb66850be..106dfabbdbeffb904f7872858357bcde129a0377 100644 --- a/glances/plugins/glances_mem.py +++ b/glances/plugins/glances_mem.py @@ -161,7 +161,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) diff --git a/glances/plugins/glances_memswap.py b/glances/plugins/glances_memswap.py index ebe922e5f781df5cfad82aa219d77e99eb38356d..00a3322bfab492add9696bb1f225783e11ab061a 100644 --- a/glances/plugins/glances_memswap.py +++ b/glances/plugins/glances_memswap.py @@ -41,7 +41,7 @@ items_history_list = [{'name': 'percent', 'color': '#00FF00', 'y_unit': '%'}] class Plugin(GlancesPlugin): - """Glances' swap memory plugin. + """Glances swap memory plugin. stats is a dict """ @@ -136,7 +136,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) diff --git a/glances/plugins/glances_monitor.py b/glances/plugins/glances_monitor.py index 55e9ba7fced4548f02ce0955d19af89d7d878ee1..caacd03d7e124615205103372dc05536397bb875 100644 --- a/glances/plugins/glances_monitor.py +++ b/glances/plugins/glances_monitor.py @@ -27,7 +27,7 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances' monitor plugin.""" + """Glances monitor plugin.""" def __init__(self, args=None): """Init the plugin.""" diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index b3824a6da920117642be8bb5e02a439bb0af8989..29a73e5eeb3c320ee67b4c9264b99ce4287f7077 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -43,7 +43,7 @@ items_history_list = [{'name': 'rx', 'color': '#00FF00', 'y_unit': 'bit/s'}, class Plugin(GlancesPlugin): - """Glances' network Plugin. + """Glances network plugin. stats is a list """ @@ -59,7 +59,7 @@ class Plugin(GlancesPlugin): self.reset() def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return 'interface_name' def reset(self): @@ -194,7 +194,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) @@ -209,7 +209,6 @@ class Plugin(GlancesPlugin): def msg_curse(self, args=None, max_width=None): """Return the dict to display in the curse interface.""" - # Init the return message ret = [] diff --git a/glances/plugins/glances_percpu.py b/glances/plugins/glances_percpu.py index 050f855d50ba1388f9c081f7a2981785d0b252e1..389c8033d7b5ee53377983467e450be48f615764 100644 --- a/glances/plugins/glances_percpu.py +++ b/glances/plugins/glances_percpu.py @@ -43,7 +43,7 @@ class Plugin(GlancesPlugin): self.reset() def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return 'cpu_number' def reset(self): diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 52eae72cc8e2a095c300001b4f143687667bf0cb..8c95038ffeaf065554032148a6514417bd79c763 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -37,7 +37,7 @@ from glances.core.glances_actions import GlancesActions class GlancesPlugin(object): - """Main class for Glances' plugin.""" + """Main class for Glances plugin.""" def __init__(self, args=None, items_history_list=None): """Init the plugin of plugins class.""" @@ -80,18 +80,18 @@ class GlancesPlugin(object): return str(self.stats) def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return None def add_item_history(self, key, value): - """Add an new item (key, value) to the current history""" + """Add an new item (key, value) to the current history.""" try: self.stats_history[key].append(value) except KeyError: self.stats_history[key] = [value] def init_stats_history(self): - """Init the stats history (dict of list)""" + """Init the stats history (dict of list).""" ret = None if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None: init_list = [i['name'] for i in self.get_items_history_list()] @@ -101,7 +101,7 @@ class GlancesPlugin(object): return ret def reset_stats_history(self): - """Reset the stats history (dict of list)""" + """Reset the stats history (dict of list).""" if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None: reset_list = [i['name'] for i in self.get_items_history_list()] logger.debug("Reset history for plugin {0} (items: {0})".format( @@ -109,7 +109,7 @@ class GlancesPlugin(object): self.stats_history = {} def update_stats_history(self, item_name=''): - """Update stats history""" + """Update stats history.""" if (self.stats and self.args is not None and self.args.enable_history and self.get_items_history_list() is not None): @@ -128,11 +128,11 @@ class GlancesPlugin(object): self.add_item_history(i['name'], self.stats[i['name']]) def get_stats_history(self): - """Return the stats history""" + """Return the stats history.""" return self.stats_history def get_items_history_list(self): - """Return the items history list""" + """Return the items history list.""" return self.items_history_list @property @@ -224,12 +224,12 @@ class GlancesPlugin(object): return self.stats def get_stats(self): - """Return the stats object in JSON format""" + """Return the stats object in JSON format.""" return json.dumps(self.stats) def get_stats_item(self, item): - """ - Return the stats object for a specific item (in JSON format) + """Return the stats object for a specific item in JSON format. + Stats should be a list of dict (processlist, network...) """ if type(self.stats) is not list: @@ -250,8 +250,8 @@ class GlancesPlugin(object): return None def get_stats_value(self, item, value): - """ - Return the stats object for a specific item=value (in JSON format) + """Return the stats object for a specific item=value in JSON format. + Stats should be a list of dict (processlist, network...) """ if type(self.stats) is not list: @@ -267,7 +267,8 @@ class GlancesPlugin(object): return None def update_views(self): - """Default builder fo the stats views + """Default builder fo the stats views. + The V of MVC A dict of dict with the needed information to display the stats. Example for the stat xxx: @@ -307,12 +308,13 @@ class GlancesPlugin(object): def get_views(self, item=None, key=None, option=None): """Return the views object. + If key is None, return all the view for the current plugin else if option is None return the view for the specific key (all option) else return the view fo the specific key/option - Specify item if the stats are stored in a dict of dict (ex: NETWORK, FS...)""" - + Specify item if the stats are stored in a dict of dict (ex: NETWORK, FS...) + """ if item is None: item_views = self.views else: @@ -436,7 +438,7 @@ class GlancesPlugin(object): return self.get_alert(current, minimum, maximum, header, log=True) def __get_limit(self, criticity, stat_name=""): - """Return the limit value for the alert""" + """Return the limit value for the alert.""" # Get the limit for stat + header # Exemple: network_wlan0_rx_careful try: @@ -450,7 +452,7 @@ class GlancesPlugin(object): return limit def __get_limit_action(self, criticity, stat_name=""): - """Return the action for the alert""" + """Return the action for the alert.""" # Get the action for stat + header # Exemple: network_wlan0_rx_careful_action try: @@ -464,7 +466,7 @@ class GlancesPlugin(object): return ret def __get_limit_log(self, stat_name, default_action=False): - """Return the log tag for the alert""" + """Return the log tag for the alert.""" # Get the log tag for stat + header # Exemple: network_wlan0_rx_log try: @@ -482,7 +484,10 @@ class GlancesPlugin(object): return log_tag[0].lower() == 'true' def get_conf_value(self, value, header="", plugin_name=None): - """Return the configuration (header_) value for the current plugin (or the one given by the plugin_name var)""" + """Return the configuration (header_) value for the current plugin. + + ...or the one given by the plugin_name var. + """ if plugin_name is None: # If not default use the current plugin name plugin_name = self.plugin_name @@ -501,7 +506,7 @@ class GlancesPlugin(object): return value in self.get_conf_value('hide', header=header) def has_alias(self, header): - """Return the alias name for the relative header or None if nonexist""" + """Return the alias name for the relative header or None if nonexist.""" try: return self._limits[self.plugin_name + '_' + header + '_' + 'alias'][0] except (KeyError, IndexError): @@ -541,7 +546,7 @@ class GlancesPlugin(object): def curse_add_line(self, msg, decoration="DEFAULT", optional=False, additional=False, splittable=False): - """Return a dict with + """Return a dict with. Where: msg: string @@ -634,7 +639,7 @@ class GlancesPlugin(object): return '{0!s}'.format(number) def _log_result_decorator(fct): - """Log (DEBUG) the result of the function fct""" + """Log (DEBUG) the result of the function fct.""" def wrapper(*args, **kw): ret = fct(*args, **kw) if is_py3: diff --git a/glances/plugins/glances_processcount.py b/glances/plugins/glances_processcount.py index 8bbdebad24b3a53d70695163cce462e64347edec..2841b7911ffcb1670ab3236df9f00145cc787576 100644 --- a/glances/plugins/glances_processcount.py +++ b/glances/plugins/glances_processcount.py @@ -29,7 +29,7 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances' processes plugin. + """Glances process count plugin. stats is a list """ diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index 341ba88ebd3262d7947cfdf88dfe105392d1c23b..4e3198dbfecb960c1badd59936a5d3f6be088d68 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -64,7 +64,7 @@ class Plugin(GlancesPlugin): # Note: 'glances_processes' is already init in the glances_processes.py script def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return 'pid' def reset(self): @@ -91,7 +91,7 @@ class Plugin(GlancesPlugin): return self.stats def get_process_tree_curses_data(self, node, args, first_level=True, max_node_count=None): - """ Get curses data to display for a process tree. """ + """Get curses data to display for a process tree.""" ret = [] node_count = 0 if not node.is_root and ((max_node_count is None) or (max_node_count > 0)): @@ -122,7 +122,7 @@ class Plugin(GlancesPlugin): return ret def add_tree_decoration(self, child_data, is_last_child, first_level): - """ Add tree curses decoration and indentation to a subtree. """ + """Add tree curses decoration and indentation to a subtree.""" # find process command indices in messages pos = [] for i, m in enumerate(child_data): @@ -170,7 +170,7 @@ class Plugin(GlancesPlugin): return child_data def get_process_curses_data(self, p, first, args): - """ Get curses data to display for a process. """ + """Get curses data to display for a process.""" ret = [self.curse_new_line()] # CPU if 'cpu_percent' in p and p['cpu_percent'] is not None and p['cpu_percent'] != '': diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index 7df0fddbc2af37d8ddd5b61980822aad8efcfced..1b5f206fe052119f311229dfe7395e1081e97b54 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -71,7 +71,7 @@ class Plugin(GlancesPlugin): return self.stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) @@ -82,7 +82,7 @@ class Plugin(GlancesPlugin): self.views[key]['decoration'] = self.get_alert(self.stats[key], header=key) def msg_curse(self, args=None, max_width=10): - """Return the list to display in the UI""" + """Return the list to display in the UI.""" # Init the return message ret = [] diff --git a/glances/plugins/glances_raid.py b/glances/plugins/glances_raid.py index 1935b64c4f0f7b1e2bc5212dfdb75e88b1784957..d0482c8d9ad7e9335676c4d5f654a1103aef6298 100644 --- a/glances/plugins/glances_raid.py +++ b/glances/plugins/glances_raid.py @@ -32,7 +32,7 @@ except ImportError: class Plugin(GlancesPlugin): - """Glances' RAID plugin. + """Glances RAID plugin. stats is a dict (see pymdstat documentation) """ @@ -139,8 +139,10 @@ class Plugin(GlancesPlugin): return ret def raid_alert(self, status, used, available): - """ - [available/used] means that ideally the array would have _available_ devices however, _used_ devices are in use. + """RAID alert messages. + + [available/used] means that ideally the array may have _available_ + devices however, _used_ devices are in use. Obviously when used >= available then things are good. """ if status == 'inactive': diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index dab9f6f5ac606888f4d3535988eb64fcc69b5373..45464b74c8be6818cdd6ddb22e1a946f247afcc5 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -39,9 +39,10 @@ else: SENSOR_TEMP_UNIT = '°C ' SENSOR_FAN_UNIT = 'RPM' + class Plugin(GlancesPlugin): - """Glances' sensors plugin. + """Glances sensors plugin. The stats list includes both sensors and hard disks stats, if any. The sensors are already grouped by chip type and then sorted by name. @@ -70,7 +71,7 @@ class Plugin(GlancesPlugin): self.reset() def get_key(self): - """Return the key of the list""" + """Return the key of the list.""" return 'label' def reset(self): @@ -149,7 +150,7 @@ class Plugin(GlancesPlugin): return stats def update_views(self): - """Update stats views""" + """Update stats views.""" # Call the father's method GlancesPlugin.update_views(self) diff --git a/glances/plugins/glances_system.py b/glances/plugins/glances_system.py index e60955dd648bbe28fbab9b4a3ae433470011c109..1df5547e9f5c038bf57a8b4d97ef6f1aaccd037c 100644 --- a/glances/plugins/glances_system.py +++ b/glances/plugins/glances_system.py @@ -69,7 +69,7 @@ class Plugin(GlancesPlugin): self.stats = {} def _linux_os_release(self): - """This function tries to determine the name of a Linux distribution. + """Try to determine the name of a Linux distribution. It checks for the /etc/os-release file. It takes the name from the 'NAME' field and the version from 'VERSION_ID'. diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py index 529c0fd015e867ad9e609317f71982b5e58cbea9..bb67e7cf0b38fb3f18035043a7c098f745ee4c31 100644 --- a/glances/plugins/glances_uptime.py +++ b/glances/plugins/glances_uptime.py @@ -34,7 +34,7 @@ snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'} class Plugin(GlancesPlugin): - """Glances' uptime plugin. + """Glances uptime plugin. stats is date (string) """