提交 bceb7cfc 编写于 作者: N nicolargo

Correct duplicate code issues in the glances_bottle.py script

上级 37a95425
......@@ -333,15 +333,8 @@ class GlancesBottle(object):
abort(404, "Cannot get views for plugin %s (%s)" % (plugin, str(e)))
return ret
def _api_item(self, plugin, item):
"""Glances API RESTFul implementation.
Return the JSON represenation of the couple plugin/item
HTTP/200 if OK
HTTP/400 if plugin is not found
HTTP/404 if others error
"""
def _api_itemvalue(self, plugin, item, value=None):
""" Father method for _api_item and _api_value"""
response.content_type = 'application/json'
if plugin not in self.plugins_list:
......@@ -350,35 +343,39 @@ class GlancesBottle(object):
# Update the stat
self.stats.update()
plist = self.stats.get_plugin(plugin).get_stats_item(item)
if value is None:
ret = self.stats.get_plugin(plugin).get_stats_item(item)
if plist is None:
abort(404, "Cannot get item %s in plugin %s" % (item, plugin))
if ret is None:
abort(404, "Cannot get item %s in plugin %s" % (item, plugin))
else:
return plist
ret = self.stats.get_plugin(plugin).get_stats_value(item, value)
def _api_value(self, plugin, item, value):
if ret is None:
abort(404, "Cannot get item(%s)=value(%s) in plugin %s" % (item, value, plugin))
return ret
def _api_item(self, plugin, item):
"""Glances API RESTFul implementation.
Return the process stats (dict) for the given item=value
Return the JSON represenation of the couple plugin/item
HTTP/200 if OK
HTTP/400 if plugin is not found
HTTP/404 if others error
"""
response.content_type = 'application/json'
if plugin not in self.plugins_list:
abort(400, "Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list))
# Update the stat
self.stats.update()
"""
return self._api_itemvalue(plugin, item)
pdict = self.stats.get_plugin(plugin).get_stats_value(item, value)
def _api_value(self, plugin, item, value):
"""Glances API RESTFul implementation.
if pdict is None:
abort(404, "Cannot get item(%s)=value(%s) in plugin %s" % (item, value, plugin))
else:
return pdict
Return the process stats (dict) for the given item=value
HTTP/200 if OK
HTTP/400 if plugin is not found
HTTP/404 if others error
"""
return self._api_itemvalue(plugin, item, value)
def _api_args(self):
"""Glances API RESTFul implementation.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册