Code Duplication    Length = 24-24 lines in 2 locations

glances/outputs/glances_restful_api.py 2 locations

@@ 685-708 (lines=24) @@
682
        else:
683
            return ORJSONResponse(ret)
684
685
    def _api_item_unit(self, plugin, item):
686
        """Glances API RESTful implementation.
687
688
        Return the JSON representation of the couple plugin/item unit
689
        HTTP/200 if OK
690
        HTTP/400 if plugin is not found
691
        HTTP/404 if others error
692
        """
693
        if plugin not in self.plugins_list:
694
            raise HTTPException(
695
                status_code=status.HTTP_400_BAD_REQUEST,
696
                detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
697
            )
698
699
        try:
700
            # Get the unit
701
            ret = self.stats.get_plugin(plugin).get_item_info(item, 'unit')
702
        except Exception as e:
703
            raise HTTPException(
704
                status_code=status.HTTP_404_NOT_FOUND,
705
                detail="Cannot get %s unit for plugin %s (%s)" % (item, plugin, str(e)),
706
            )
707
        else:
708
            return ORJSONResponse(ret)
709
710
    def _api_value(self, plugin, item, value):
711
        """Glances API RESTful implementation.
@@ 660-683 (lines=24) @@
657
        else:
658
            return ORJSONResponse(ret)
659
660
    def _api_item_description(self, plugin, item):
661
        """Glances API RESTful implementation.
662
663
        Return the JSON representation of the couple plugin/item description
664
        HTTP/200 if OK
665
        HTTP/400 if plugin is not found
666
        HTTP/404 if others error
667
        """
668
        if plugin not in self.plugins_list:
669
            raise HTTPException(
670
                status_code=status.HTTP_400_BAD_REQUEST,
671
                detail="Unknown plugin %s (available plugins: %s)" % (plugin, self.plugins_list),
672
            )
673
674
        try:
675
            # Get the description
676
            ret = self.stats.get_plugin(plugin).get_item_info(item, 'description')
677
        except Exception as e:
678
            raise HTTPException(
679
                status_code=status.HTTP_404_NOT_FOUND,
680
                detail="Cannot get %s description for plugin %s (%s)" % (item, plugin, str(e)),
681
            )
682
        else:
683
            return ORJSONResponse(ret)
684
685
    def _api_item_unit(self, plugin, item):
686
        """Glances API RESTful implementation.