Skip to content

Commit bbd7d6c

Browse files
committed
Python File System API (os)
1 parent 709c3bc commit bbd7d6c

23 files changed

Lines changed: 2256 additions & 25 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# MatrixOS Python Interface - File Mode Constants
2+
# File access mode definitions for MatrixOS File System
3+
4+
from PikaObj import *
5+
6+
# Access mode enum - matches MatrixOS::File::AccessMode
7+
class FileMode(TinyObj):
8+
READ = 0x01
9+
WRITE = 0x02
10+
OPEN_EXISTING = 0x00
11+
CREATE_NEW = 0x04
12+
CREATE_ALWAYS = 0x08
13+
OPEN_ALWAYS = 0x10
14+
OPEN_APPEND = 0x30
15+
16+
# Seek mode enum - matches MatrixOS::File::SeekMode
17+
class SeekMode(TinyObj):
18+
SET = 0 # From beginning of file
19+
CUR = 1 # From current position
20+
END = 2 # From end of file
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# MatrixOS Python Interface - File Mode Constants
2+
# File access mode definitions for MatrixOS File System
3+
4+
# Access mode enum - matches MatrixOS::File::AccessMode
5+
class FileMode:
6+
READ = 0x01
7+
WRITE = 0x02
8+
OPEN_EXISTING = 0x00
9+
CREATE_NEW = 0x04
10+
CREATE_ALWAYS = 0x08
11+
OPEN_ALWAYS = 0x10
12+
OPEN_APPEND = 0x30
13+
14+
# Seek mode enum - matches MatrixOS::File::SeekMode
15+
class SeekMode:
16+
SET = 0 # From beginning of file
17+
CUR = 1 # From current position
18+
END = 2 # From end of file
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# MatrixOS Python Interface - File System (Vanilla Python API)
2+
# Pythonic file system operations with automatic sandboxing
3+
4+
from PikaObj import *
5+
from MatrixOS_FileMode import FileMode, SeekMode
6+
7+
# Vanilla Python-style file operations
8+
def open(file: str, mode: str = "r", buffering: int = -1, encoding: str = None):
9+
pass
10+
11+
def listdir(path: str = "."):
12+
pass
13+
14+
def mkdir(path: str, mode: int = 0o777):
15+
pass
16+
17+
def makedirs(path: str, mode: int = 0o777, exist_ok: bool = False):
18+
pass
19+
20+
def remove(path: str):
21+
pass
22+
23+
def rmdir(path: str):
24+
pass
25+
26+
def rename(src: str, dst: str):
27+
pass
28+
29+
def getcwd() -> str:
30+
pass
31+
32+
def chdir(path: str):
33+
pass
34+
35+
# Path operations
36+
class path(TinyObj):
37+
@staticmethod
38+
def exists(path: str) -> bool:
39+
pass
40+
41+
@staticmethod
42+
def isfile(path: str) -> bool:
43+
pass
44+
45+
@staticmethod
46+
def isdir(path: str) -> bool:
47+
pass
48+
49+
@staticmethod
50+
def getsize(path: str) -> int:
51+
pass
52+
53+
@staticmethod
54+
def join(*paths: str) -> str:
55+
pass
56+
57+
@staticmethod
58+
def dirname(path: str) -> str:
59+
pass
60+
61+
@staticmethod
62+
def basename(path: str) -> str:
63+
pass
64+
65+
@staticmethod
66+
def splitext(path: str):
67+
pass
68+
69+
# File object class (similar to Python's built-in file object)
70+
class FileObject(TinyObj):
71+
def __init__(self, path: str, mode: str):
72+
pass
73+
74+
def __del__(self):
75+
pass
76+
77+
def __enter__(self):
78+
pass
79+
80+
def __exit__(self, exc_type, exc_val, exc_tb):
81+
pass
82+
83+
def read(self, size: int = -1):
84+
pass
85+
86+
def readline(self, size: int = -1):
87+
pass
88+
89+
def readlines(self, hint: int = -1):
90+
pass
91+
92+
def write(self, data):
93+
pass
94+
95+
def writelines(self, lines):
96+
pass
97+
98+
def seek(self, offset: int, whence: int = 0):
99+
pass
100+
101+
def tell(self):
102+
pass
103+
104+
def flush(self):
105+
pass
106+
107+
def close(self):
108+
pass
109+
110+
def closed(self):
111+
pass
112+
113+
def readable(self):
114+
pass
115+
116+
def writable(self):
117+
pass
118+
119+
def seekable(self):
120+
pass
121+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# MatrixOS Python Interface - File System (Vanilla Python API)
2+
# Pythonic file system operations with automatic sandboxing
3+
4+
from typing import List, Optional, Union
5+
from MatrixOS_FileMode import FileMode, SeekMode
6+
7+
# Vanilla Python-style file operations
8+
def open(file: str, mode: str = "r", buffering: int = -1, encoding: Optional[str] = None) -> "FileObject": ...
9+
def listdir(path: str = ".") -> List[str]: ...
10+
def mkdir(path: str, mode: int = 0o777) -> None: ...
11+
def makedirs(path: str, mode: int = 0o777, exist_ok: bool = False) -> None: ...
12+
def remove(path: str) -> None: ...
13+
def rmdir(path: str) -> None: ...
14+
def rename(src: str, dst: str) -> None: ...
15+
def getcwd() -> str: ...
16+
def chdir(path: str) -> None: ...
17+
18+
# Path operations
19+
class path:
20+
def exists(path: str) -> bool: ...
21+
def isfile(path: str) -> bool: ...
22+
def isdir(path: str) -> bool: ...
23+
def getsize(path: str) -> int: ...
24+
def join(*paths: str) -> str: ...
25+
def dirname(path: str) -> str: ...
26+
def basename(path: str) -> str: ...
27+
def splitext(path: str) -> tuple: ...
28+
29+
# File object class (similar to Python's built-in file object)
30+
class FileObject:
31+
def __init__(self, path: str, mode: str): ...
32+
def __del__(self): ...
33+
def __enter__(self) -> FileObject: ...
34+
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...
35+
36+
def read(self, size: int = -1) -> Union[str, bytes]: ...
37+
def readline(self, size: int = -1) -> Union[str, bytes]: ...
38+
def readlines(self, hint: int = -1) -> List[Union[str, bytes]]: ...
39+
def write(self, data: Union[str, bytes]) -> int: ...
40+
def writelines(self, lines: List[Union[str, bytes]]) -> None: ...
41+
def seek(self, offset: int, whence: int = 0) -> int: ...
42+
def tell() -> int: ...
43+
def flush() -> None: ...
44+
def close() -> None: ...
45+
def closed() -> bool: ...
46+
def readable() -> bool: ...
47+
def writable() -> bool: ...
48+
def seekable() -> bool: ...
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
O_RDONLY: int
2+
O_WRONLY: int
3+
O_RDWR: int
4+
O_APPEND: int
5+
O_CREAT: int
6+
7+
8+
def __init__(self):
9+
pass
10+
11+
12+
def mkdir(self, path: str, *mode):
13+
pass
14+
15+
16+
def rmdir(self, path: str):
17+
pass
18+
19+
20+
def chdir(self, path: str):
21+
pass
22+
23+
24+
def listdir(self, path: str) -> list:
25+
pass
26+
27+
28+
def getcwd(self) -> str:
29+
pass
30+
31+
32+
def open(self, filename: str, flags: int) -> FILE:
33+
pass
34+
35+
36+
def read(self, fd: FILE, len: int) -> str:
37+
pass
38+
39+
40+
def write(self, fd: FILE, buf: any) -> int:
41+
pass
42+
43+
44+
def lseek(self, fd: FILE, pos: int, how: int) -> int:
45+
pass
46+
47+
48+
def close(self, fd: FILE):
49+
pass
50+
51+
52+
def fstat(self, fd: FILE) -> fileStat:
53+
pass
54+
55+
56+
def remove(self, filename: str):
57+
pass
58+
59+
60+
def rename(self, old: str, new: str):
61+
pass
62+
63+
64+
class fileStat:
65+
def st_size(self) -> int:
66+
pass
67+
68+
69+
class path:
70+
def join(self, *paths) -> str:
71+
pass
72+
73+
def split(self, path: str) -> tuple:
74+
pass
75+
76+
def splitext(self, path: str) -> tuple:
77+
pass
78+
79+
def basename(self, path: str) -> str:
80+
pass
81+
82+
def dirname(self, path: str) -> str:
83+
pass
84+
85+
def exists(self, path: str) -> bool:
86+
pass
87+
88+
def isdir(self, path: str) -> bool:
89+
pass
90+
91+
def isfile(self, path: str) -> bool:
92+
pass
93+
94+
def isabs(self, path: str) -> bool:
95+
pass
96+
97+
def abspath(self, path: str) -> str:
98+
pass

0 commit comments

Comments
 (0)