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

@@ 766-859 (lines=94) @@
763
            msg = self.layout_header['command'].format("Command", shortkey)
764
            ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'name' else 'DEFAULT'))
765
766
    def _msg_curse_sum(self, ret, sep_char='_', mmm=None, args=None):
767
        """
768
        Build the sum message (only when filter is on) and add it to the ret dict.
769
770
        :param ret: list of string where the message is added
771
        :param sep_char: define the line separation char
772
        :param mmm: display min, max, mean or current (if mmm=None)
773
        :param args: Glances args
774
        """
775
        ret.append(self.curse_new_line())
776
        if mmm is None:
777
            ret.append(self.curse_add_line(sep_char * 69))
778
            ret.append(self.curse_new_line())
779
        # CPU percent sum
780
        msg = ' '
781
        msg += self.layout_stat['cpu'].format(self._sum_stats('cpu_percent', mmm=mmm))
782
        ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm)))
783
        # MEM percent sum
784
        msg = self.layout_stat['mem'].format(self._sum_stats('memory_percent', mmm=mmm))
785
        ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm)))
786
        # VIRT and RES memory sum
787
        if (
788
            'memory_info' in self.stats[0]
789
            and self.stats[0]['memory_info'] is not None
790
            and self.stats[0]['memory_info'] != ''
791
        ):
792
            # VMS
793
            msg = self.layout_stat['virt'].format(
794
                self.auto_unit(self._sum_stats('memory_info', sub_key='vms', mmm=mmm), low_precision=False)
795
            )
796
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True))
797
            # RSS
798
            msg = self.layout_stat['res'].format(
799
                self.auto_unit(self._sum_stats('memory_info', sub_key='rss', mmm=mmm), low_precision=False)
800
            )
801
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True))
802
        else:
803
            msg = self.layout_header['virt'].format('')
804
            ret.append(self.curse_add_line(msg))
805
            msg = self.layout_header['res'].format('')
806
            ret.append(self.curse_add_line(msg))
807
        # PID
808
        msg = self.layout_header['pid'].format('', width=self._max_pid_size())
809
        ret.append(self.curse_add_line(msg))
810
        # USER
811
        msg = self.layout_header['user'].format('')
812
        ret.append(self.curse_add_line(msg))
813
        # TIME+
814
        msg = self.layout_header['time'].format('')
815
        ret.append(self.curse_add_line(msg, optional=True))
816
        # THREAD
817
        msg = self.layout_header['thread'].format('')
818
        ret.append(self.curse_add_line(msg))
819
        # NICE
820
        msg = self.layout_header['nice'].format('')
821
        ret.append(self.curse_add_line(msg))
822
        # STATUS
823
        msg = self.layout_header['status'].format('')
824
        ret.append(self.curse_add_line(msg))
825
        # IO read/write
826
        if 'io_counters' in self.stats[0] and mmm is None:
827
            # IO read
828
            io_rs = int(
829
                (self._sum_stats('io_counters', 0) - self._sum_stats('io_counters', sub_key=2, mmm=mmm))
830
                / self.stats[0]['time_since_update']
831
            )
832
            if io_rs == 0:
833
                msg = self.layout_stat['ior'].format('0')
834
            else:
835
                msg = self.layout_stat['ior'].format(self.auto_unit(io_rs, low_precision=True))
836
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True, additional=True))
837
            # IO write
838
            io_ws = int(
839
                (self._sum_stats('io_counters', 1) - self._sum_stats('io_counters', sub_key=3, mmm=mmm))
840
                / self.stats[0]['time_since_update']
841
            )
842
            if io_ws == 0:
843
                msg = self.layout_stat['iow'].format('0')
844
            else:
845
                msg = self.layout_stat['iow'].format(self.auto_unit(io_ws, low_precision=True))
846
            ret.append(self.curse_add_line(msg, decoration=self._mmm_deco(mmm), optional=True, additional=True))
847
        else:
848
            msg = self.layout_header['ior'].format('')
849
            ret.append(self.curse_add_line(msg, optional=True, additional=True))
850
            msg = self.layout_header['iow'].format('')
851
            ret.append(self.curse_add_line(msg, optional=True, additional=True))
852
        if mmm is None:
853
            msg = '< {}'.format('current')
854
            ret.append(self.curse_add_line(msg, optional=True))
855
        else:
856
            msg = f'< {mmm}'
857
            ret.append(self.curse_add_line(msg, optional=True))
858
            msg = '(\'M\' to reset)'
859
            ret.append(self.curse_add_line(msg, optional=True))
860
861
    def _mmm_deco(self, mmm):
862
        """Return the decoration string for the current mmm status."""