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

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