Code Duplication    Length = 94-94 lines in 2 locations

glances/plugins/programlist/__init__.py 1 location

@@ 234-327 (lines=94) @@
231
            msg = self.layout_header['command'].format("Programs", shortkey)
232
            ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'name' else 'DEFAULT'))
233
234
    def _msg_curse_sum(self, ret, sep_char='_', mmm=None, args=None):
235
        """
236
        Build the sum message (only when filter is on) and add it to the ret dict.
237
238
        :param ret: list of string where the message is added
239
        :param sep_char: define the line separation char
240
        :param mmm: display min, max, mean or current (if mmm=None)
241
        :param args: Glances args
242
        """
243
        ret.append(self.curse_new_line())
244
        if mmm is None:
245
            ret.append(self.curse_add_line(sep_char * 69))
246
            ret.append(self.curse_new_line())
247
        # CPU percent sum
248
        msg = ' '
249
        msg += self.layout_stat['cpu'].format(self._sum_stats('cpu_percent', mmm=mmm))
250
        ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm)))
251
        # MEM percent sum
252
        msg = self.layout_stat['mem'].format(self._sum_stats('memory_percent', mmm=mmm))
253
        ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm)))
254
        # VIRT and RES memory sum
255
        if (
256
            'memory_info' in self.stats[0]
257
            and self.stats[0]['memory_info'] is not None
258
            and self.stats[0]['memory_info'] != ''
259
        ):
260
            # VMS
261
            msg = self.layout_stat['virt'].format(
262
                self.auto_unit(self._sum_stats('memory_info', sub_key='vms', mmm=mmm), low_precision=False)
263
            )
264
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True))
265
            # RSS
266
            msg = self.layout_stat['res'].format(
267
                self.auto_unit(self._sum_stats('memory_info', sub_key='rss', mmm=mmm), low_precision=False)
268
            )
269
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True))
270
        else:
271
            msg = self.layout_header['virt'].format('')
272
            ret.append(self.curse_add_line(msg))
273
            msg = self.layout_header['res'].format('')
274
            ret.append(self.curse_add_line(msg))
275
        # PID
276
        msg = self.layout_header['nprocs'].format('')
277
        ret.append(self.curse_add_line(msg))
278
        # USER
279
        msg = self.layout_header['user'].format('')
280
        ret.append(self.curse_add_line(msg))
281
        # TIME+
282
        msg = self.layout_header['time'].format('')
283
        ret.append(self.curse_add_line(msg, optional=True))
284
        # THREAD
285
        msg = self.layout_header['thread'].format('')
286
        ret.append(self.curse_add_line(msg))
287
        # NICE
288
        msg = self.layout_header['nice'].format('')
289
        ret.append(self.curse_add_line(msg))
290
        # STATUS
291
        msg = self.layout_header['status'].format('')
292
        ret.append(self.curse_add_line(msg))
293
        # IO read/write
294
        if 'io_counters' in self.stats[0] and mmm is None:
295
            # IO read
296
            io_rs = int(
297
                (self._sum_stats('io_counters', 0) - self._sum_stats('io_counters', sub_key=2, mmm=mmm))
298
                / self.stats[0]['time_since_update']
299
            )
300
            if io_rs == 0:
301
                msg = self.layout_stat['ior'].format('0')
302
            else:
303
                msg = self.layout_stat['ior'].format(self.auto_unit(io_rs, low_precision=True))
304
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True, additional=True))
305
            # IO write
306
            io_ws = int(
307
                (self._sum_stats('io_counters', 1) - self._sum_stats('io_counters', sub_key=3, mmm=mmm))
308
                / self.stats[0]['time_since_update']
309
            )
310
            if io_ws == 0:
311
                msg = self.layout_stat['iow'].format('0')
312
            else:
313
                msg = self.layout_stat['iow'].format(self.auto_unit(io_ws, low_precision=True))
314
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True, additional=True))
315
        else:
316
            msg = self.layout_header['ior'].format('')
317
            ret.append(self.curse_add_line(msg, optional=True, additional=True))
318
            msg = self.layout_header['iow'].format('')
319
            ret.append(self.curse_add_line(msg, optional=True, additional=True))
320
        if mmm is None:
321
            msg = '< {}'.format('current')
322
            ret.append(self.curse_add_line(msg, optional=True))
323
        else:
324
            msg = f'< {mmm}'
325
            ret.append(self.curse_add_line(msg, optional=True))
326
            msg = '(\'M\' to reset)'
327
            ret.append(self.curse_add_line(msg, optional=True))
328

glances/plugins/processlist/__init__.py 1 location

@@ 797-890 (lines=94) @@
794
            msg = self.layout_header['command'].format("Command", shortkey)
795
            ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'name' else 'DEFAULT'))
796
797
    def _msg_curse_sum(self, ret, sep_char='_', mmm=None, args=None):
798
        """
799
        Build the sum message (only when filter is on) and add it to the ret dict.
800
801
        :param ret: list of string where the message is added
802
        :param sep_char: define the line separation char
803
        :param mmm: display min, max, mean or current (if mmm=None)
804
        :param args: Glances args
805
        """
806
        ret.append(self.curse_new_line())
807
        if mmm is None:
808
            ret.append(self.curse_add_line(sep_char * 69))
809
            ret.append(self.curse_new_line())
810
        # CPU percent sum
811
        msg = ' '
812
        msg += self.layout_stat['cpu'].format(self._sum_stats('cpu_percent', mmm=mmm))
813
        ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm)))
814
        # MEM percent sum
815
        msg = self.layout_stat['mem'].format(self._sum_stats('memory_percent', mmm=mmm))
816
        ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm)))
817
        # VIRT and RES memory sum
818
        if (
819
            'memory_info' in self.stats[0]
820
            and self.stats[0]['memory_info'] is not None
821
            and self.stats[0]['memory_info'] != ''
822
        ):
823
            # VMS
824
            msg = self.layout_stat['virt'].format(
825
                self.auto_unit(self._sum_stats('memory_info', sub_key='vms', mmm=mmm), low_precision=False)
826
            )
827
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True))
828
            # RSS
829
            msg = self.layout_stat['res'].format(
830
                self.auto_unit(self._sum_stats('memory_info', sub_key='rss', mmm=mmm), low_precision=False)
831
            )
832
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True))
833
        else:
834
            msg = self.layout_header['virt'].format('')
835
            ret.append(self.curse_add_line(msg))
836
            msg = self.layout_header['res'].format('')
837
            ret.append(self.curse_add_line(msg))
838
        # PID
839
        msg = self.layout_header['pid'].format('', width=self._max_pid_size())
840
        ret.append(self.curse_add_line(msg))
841
        # USER
842
        msg = self.layout_header['user'].format('')
843
        ret.append(self.curse_add_line(msg))
844
        # TIME+
845
        msg = self.layout_header['time'].format('')
846
        ret.append(self.curse_add_line(msg, optional=True))
847
        # THREAD
848
        msg = self.layout_header['thread'].format('')
849
        ret.append(self.curse_add_line(msg))
850
        # NICE
851
        msg = self.layout_header['nice'].format('')
852
        ret.append(self.curse_add_line(msg))
853
        # STATUS
854
        msg = self.layout_header['status'].format('')
855
        ret.append(self.curse_add_line(msg))
856
        # IO read/write
857
        if 'io_counters' in self.stats[0] and mmm is None:
858
            # IO read
859
            io_rs = int(
860
                (self._sum_stats('io_counters', 0) - self._sum_stats('io_counters', sub_key=2, mmm=mmm))
861
                / self.stats[0]['time_since_update']
862
            )
863
            if io_rs == 0:
864
                msg = self.layout_stat['ior'].format('0')
865
            else:
866
                msg = self.layout_stat['ior'].format(self.auto_unit(io_rs, low_precision=True))
867
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True, additional=True))
868
            # IO write
869
            io_ws = int(
870
                (self._sum_stats('io_counters', 1) - self._sum_stats('io_counters', sub_key=3, mmm=mmm))
871
                / self.stats[0]['time_since_update']
872
            )
873
            if io_ws == 0:
874
                msg = self.layout_stat['iow'].format('0')
875
            else:
876
                msg = self.layout_stat['iow'].format(self.auto_unit(io_ws, low_precision=True))
877
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True, additional=True))
878
        else:
879
            msg = self.layout_header['ior'].format('')
880
            ret.append(self.curse_add_line(msg, optional=True, additional=True))
881
            msg = self.layout_header['iow'].format('')
882
            ret.append(self.curse_add_line(msg, optional=True, additional=True))
883
        if mmm is None:
884
            msg = '< {}'.format('current')
885
            ret.append(self.curse_add_line(msg, optional=True))
886
        else:
887
            msg = f'< {mmm}'
888
            ret.append(self.curse_add_line(msg, optional=True))
889
            msg = '(\'M\' to reset)'
890
            ret.append(self.curse_add_line(msg, optional=True))
891
892
    def _mmm_deco(self, mmm):
893
        """Return the decoration string for the current mmm status."""