在 main.py 中添加对 'update' 命令的支持,实现代码同步功能,并优化 'ls' 命令的处理逻辑

This commit is contained in:
2025-04-08 22:34:40 +08:00
Unverified
parent 8335b7487d
commit a474253912

23
main.py
View File

@@ -73,17 +73,24 @@ def pseudo_zsh():
except FileNotFoundError: except FileNotFoundError:
print(f"cd: no such file or directory: {args[1]}") # 目录不存在 print(f"cd: no such file or directory: {args[1]}") # 目录不存在
continue continue
if args[0] == 'ls':
if len(args) == 1:
args.append('-l') # 默认参数
subprocess.run(['ls'] + args[1:]) # 执行 ls 命令
if args[0] == 'l': if args[0] == 'l':
if len(args) == 1: subprocess.run(['ls','-l']) # 执行 ls 命令
args.append('-l')
subprocess.run(['ls'] + args[1:])
if args[0] == 'ssh1': if args[0] == 'ssh1':
subprocess.run(['ssh','root@10.147.17.161']) subprocess.run(['ssh','root@10.147.17.161'])
if args[0] == 'sudo':
if args[0] == 'update':
try:
subprocess.run(['git', 'pull'])
subprocess.run(['git', 'push'])
print("Code synchronized successfully.")
print("Restarting the program...")
os.execv(sys.executable, ['python3'] + sys.argv) # 重新运行程序
except Exception as e:
print(f"Error during update: {e}")
if args[0] == 'sudo':
flight1 = True flight1 = True
a = 0 a = 0
for attempt in range(3): # 循环 3 次 for attempt in range(3): # 循环 3 次