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

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