-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (24 loc) · 875 Bytes
/
utils.py
File metadata and controls
30 lines (24 loc) · 875 Bytes
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
import hashlib
import os
def hash(text):
text_encoded = text.encode('utf-8')
hashed = hashlib.sha256(text_encoded)
return hashed.hexdigest()
def getFileName(path):
return os.path.basename(path)
def contains_file(lst, file_name):
file_dict = {d.get('name'): True for d in lst}
return file_name in file_dict
def format_used_memory(used_memory):
gb_threshold = 1 * 1024 * 1024 * 1024 # 1 GB in bytes
used_memory_mb = used_memory / (1024 * 1024)
if used_memory < gb_threshold:
formatted_used_memory = round(used_memory_mb, 2)
unit = "MB"
else:
formatted_used_memory = round(used_memory / gb_threshold, 2)
unit = "GB"
return str(formatted_used_memory)+" "+unit
def calculate_percentage(used_memory, total_memory):
percentage = (used_memory / total_memory) * 100
return round(percentage, 2)