Code Duplication    Length = 23-23 lines in 2 locations

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

glances/plugins/vms/__init__.py 1 location

@@ 326-348 (lines=23) @@
323
        return 'INFO'
324
325
326
def sort_vm_stats(stats: list[dict[str, Any]]) -> tuple[str, list[dict[str, Any]]]:
327
    # Make VM sort related to process sort
328
    if glances_processes.sort_key == 'memory_percent':
329
        sort_by = 'memory_usage'
330
        sort_by_secondary = 'cpu_time'
331
    elif glances_processes.sort_key == 'name':
332
        sort_by = 'name'
333
        sort_by_secondary = 'load_1min'
334
    else:
335
        sort_by = 'cpu_time'
336
        sort_by_secondary = 'load_1min'
337
338
    # Sort vm stats
339
    sort_stats_processes(
340
        stats,
341
        sorted_by=sort_by,
342
        sorted_by_secondary=sort_by_secondary,
343
        # Reverse for all but name
344
        reverse=glances_processes.sort_key != 'name',
345
    )
346
347
    # Return the main sort key and the sorted stats
348
    return sort_by, stats
349