补充类型注解

This commit is contained in:
cxykevin 2024-02-10 21:02:45 +08:00
parent b6505aef27
commit 9c0f122beb
6 changed files with 19 additions and 19 deletions

View File

@ -37,7 +37,7 @@ import makelnk
import regwrite
def force_copy(pkg_path, pkg_name, data_list, froms, tos):
def force_copy(pkg_path: str, pkg_name: str, data_list: list, froms: str, tos: str) -> list[tuple]:
froms = froms.replace("\\", "/")
if len(froms) > 1 and froms[-1] == '/':
froms = froms[:-1]
@ -70,7 +70,7 @@ def force_copy(pkg_path, pkg_name, data_list, froms, tos):
return datas
def copy(pkg_path, pkg_name, data_list, froms, tos):
def copy(pkg_path: str, pkg_name: str, data_list: list, froms: str, tos: str) -> list:
froms = froms.replace("\\", "/")
if len(froms) > 1 and froms[-1] == '/':
froms = froms[:-1]
@ -83,7 +83,7 @@ def copy(pkg_path, pkg_name, data_list, froms, tos):
data_check = [i["from"] for i in data_list]
def search_dir(path):
def search_dir(path: str): # dfs search
if froms+path in data_check:
datas.append(
(4, pkg_path+"/"+froms+path, data_dir+"/"+data_list[data_check.index(froms+path)]["to"]))
@ -103,11 +103,11 @@ def copy(pkg_path, pkg_name, data_list, froms, tos):
return datas
def start(pkg_name, data_list, cmd):
def start(pkg_name: str, data_list: list, cmd: str) -> list:
return [(5, cmd)]
def save_action(actions_list):
def save_action(actions_list: list) -> None:
tmp_filename = "PEinjector.tmp"
log.info(f"save action list to {config.TEMP_DIR.replace(
'{TEMP}', os.environ['TEMP'].replace("\\", "/"))+'/'+tmp_filename}")
@ -116,7 +116,7 @@ def save_action(actions_list):
return tmp_filename
def do_action(actions_list):
def do_action(actions_list: list) -> str:
actionlogs = "----- Action Log Start -----\r\n"
for i in actions_list:
if i[0] == 0:

View File

@ -55,7 +55,7 @@ def version_check(configuration: dict, pkg_name: str) -> int:
return 7
def file_check(file_json, pkg_name):
def file_check(file_json: dict, pkg_name: str) -> int:
try:
for i in file_json.get("compatibility", {}).get("file", {}).get("must", []):
if not os.path.exists(i):
@ -77,7 +77,7 @@ def file_check(file_json, pkg_name):
actions = {"onboot": [], "onload": []}
def load_package(pkg_name):
def load_package(pkg_name: str) -> int:
pkg_path = f"{disk}/PEinjector/package/{pkg_name}"
loaded_package.append(pkg_name)
if "manifest.json" not in os.listdir(pkg_path):

View File

@ -15,46 +15,46 @@ levels = {
}
def newlog():
def newlog() -> None:
with open(config.LOGPATH.replace("{DISK}", utils.find_disk()), "w") as _:
pass
def init():
def init() -> None:
logging.basicConfig(filename=config.LOGPATH.replace("{DISK}", utils.find_disk()),
format='[%(asctime)s][%(levelname)s] %(message)s',
level=levels[config.LOGLEVEL])
def info(msg):
def info(msg: str) -> None:
if (20 >= levels[config.LOGLEVEL]):
sys.stdout.write(
("[\033[34mINFO\033[0m]" if config.OUTPUT_COLORFUL else "[INFO]") + msg + "\n")
logging.info(msg)
def warn(msg):
def warn(msg: str) -> None:
if (30 >= levels[config.LOGLEVEL]):
sys.stdout.write(
("[\033[33mWARNING\033[0m]" if config.OUTPUT_COLORFUL else "[WARNING]") + msg + "\n")
logging.warn(msg)
def err(msg):
def err(msg: str) -> None:
if (40 >= levels[config.LOGLEVEL]):
sys.stdout.write(
("[\033[31mERROR\033[0m]" if config.OUTPUT_COLORFUL else "[ERROR]") + msg + "\n")
logging.error(msg)
def break_err(msg):
def break_err(msg: str) -> None:
if (40 >= levels[config.LOGLEVEL]):
sys.stdout.write(
("[\033[31mERROR\033[0m]" if config.OUTPUT_COLORFUL else "[ERROR]") + msg + "\n")
logging.error(msg)
def print(*args, end="\n"):
def print(*args, end="\n") -> None:
msg = ' '.join(map(str, args))
if (10 >= levels[config.LOGLEVEL]):
sys.stdout.write(msg + end)

View File

@ -17,7 +17,7 @@ for i in os.listdir(f"{sysdrive}\\Users"):
username = i
def makelnk(name, exepath, iconpath):
def makelnk(name: str, exepath: str, iconpath: str) -> None:
log.info(f"make shortcut \"{name}\"")
pylnk3.for_file(exepath,
lnk_name=f"{sysdrive}\\Users\\{username}" +

View File

@ -7,7 +7,7 @@ import log
import os
def add_path(path):
def add_path(path: str) -> None:
log.info(f"add path \"{path}\"")
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, winreg.KEY_READ) as key:
@ -20,6 +20,6 @@ def add_path(path):
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)
def add_reg(regpath):
def add_reg(regpath: str) -> None:
log.info(f"add reg \"{regpath}\"")
assert os.system(f"reg import \"{regpath.replace("/", "\\")}\"") == 0

View File

@ -5,7 +5,7 @@
import os
def find_disk(): # This code from dashedgeless
def find_disk() -> str: # This code from dashedgeless
disk_list = "CDEFGHIJKABLMNOPQRSTUVWYZ"
for i in disk_list:
this_disk = i + ":"