snapshot before regression test
This commit is contained in:
39
Test/SysLibTest/App/os_backend.py
Normal file
39
Test/SysLibTest/App/os_backend.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import t, c
|
||||
from stdint import *
|
||||
import platmacro
|
||||
import os._win32
|
||||
import os._posix
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Workaround: TransPyC 无法正确解析 os.xxx() 包级函数调用
|
||||
# (os.path.xxx() 子模块调用正常,但 os.xxx() 包级调用解析为本地模块)
|
||||
# 此文件单独导入 os._win32 / os._posix 子模块,避免污染调用方的 os.rmdir() 等解析。
|
||||
# =============================================================================
|
||||
|
||||
def os_exists(path: str) -> bool:
|
||||
"""检查文件/目录是否存在(跨平台)"""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return os._win32.exists(path)
|
||||
return os._posix.exists(path)
|
||||
|
||||
|
||||
def os_remove(path: str) -> int:
|
||||
"""删除文件(跨平台)。成功返回 0,失败返回 -1。"""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return os._win32.remove(path)
|
||||
return os._posix.remove(path)
|
||||
|
||||
|
||||
def os_isdir(path: str) -> bool:
|
||||
"""检查路径是否为目录(跨平台)"""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return os._win32.isdir(path)
|
||||
return os._posix.isdir(path)
|
||||
|
||||
|
||||
def os_getsize(path: str) -> t.CInt64T:
|
||||
"""返回文件大小(字节,跨平台)。失败返回 -1。"""
|
||||
if platmacro.IS_WINDOWS:
|
||||
return os._win32.getsize(path)
|
||||
return os._posix.getsize(path)
|
||||
Reference in New Issue
Block a user