-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_total_size.py
More file actions
38 lines (28 loc) · 1.55 KB
/
Copy pathcalculate_total_size.py
File metadata and controls
38 lines (28 loc) · 1.55 KB
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
from list_validator import is_list_of_special_dicts, is_list_of_str
def size_of_suspicious_names(suspicious_files: list[dict[str, str]], suspicious_names: list[str]) -> float:
"""
Function that counts and displays the amount of files in each suspicious levels.
Args:
suspicious_files (list[dict[str, str]]): A list of dictionaries, each representing file's details
from last scan.
suspicious_names (list[str]): A list of suspicious file names.
Returns:
float: The total size of suspicious names in MB.
Raises:
TypeError: If 'suspicious_files' is not a list of dictionaries with the required keys,
or 'suspicious_names' is not list of strings.
"""
# Validate that both 'suspicious_files' is list of dictionaries with the required keys.
if not is_list_of_special_dicts(suspicious_files):
raise TypeError("'suspicious_files' must be a list of dictionaries with required keys.")
# Validate that suspicious names is list of str.
if not is_list_of_str(suspicious_names):
raise TypeError("'suspicious_names' must be lists of strings")
# Initialize the total size counter.
sizes_sum = 0
# Iterate through each file and sum size only for files that name is suspicious.
for file in suspicious_files:
if file["name"] in suspicious_names:
sizes_sum += file["size"]
# Convert to MB and round to two decimal places
return round(sizes_sum / 1024 / 1024, 2)