Code Duplication    Length = 23-23 lines in 2 locations

glances/plugins/vms/__init__.py 1 location

@@ 296-318 (lines=23) @@
293
        return 'INFO'
294
295
296
def sort_vm_stats(stats: list[dict[str, Any]]) -> tuple[str, list[dict[str, Any]]]:
297
    # Make VM sort related to process sort
298
    if glances_processes.sort_key == 'memory_percent':
299
        sort_by = 'memory_usage'
300
        sort_by_secondary = 'load_1min'
301
    elif glances_processes.sort_key == 'name':
302
        sort_by = 'name'
303
        sort_by_secondary = 'load_1min'
304
    else:
305
        sort_by = 'load_1min'
306
        sort_by_secondary = 'memory_usage'
307
308
    # Sort vm stats
309
    sort_stats_processes(
310
        stats,
311
        sorted_by=sort_by,
312
        sorted_by_secondary=sort_by_secondary,
313
        # Reverse for all but name
314
        reverse=glances_processes.sort_key != 'name',
315
    )
316
317
    # Return the main sort key and the sorted stats
318
    return sort_by, stats
319

glances/plugins/containers/__init__.py 1 location

@@ 553-575 (lines=23) @@
550
        return 'INFO'
551
552
553
def sort_docker_stats(stats: list[dict[str, Any]]) -> tuple[str, list[dict[str, Any]]]:
554
    # Make VM sort related to process sort
555
    if glances_processes.sort_key == 'memory_percent':
556
        sort_by = 'memory_usage'
557
        sort_by_secondary = 'cpu_percent'
558
    elif glances_processes.sort_key == 'name':
559
        sort_by = 'name'
560
        sort_by_secondary = 'cpu_percent'
561
    else:
562
        sort_by = 'cpu_percent'
563
        sort_by_secondary = 'memory_usage'
564
565
    # Sort docker stats
566
    sort_stats_processes(
567
        stats,
568
        sorted_by=sort_by,
569
        sorted_by_secondary=sort_by_secondary,
570
        # Reverse for all but name
571
        reverse=glances_processes.sort_key != 'name',
572
    )
573
574
    # Return the main sort key and the sorted stats
575
    return sort_by, stats
576