2023-07-17 19:05:33 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
CHARSET = 'UTF-8'
|
|
|
|
|
|
|
|
|
|
|
|
def create_image(file_path: str, size_bytes: int):
|
2023-07-17 21:07:42 +00:00
|
|
|
subprocess.run([
|
2023-07-17 19:05:33 +00:00
|
|
|
'qemu-img',
|
|
|
|
'create',
|
|
|
|
'-f', 'qcow2',
|
|
|
|
file_path,
|
|
|
|
size_bytes,
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
def empty(file_path: str):
|
|
|
|
write(file_path, str())
|
|
|
|
|
|
|
|
|
|
|
|
def make(directory_path: str):
|
|
|
|
os.makedirs(directory_path, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
def wipe(path: str):
|
|
|
|
try:
|
|
|
|
shutil.rmtree(path)
|
|
|
|
except NotADirectoryError:
|
|
|
|
os.remove(path)
|
2023-07-17 21:07:42 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2023-07-17 19:05:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def write(file_path: str, text: str, charset=CHARSET):
|
|
|
|
with open(file_path, 'bw') as file_object:
|
|
|
|
file_object.write(text.encode(charset))
|