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

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