#!/usr/bin/python3
#-*-coding:utf-8 -*-
import os
class Menu:
menulist = [{"name": "安装", "script": "setup.sh"},
{"name": "升级", "script": "upgrade.sh"},
{"name": "日志清理", "script": "del-alllog.sh"},
{"name": "节点还原", "script": "rollback.sh"},
{"name": "卸载", "script": "clean.sh"},
{"name": "重启", "script": "restartAllApp.sh"},
{"name": "创建分库规则", "script": "createDbRule.sh"}
]
shell_path = "./shell/"
def copyright(self):
print(
'''
********************************************************
**** *** 系统自动安装工具 ****
**** Copyright(c) 1995--2099 ****** ****
********************************************************
安装菜单:''')
def printtile(self, repeatnum, flag):
print(repeatnum * flag)
def menuhead(self):
self.printtile(80, "-")
def menutail(self):
self.menuhead()
def formatoption(self, num, content):
print("\t\t\t\t" + str(num) + ": " + content)
def showmenu(self):
for i, line in enumerate(self.menulist):
self.formatoption(i, line['name'])
def getlength(self):
return len(self.menulist)
def execmd(self, item):
if int(item) > self.getlength()-1:
print("选择的数字非法!")
self.choosemenu()
scriptsh = self.menulist[int(item)].get("script")
cmd = self.shell_path + scriptsh
print(cmd)
os.system(cmd)
def choosemenu(self):
while True:
title = '请输入菜单编号:' + '【0-' + str(self.getlength()-1) + '】,键入“Q”退出程序:'
item = input(title)
if not item:
break
elif item.isalpha() and (item.upper() == 'Q'):
print("退出!")
exit(1)
else:
self.execmd(item)
if __name__ == '__main__':
menu = Menu()
menu.menuhead()
menu.copyright()
menu.showmenu()
menu.menutail()
menu.choosemenu()
【python】一个py的启动菜单
最新推荐文章于 2022-06-30 20:34:17 发布