38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
from stdint import *
|
|
import platmacro
|
|
import os._win32
|
|
import os._posix
|
|
|
|
|
|
# =============================================================================
|
|
# Workaround: TransPyC mis-resolves package-level os.xxx() calls as a local
|
|
# module. Import os._win32 / os._posix here so caller code stays intact.
|
|
# =============================================================================
|
|
|
|
def os_exists(path: str) -> bool:
|
|
"""Return whether the file/dir exists."""
|
|
if platmacro.IS_WINDOWS:
|
|
return os._win32.exists(path)
|
|
return os._posix.exists(path)
|
|
|
|
|
|
def os_remove(path: str) -> int:
|
|
"""Remove a file. Returns 0 on success, -1 on failure."""
|
|
if platmacro.IS_WINDOWS:
|
|
return os._win32.remove(path)
|
|
return os._posix.remove(path)
|
|
|
|
|
|
def os_isdir(path: str) -> bool:
|
|
"""Return whether the path is a directory."""
|
|
if platmacro.IS_WINDOWS:
|
|
return os._win32.isdir(path)
|
|
return os._posix.isdir(path)
|
|
|
|
|
|
def os_getsize(path: str) -> int64:
|
|
"""Return file size in bytes, or -1 on failure."""
|
|
if platmacro.IS_WINDOWS:
|
|
return os._win32.getsize(path)
|
|
return os._posix.getsize(path)
|