Ai
1 Star 0 Fork 0

musnows/Learn_Python_code

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
auto_git_push.py 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
musnows 提交于 2022-09-02 21:53 +08:00 . Code updated: 22-09-02 21:53:33
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/musnows/learn_python_code.git
git@gitee.com:musnows/learn_python_code.git
musnows
learn_python_code
Learn_Python_code
master

搜索帮助