-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_utils.py
44 lines (36 loc) · 1.53 KB
/
output_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from typing import List, Tuple
VERBOSE = False
QUIET = False
HIDE_DEEP_FILES = False
def set_output_mode(verbose: bool, quiet: bool, hide_deep_files: bool):
global VERBOSE, QUIET, HIDE_DEEP_FILES
VERBOSE = verbose
QUIET = quiet
HIDE_DEEP_FILES = hide_deep_files
def print_verbose(message):
if VERBOSE and not QUIET:
print(message)
def print_quiet(message):
if not QUIET:
print(message)
def format_size(size_in_bytes: int) -> str:
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
if size_in_bytes < 1024.0:
return f"{size_in_bytes:.2f} {unit}"
size_in_bytes /= 1024.0
return f"{size_in_bytes:.2f} PB"
def print_list(items: List[Tuple[str, int, str]], threshold: int, item_type: str):
print_quiet(f"\nLarge {item_type}s:")
for item, size, item_subtype in items:
if size > threshold * 1024 * 1024: # Convert MB to bytes
print_quiet(f"{item} ({item_subtype}): {format_size(size)}")
def print_folders(folders: List[Tuple[str, int]], threshold: int):
print_quiet("\nLarge folders:")
for folder, size in folders:
if size > threshold * 1024 * 1024: # Convert MB to bytes
print_quiet(f"{folder}: {format_size(size)}")
def print_packages(packages: List[Tuple[str, int]], threshold: int):
print_quiet("\nLarge packages:")
for package, size in packages:
if size > threshold * 1024: # Package sizes are in KB
print_quiet(f"{package}: {format_size(size * 1024)}") # Convert KB to bytes for consistent formatting