初次提交

This commit is contained in:
2022-04-15 12:26:43 +08:00
commit 09b2956573
30 changed files with 952 additions and 0 deletions

0
util/__init__.py Normal file
View File

6
util/file.py Normal file
View File

@ -0,0 +1,6 @@
import os
def check_file_exist(file):
if not os.path.isfile(file):
raise FileNotFoundError("文件不存在:%s" % file)

29
util/system.py Normal file
View File

@ -0,0 +1,29 @@
import os
import platform
import subprocess
from typing import Union
def check_exec(name: Union[os.PathLike[str], str]) -> bool:
if is_windows():
check_process = subprocess.Popen([
"where.exe", name
], stdout=subprocess.PIPE)
check_process.wait()
return len(check_process.stdout.readlines()) > 0
elif is_linux():
check_process = subprocess.Popen([
"which", name
])
check_process.wait()
return check_process.returncode == 0
else:
return False
def is_windows() -> bool:
return platform.system().lower() == "windows"
def is_linux() -> bool:
return platform.system().lower() == "linux"