# while-true logrufu ,input提示 非 click提示 python模板
import subprocess
import time
from functools import wraps
from loguru import logger
import sys, os
def time_this_function(func):
#作为装饰器使用,返回函数执行需要花费的时间
@wraps(func)
def wrapper(*args,**kwargs):
pid = os.getpid()
start=time.time()
result=func(*args,**kwargs)
end=time.time()
print(pid)
# print("%s,%f" % (func.__name__, end-start))
logger.debug('[func %s running with (%s, %s) ] [time of duration is %fs] [pid is %s ]' % (func.__name__, args, kwargs, end-start, pid))
logger.info("this is info log")
# logger.error("this is error log")
return result
return wrapper
@time_this_function
def my_cmd(mycmd, cwd):
cwd = cwd
mycmd = mycmd
p = subprocess.Popen("{}".format(mycmd), shell=True, cwd=cwd)
p.communicate()
returncode = p.returncode
if returncode != 0:
print("returncode is" , returncode, "命令有误。")
@time_this_function
def start_check():
print(" check is ok")
@time_this_function
def install_os():
print(" install os is ok")
@time_this_function
def install_aliyun():
pass
@time_this_function
def install_docker():
pass
@time_this_function
def install_k8s():
pass
if __name__ == "__main__":
count = 1
if count > 0:
password = input('请输入您的密码:')
if password == "passwd":
while True:
number = input('0 检查环境 1 配置系统环境 2 安装阿里云 7 安装docker 8安装kubelet 9 安装k8s-master 10 退出程序,请输入:')
if number == "0":
print("start check")
start_check()
# my_cmd("lk", "/root")
elif number == "1":
print("start install os hostname ,stop firewalld ...")
install_os()
elif number == "2":
print(" aliyum.repo start")
install_aliyun()
elif number == "7":
print(" start install docker ")
elif number == "8":
print(" start install kubelet ")
elif number == "9":
print("start init k8s-master")
elif number == "10":
break
else:
print('输入错误,请重新输入:')
elif count > 0:
count -= 1
print('您输入的密码不正确,还有{}次输入机会'.format(count))
# loguru 文章 https://cuiqingcai.com/7776.html
# loguru代码官方文档 https://loguru.readthedocs.io/en/stable/api/logger.html
1750

被折叠的 条评论
为什么被折叠?



