代码拉取完成,页面将自动刷新
import os
import time
#获取当前时间
def GetTime():
return time.strftime("%y-%m-%d %H:%M:%S", time.localtime())
#打印的颜色信息
class bcolors:
PURPLE = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
WARNING = '\033[93m'
ENDC = '\033[0m'
#修改默认的提交信息
commit_msg = f" \"Code updated: {GetTime()}\" "
print(bcolors.PURPLE+"[Commit] 请在下方键入提交信息,可回车跳过"+bcolors.ENDC)
commit_input = input(bcolors.PURPLE+"[Commit] 请输入commit信息:"+bcolors.ENDC)
if commit_input != "": #不为空就修改,为空直接跳过
commit_msg = " \"" + commit_input + " \""
#显示最终的提交信息
print(bcolors.PURPLE+"[Commit]", commit_msg,bcolors.ENDC)
#git提交命令
cmd_1 = "git status"
cmd_2 = "git add --all"
cmd_3 = "git commit -m " + commit_msg
cmd_4 = "git push"
print(bcolors.GREEN+"[Start] auto-git-push"+bcolors.ENDC)
print(bcolors.BLUE+'[CMD]', cmd_1,bcolors.ENDC)
#显示当前动态,读取返回值
status_res = os.popen(cmd_1)
res = status_res.read()
print(res)
#如果出现了无需commit,直接退出程序
if "nothing to commit" in res:
print(bcolors.WARNING+'[Exit] nothing to commit'+bcolors.ENDC)
print("窗口将在5s后关闭...")
time.sleep(5)
os._exit(0)
print(bcolors.BLUE+'[CMD]', cmd_2,bcolors.ENDC)
os.system(cmd_2) #添加所有文件更改到工作区
print(bcolors.BLUE+'[CMD]', cmd_3,bcolors.ENDC)
os.system(cmd_3) #自动commit
print(bcolors.BLUE+'[CMD]', cmd_4,bcolors.ENDC)
os.system(cmd_4) #push上传
#完成上传
print(bcolors.GREEN+"[Finish] auto-git-push"+bcolors.ENDC)
print("窗口将在5s后关闭...")
time.sleep(5) #休眠5秒可以看清楚结果
# 在windows平台下
# pip install pyinstaller
# 安装好pyinstaller包之后,执行下面的命令
#C:\Users\moth\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts\pyinstaller.exe -F 文件名
#你需要把前面的路径替换成你的Python安装路径,如果找不到,那就全盘检索pyinstaller
#最终会打包成一个exe
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。