80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
|
import os
|
||
|
import json
|
||
|
from lib import vars
|
||
|
from logger.logger import *
|
||
|
|
||
|
|
||
|
isolist = []
|
||
|
|
||
|
|
||
|
def sync_iso():
|
||
|
global isolist
|
||
|
isolist = []
|
||
|
|
||
|
info("[sync_disk]start sync iso")
|
||
|
|
||
|
searchroot = ""
|
||
|
search_level = 3
|
||
|
if os.path.exists(vars.DISKMOUNT+f"{os.sep}ventoy{os.sep}ventoy.json"):
|
||
|
with open(vars.DISKMOUNT+f"{os.sep}ventoy{os.sep}ventoy.json", "r") as file:
|
||
|
ventoy_cfg = json.load(file)
|
||
|
|
||
|
if "control" in ventoy_cfg:
|
||
|
for i in ventoy_cfg["control"]:
|
||
|
if "VTOY_DEFAULT_SEARCH_ROOT" in i:
|
||
|
searchroot = i["VTOY_DEFAULT_SEARCH_ROOT"]
|
||
|
if "VTOY_MAX_SEARCH_LEVEL" in i:
|
||
|
if i["VTOY_MAX_SEARCH_LEVEL"] != "max":
|
||
|
search_level = int(i["VTOY_MAX_SEARCH_LEVEL"])
|
||
|
|
||
|
info(f"[sync_disk]sync in \"{searchroot}\" {str(search_level)} levels")
|
||
|
|
||
|
def dfs(deep, dir, search_levels):
|
||
|
global isolist
|
||
|
if deep > search_levels:
|
||
|
return
|
||
|
lists = os.listdir(vars.DISKMOUNT+dir)
|
||
|
for i in lists:
|
||
|
if os.path.isfile(vars.DISKMOUNT+dir+os.sep+i):
|
||
|
if ".iso" in i.lower():
|
||
|
isolist.append((dir+os.sep+i).replace(os.sep, "/"))
|
||
|
else:
|
||
|
dfs(deep+1, dir+os.sep+i, search_levels)
|
||
|
|
||
|
dfs(0, searchroot, search_level)
|
||
|
|
||
|
info(f"[sync_disk]sync finish, found {str(len(isolist))} iso files")
|
||
|
|
||
|
|
||
|
def get_isolist():
|
||
|
if (len(isolist) == 0):
|
||
|
sync_iso()
|
||
|
return isolist
|
||
|
|
||
|
|
||
|
def get_injected_iso():
|
||
|
global isolist
|
||
|
|
||
|
info("[sync_disk]get injected iso")
|
||
|
|
||
|
if os.path.exists(vars.DISKMOUNT+f"{os.sep}ventoy{os.sep}ventoy.json"):
|
||
|
with open(vars.DISKMOUNT+f"{os.sep}ventoy{os.sep}ventoy.json", "r") as file:
|
||
|
ventoy_cfg = json.load(file)
|
||
|
if "injection" in ventoy_cfg:
|
||
|
injected_list = []
|
||
|
for i in ventoy_cfg["injection"]:
|
||
|
if ("image" not in i or "archive" not in i):
|
||
|
warn(f"[sync_disk]error ventoy config \"{repr(i)}\"")
|
||
|
continue
|
||
|
if ("PEinjector" not in i["archive"]):
|
||
|
continue
|
||
|
if (i["image"] not in isolist):
|
||
|
continue
|
||
|
injected_list.append(i["image"])
|
||
|
info(f"[sync_disk]found injected iso \"{i['image']}\"")
|
||
|
return injected_list
|
||
|
else:
|
||
|
return []
|
||
|
else:
|
||
|
return []
|