2023-01-19 22:33:11 +01:00
|
|
|
import os,re
|
2023-01-17 15:01:32 +01:00
|
|
|
|
2024-01-29 19:59:33 +01:00
|
|
|
table = str.maketrans({
|
|
|
|
"<": "<",
|
|
|
|
">": ">",
|
|
|
|
"&": "&",
|
|
|
|
"'": "'",
|
|
|
|
'"': """,
|
|
|
|
})
|
|
|
|
def xmlesc(txt):
|
|
|
|
return txt.translate(table)
|
|
|
|
|
2023-01-17 15:01:32 +01:00
|
|
|
def get_size(file_path, unit='bytes'):
|
|
|
|
file_size = os.path.getsize(file_path)
|
|
|
|
exponents_map = {'bytes': 0, 'kb': 1, 'mb': 2, 'gb': 3}
|
|
|
|
if unit not in exponents_map:
|
|
|
|
raise ValueError("Must select from \
|
|
|
|
['bytes', 'kb', 'mb', 'gb']")
|
|
|
|
else:
|
|
|
|
size = file_size / 1024 ** exponents_map[unit]
|
|
|
|
return round(size, 1)
|
2023-01-19 22:33:11 +01:00
|
|
|
|
|
|
|
def get_cvdb(string):
|
|
|
|
return re.findall('(?<=\[CVDB)(.*)(?=].)', string[0].text)[0]
|