我看别人用Python写操作系统,可是完全不会用啊!
因此,我连夜肝了一个系统,全英文(有强迫症的朋友可以翻译)。
代码不得抄袭!!!!!!但可以复制了玩!!!
编程环境:
Windows 10
PyCharm2024
Python 2.7.0
注意事项:一定是Python 2.7的环境!必须在终端中运行,否则有些命令就无法之行。有help命令,进入系统,输入:login ,密码:123asd,输入用户root,密码:123qwe。可以更改密码!
OK!废话不多说,代码,参上!
# -*- coding: utf-8 -*-
import datetime
import os
import time
import random
os.system("title pear A 1.5.2")
help = r"""
----------------------------------------------
name | detailed introduction
cat | View the contents of the file.
cd | Change directory.
clear | Clear screen.
help | Show help.
ip | Check your computer's IP address.
ls | List all files in current directory.
python | programming language.
quit | Quit the program.
run | Run the program.
time | Show current time.
user | Show your current user.
version | Show version.
"""
test_py = r"""
if __name__=="__main__":
print("Hello World!")
def main(a, b):
c = a+b
return c
main(1, 4)
"""
def user():
while True:
p = raw_input("%s@%s-VirtualBox:user$ " % (name, name))
if p == 'ls':
print "bin log-20240629"
elif p == 'clear':
os.system("cls")
elif p == "cd log-20240629":
def log():
while True:
p = raw_input("%s@%s-VirtualBox:user/log-20240629$ " % (name, name))
if p == "ls":
print "2024-6.log tet.log"
elif p == "clear":
os.system("cls")
elif p == "quit":
quit()
elif p == "python":
os.system("python")
elif p == "cd .." or p == "cd..":
return
elif p == "run 2024-6.log":
print "System is running!"
print "running..."
print "\n"
elif p == "run tet.log":
print "System is running!"
print "running..."
print "\n"
print "服務器運行中..."
time.sleep(random.randint(1,2))
os.system("cls")
print "2024年pear1.5.8開發出來.."
print "□■▽※吖■▽※ ▬▬▬▬▬▬"
print "▼▲▼◆■●○■♂⋚⋛¬☶嬲"
print "龘炛兲嫐恏"
print "如果出現錯誤,請終端程序,可以按下"
time
print "Error!!!!"
print "Ctrl+C"
print "Erorr!!!!!"
print "\n"
time.sleep(1)
print "Error...."
print "\n"
print "Error!!!!!!!!!!"
while True:
print "Error!!!!!!!"
elif p == "version":
print "pear A 1.5"
elif p == "ip":
print "ip is 127.133.45.6"
elif p == '' or p == ' ' or p == ' ':
pass
elif p == "time":
times = datetime.datetime.now()
print times
elif p == "help":
print help
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
else:
print "error!"
log()
elif p == 'quit':
quit()
elif p == 'python':
os.system("python")
elif p == '' or p == ' ' or p == ' ':
pass
elif p == 'ip':
print "ip is 127.133.45.6"
elif p == 'version':
print "pear A 1.5"
elif p == 'cd ..' or p == 'cd..':
return
elif p == "time":
times = datetime.datetime.now()
print times
elif p == "help":
print help
elif p == "cd bin":
def bin():
while True:
p = raw_input("%s@%s-VirtualBox:user/bin$ " % (name, name))
if p == "ls":
print ""
elif p == "clear":
os.system("cls")
elif p == "time":
times = datetime.datetime.now()
print times
elif p == "quit":
quit()
elif p == "python":
os.system("python")
elif p == "cd .." or p == "cd..":
return
elif p == "version":
print "pear A 1.5"
elif p == '' or p == ' ' or p == ' ':
pass
elif p == "ip":
print "ip is 127.133.45.6"
elif p == "help":
print help
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
else:
print "error!"
bin()
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
else:
print "error!"
def media():
while True:
p = raw_input("%s@%s-VirtualBox:media$ " % (name, name))
if p == 'ls':
print "IS test "
elif p == 'cd IS':
def IS():
while True:
p = raw_input("%s@%s-VirtualBox:media/IS$ " % (name, name))
if p == 'ls':
print ""
elif p == 'clear':
os.system("cls")
elif p == 'python':
os.system("python")
elif p == 'cd ..' or p == 'cd..':
return
elif p == 'quit':
quit()
elif p == "ip":
print "ip is 127.133.45.6"
elif p == "version":
print "pear A 1.5"
elif p == '' or p == ' ' or p == ' ':
pass
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
elif p == "help":
print help
elif p == "time":
times = datetime.datetime.now()
print times
else:
print "error!"
IS()
elif p == "cd test":
def test():
while True:
p = raw_input("%s@%s-VirtualBox:media/test$ " % (name, name))
if p == 'ls':
print "test.py"
elif p == 'cat test.py':
print test_py
elif p == 'clear':
os.system("cls")
elif p == 'python':
os.system("python")
elif p == 'cd ..' or p == 'cd..':
return
elif p == "ip":
print "ip is 127.133.45.6"
elif p == 'quit':
quit()
elif p == '' or p == ' ' or p == ' ':
pass
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
elif p == "time":
times = datetime.datetime.now()
print times
elif p == "help":
print help
elif p == "version":
print "pear A 1.5"
else:
print "error!"
test()
elif p == 'clear':
os.system("cls")
elif p == 'python':
os.system("python")
elif p == 'cd ..' or p == 'cd..':
return
elif p == "help":
print help
elif p == 'quit':
quit()
elif p == '' or p == ' ' or p == ' ':
pass
elif p == '' or p == ' ' or p == ' ':
pass
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
elif p == "version":
print "pear A 1.5"
elif p == "ip":
print "ip is 127.133.45.6"
elif p == "time":
times = datetime.datetime.now()
print times
else:
print "error!"
name = "root"
pswd = "123qwe"
pswd2 = "123asd"
if name == "":
print "name is not!"
quit()
else:
pass
os.system('cls')
a = """
Pear OS A 1.5.83 [OK]
Kernel 2.6.9-5.EL on ana i686
localhost login: vmxnet_close: Failed to finish all pend tx.
Is the related vmxnet device disabled?
This virtual machine may be in inconsistent state.
"""
print a
login1 = raw_input("")
if login1 == "bye":
print "bye!"
time.sleep(2)
exit()
elif login1 == "login" or login1 == "Login":
pswd3 = raw_input("Password:")
if pswd3 != pswd2:
print "Password is error!"
time.sleep(2)
exit()
else:
pass
else:
print "error"
time.sleep(2)
exit()
print "Login incorrect"
print ""
login = raw_input("login: ")
password = raw_input("Password: ")
if login != name and password != pswd:
print "name or password is not!"
quit()
else:
pass
times = datetime.datetime.now()
print "Last login: %s from 127.133.45.6" % times
print "\n"
while True:
p = raw_input("%s@%s-VirtualBox ~$ " % (name, name))
if p == 'ls':
print "user media VERSION system.kst 8106784.system"
elif p == 'python':
os.system('python')
elif p == 'quit':
quit()
elif p == 'clear':
os.system('cls')
elif p == "version":
print "pear A 1.5"
elif p == 'cd user':
user()
elif p == "ip":
print "ip is 127.133.45.6"
elif p == 'cd media':
media()
elif p == 'run system.kst':
print "System is running!"
print "\n"
pass
elif p == 'run 8106784.system':
print "System is running!"
print "running..."
time.sleep(random.randint(1,2))
print "ip is 127.133.45.6"
time.sleep(random.randint(1,2))
print "\n"
print "87345376"
print "74583453kieoh"
print "37uwhye82342jw89wu384u23ry7634i23yhrf8qwr"
print "23352345"
print "\n"
pass
elif p == '' or p == ' ' or p == ' ':
pass
elif p == 'cd VERSION':
def vs():
while True:
p = raw_input("%s@%s-VirtualBox:VERSION$ " % (name, name))
if p == "ls":
print ""
elif p == "clear":
os.system("cls")
elif p == "quit":
quit()
elif p == "python":
os.system("python")
elif p == "cd .." or p == "cd..":
return
elif p == "version":
print "pear A 1.5"
elif p == "ip":
print "ip is 127.133.45.6"
elif p == '' or p == ' ' or p == ' ':
pass
elif p == "time":
times = datetime.datetime.now()
print times
elif p == "help":
print help
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
else:
print "error!"
vs()
elif p == "help":
print help
elif p == "time":
times = datetime.datetime.now()
print times
elif p == "user":
tests = raw_input("Please enter the current user password~$ ")
if tests == pswd:
print "User password is correct!"
print "\n"
print "User name is %s" % name
else:
print "Password is incorrect!"
print "\n"
pass
else:
print "error!"