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

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