Skip to content

Commit e3d207d

Browse files
authored
Merge pull request #11 from ArnoldFeng767/pyi_add
Pyi add
2 parents bd647f0 + 03a2979 commit e3d207d

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

quecpython_stubs/backup_restore.pyi

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""
2+
Backup and Restore Module
3+
Provides secure backup and restore functionality with CRC32 checksum verification.
4+
5+
Descriptions taken from:
6+
Not yet.
7+
"""
8+
9+
class _checkError(Exception):
10+
"""Custom exception for backup check failures"""
11+
12+
def __init__(self, value: str):
13+
"""
14+
:param value: Error description
15+
"""
16+
def __str__(self) -> str:
17+
"""Returns string representation of the error
18+
19+
:return: Error description string
20+
"""
21+
22+
def bak_update(file: str, data: any) -> int:
23+
"""Updates or creates a backup file with checksum verification
24+
25+
:param file: File path to update (auto-prefixed with '/' if needed)
26+
:param data: Data to store (dict for new files, any type for existing)
27+
:return:
28+
0 - Success
29+
-1 - Invalid input or file exists
30+
-2 - Flag check failed
31+
-3 - Backup disabled
32+
-5 - Operation failed
33+
34+
Process:
35+
1. Mounts secure backup filesystem
36+
2. Creates primary file if missing
37+
3. Copies file to backup location
38+
4. Updates checksums for both files
39+
"""
40+
41+
def bak_file(file: str) -> any:
42+
"""Retrieves a file from backup storage
43+
44+
:param file: File path to retrieve (auto-prefixed with '/' if needed)
45+
:return:
46+
File content on success
47+
-1 - File not found
48+
-2 - Flag check failed
49+
-3 - Backup disabled
50+
-4 - Checksum mismatch
51+
-5 - Operation failed
52+
-6 - Copy failed
53+
54+
Process:
55+
1. Mounts secure backup filesystem
56+
2. Copies backup file to primary location
57+
3. Verifies checksums
58+
"""
59+
60+
def main() -> None:
61+
"""Main backup restore procedure
62+
63+
Automatically performs:
64+
1. Checks backup restore flag
65+
2. Compares CRC32 checksums
66+
3. Restores mismatched files from backup
67+
4. Updates checksum database
68+
69+
Note: Runs automatically on module import
70+
"""
71+
72+
def _get_backup_restore_flag() -> bool:
73+
"""Internal: Gets backup enable flag (not for direct use)
74+
75+
:return: True if backup enabled, False otherwise
76+
"""
77+
78+
def _check() -> str:
79+
"""Internal: Validates backup flag file (not for direct use)
80+
81+
:return: JSON content of flag file
82+
:raises _checkError: If file missing or empty
83+
"""

quecpython_stubs/bak_util.pyi

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Secure Storage Module
3+
Provides secure storage functionality for configuration data and files with backup support.
4+
5+
Descriptions taken from:
6+
Not yet.
7+
"""
8+
from backup_restore import bak_update, bak_file
9+
import uos, ujson, ql_fs
10+
11+
class SecureStorage:
12+
"""Secure storage class for configuration data and file backup"""
13+
14+
@classmethod
15+
def write(cls, data: dict) -> int:
16+
"""Writes configuration data to secure storage
17+
18+
:param data: Configuration data in dictionary format
19+
:return:
20+
0 - Success
21+
-1 - Invalid input (not a dictionary)
22+
-2 - Write operation failed
23+
-3 - Backup file already exists
24+
25+
Note: Automatically creates backup if none exists
26+
"""
27+
28+
@classmethod
29+
def read(cls) -> dict:
30+
"""Reads configuration data from secure storage
31+
32+
:return: Configuration data dictionary or None if not found
33+
34+
Note: Automatically restores from backup if primary file is missing
35+
"""
36+
37+
@classmethod
38+
def add(cls, file: str, data: any) -> int:
39+
"""Adds or updates a file in secure storage
40+
41+
:param file: File path to add/update
42+
:param data: Data to store in the file
43+
:return: 0 if successful, error code otherwise
44+
45+
Uses bak_update function for the operation
46+
"""
47+
48+
@classmethod
49+
def file(cls, file: str) -> any:
50+
"""Retrieves a file from secure storage
51+
52+
:param file: File path to retrieve
53+
:return: File content or None if not found
54+
55+
Uses bak_file function for the operation
56+
"""
57+
JsonFile = SecureStorage

0 commit comments

Comments
 (0)