Add getViews<plugin>() method for then XML API, first step for the issue977

This commit is contained in:
nicolargo 2017-05-10 14:52:32 +02:00
parent 5f4b92b88c
commit 996414e829
2 changed files with 17 additions and 1 deletions

View File

@ -457,6 +457,10 @@ class GlancesPlugin(object):
else:
return 'DEFAULT'
def get_json_views(self, item=None, key=None, option=None):
"""Return 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."""

View File

@ -54,9 +54,21 @@ class GlancesStats(object):
The goal is to dynamically generate the following methods:
- getPlugname(): return Plugname stat in JSON format
- getViewsPlugname(): return views of the Plugname stat in JSON format
"""
# Check if the attribute starts with 'get'
if item.startswith('get'):
if item.startswith('getViews'):
# Get the plugin name
plugname = item[len('getViews'):].lower()
# Get the plugin instance
plugin = self._plugins[plugname]
if hasattr(plugin, 'get_json_views'):
# The method get_views exist, return it
return getattr(plugin, 'get_json_views')
else:
# The method get_views is not found for the plugin
raise AttributeError(item)
elif item.startswith('get'):
# Get the plugin name
plugname = item[len('get'):].lower()
# Get the plugin instance