博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一键git push脚本(python版)
阅读量:4542 次
发布时间:2019-06-08

本文共 1531 字,大约阅读时间需要 5 分钟。

#!/usr/bin/env pythonimport osimport subprocessimport sysimport timegitconfig = {    'cwd': './blog/public',    'git': {        'github': ['git@github.com:akkuman/akkuman.github.io.git', 'master'],        'coding': ['git@git.coding.net:Akkuman/Akkuman.git', 'coding-pages'],    }}def main():    global gitconfig    # change working directory    os.chdir(gitconfig.get('cwd', '.'))    # check if git init    if '.git' not in os.listdir():        subprocess.check_call(['git', 'init'])    # check if remote in config, if not, add the remote    git_remotes = subprocess.check_output(['git', 'remote', '-v'])    git_remotes_str = bytes.decode(git_remotes).strip()    git_remotes_list = [line.split()[0] for line in git_remotes_str.split('\n')]    for k,v in gitconfig['git'].items():        if k not in git_remotes_list:            subprocess.check_call(['git', 'remote', 'add', k, v[0]])    # add . & commit with message    subprocess.check_call(['git', 'add', '.'])    commit_message = 'Site updated: %s' % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())    if len(sys.argv) == 2:        commit_message = sys.argv[1]    subprocess.call(['git', 'commit', '-m', commit_message])        # push to every remote repo    for k,v in gitconfig['git'].items():        subprocess.check_call(['git', 'push', k, 'master:%s' % v[1]])if __name__ == '__main__':    if len(sys.argv) == 2:        if sys.argv[1] == '-h':            print('Usage:\n\t%s [commit_message]' % sys.argv[0])    main()

转载于:https://www.cnblogs.com/Akkuman/p/9519200.html

你可能感兴趣的文章
随笔13 java中的普通代码块,构造代码块,静态代码块
查看>>
目录的创建,删除,获取当前目录
查看>>
软件体系结构原理、方法与实践总结
查看>>
数字排序转变为字母排序
查看>>
2017-2018-1 《程序设计与数据结构》第3周学习总结
查看>>
C++ stringstream介绍,使用方法与例子
查看>>
android 系统目录及adb
查看>>
Hibernate入门
查看>>
sql语法:从一个表update到另外一个表
查看>>
HashMap学习总结
查看>>
十三,权限
查看>>
判断两个线段是否相交
查看>>
一些基础语法
查看>>
360多万条信息把一台服务器快拖卡了
查看>>
Git详解之六 Git工具
查看>>
等高布局display:table
查看>>
onunload与onbeforeunload事件解析 ...
查看>>
Openjudge-计算概论(A)-取石子游戏
查看>>
python-装饰器
查看>>
(4)获取servlet常用api
查看>>