Code Duplication    Length = 23-23 lines in 2 locations

glances/plugins/vms/__init__.py 1 location

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

glances/plugins/containers/__init__.py 1 location

@@ 525-547 (lines=23) @@
522
        return 'INFO'
523
524
525
def sort_docker_stats(stats: List[Dict[str, Any]]) -> Tuple[str, List[Dict[str, Any]]]:
526
    # Make VM sort related to process sort
527
    if glances_processes.sort_key == 'memory_percent':
528
        sort_by = 'memory_usage'
529
        sort_by_secondary = 'cpu_percent'
530
    elif glances_processes.sort_key == 'name':
531
        sort_by = 'name'
532
        sort_by_secondary = 'cpu_percent'
533
    else:
534
        sort_by = 'cpu_percent'
535
        sort_by_secondary = 'memory_usage'
536
537
    # Sort docker stats
538
    sort_stats_processes(
539
        stats,
540
        sorted_by=sort_by,
541
        sorted_by_secondary=sort_by_secondary,
542
        # Reverse for all but name
543
        reverse=glances_processes.sort_key != 'name',
544
    )
545
546
    # Return the main sort key and the sorted stats
547
    return sort_by, stats
548