This repository was archived by the owner on Dec 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqos.py
More file actions
124 lines (119 loc) · 5.1 KB
/
qos.py
File metadata and controls
124 lines (119 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Quarter Operation System (QOS) - Boot Program
"""
# QOS - Quarter Operation System
@ Author: ElofHew aka Dan_Evan
@ Version: Alpha 0.2.2
@ Date: 2025-08-02
@ License: GNU General Public License v3.0
@ Description: A Professional Fake-OS Powered by Python3.
"""
# Check qos.py in path (检测路径是否正确)
try:
import os, sys, colorama
now_path = os.getcwd()
if not os.path.isfile(os.path.join(now_path, 'qos.py')):
raise FileNotFoundError(f"{colorama.Fore.RED}No such file: 'qos.py' in this directory.{colorama.Fore.RESET}")
if not os.path.isdir(os.path.join(now_path, 'system')):
raise NotADirectoryError(f"{colorama.Fore.RED}No such directory:'system' in this directory.{colorama.Fore.RESET}")
if not os.path.isfile(os.path.join(now_path, 'system', 'main.py')):
print(f"{colorama.Fore.RED}No such file:'main.py' in'system' directory.{colorama.Fore.RESET}")
print(f"{colorama.Fore.CYAN}Maybe QOS on your system has been broken.{colorama.Fore.RESET}")
sys.exit(0)
except FileNotFoundError as e:
print(e)
sys.exit(0)
except NotADirectoryError as e:
print(e)
sys.exit(0)
except ImportError as e:
print(f"Error: {e}")
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
sys.exit(0)
# (20250625)稍微解释一下:
# 上面会检测你当前所在目录是否是QOS所在目录
# 如果不是则不允许你启动,直接sys.exit(0)退出
# 另外如果当前目录最后是"QOS"时,提示你再次cd QOS
# (20250713)新增:检测system文件夹下是否存在main.py文件,如果不存在则提示你可能是QOS损坏
# Check Python Version (检测Python版本)
try:
import sys, colorama
if sys.version_info.major < 3 or sys.version_info.minor < 10:
print(f"{colorama.Fore.RED}Error: QOS requires Python 3.10 or higher.{colorama.Fore.RESET}")
sys.exit(0)
except ImportError as e:
print(f"Error: {e}")
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
sys.exit(0)
# (20250629)解释一下:
# 这里检测你是否安装了Python 3.10或更高版本,如果不是则不允许你启动,直接sys.exit(0)退出
# Check Python Virtual Environment (检测Python虚拟环境)
try:
import sys, colorama
if hasattr(sys, "real_prefix") or (hasattr(sys, "base_prefix") and sys.prefix != sys.base_prefix):
pass
else:
print(f"{colorama.Fore.RED}Error: Please run QOS in a Python Virtual Environment.{colorama.Fore.RESET}")
print(f"{colorama.Fore.CYAN}If you don't know how to create or activate a Python Virtual Environment, please read the official documentation in 'docs' folder.{colorama.Fore.RESET}")
sys.exit(0)
except ImportError as e:
print(f"Error: {e}")
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
sys.exit(0)
# (20250627)解释一下:
# 这里检测你是否在Python虚拟环境中,如果不是则不允许你启动,直接sys.exit(0)退出
# 这里的检测方法是通过判断sys.real_prefix是否存在来实现的,如果存在则说明你在虚拟环境中,否则反之。
# Start Main Program (启动主程序)
if __name__ == "__main__":
work_path = os.getcwd()
try:
import os
import sys
import time
import subprocess
while True:
process = subprocess.run([sys.executable, os.path.join(work_path, "system", "main.py"), "--boot", "--regular"])
qos_return_code = process.returncode
match qos_return_code:
case 0:
# 0: 正常退出(关机)
break
case 11:
# 1: 重新运行(重启)
time.sleep(1)
continue
case 12:
# 2: 暂未开发但已预留的启动项
print("Error: This feature is not yet developed.")
break
case 16:
# 3: 启动参数不正确
print("Error: Invalid startup parameters.")
break
case 19:
# 4: 捕捉到错误
print("Error: Something went wrong.")
break
case _:
# 其他值: 未知错误
print(f"Error: Unknown return code {qos_return_code}.")
break
input("(Press any key to exit)")
except KeyboardInterrupt:
print("\nKeyboardInterrupt: Exiting QOS.")
sys.exit(1)
except (FileNotFoundError, NotADirectoryError, ImportError, Exception) as e:
print(f"Error: {e}")
sys.exit(0)
"""
# 20250802
孩子们,Leaf Boot Manager已完成基本开发,并将在近期完全用于QOS,作为QOS的引导程序。
相信孩子们以及看出来了,为什么规定了像“11”、“12”、“16”、“19”这样的错误码?
其实这就是Leaf Boot Manager的标准接收返回值,没错,其实我们已经为迁移到Leaf Boot Manager做好了准备。
Leaf Boot Manager的更多高级功能将持续开发,也会提供更多的配套工具,敬请期待。。。
"""