zoukankan      html  css  js  c++  java
  • 一键git push脚本(python版)

    #!/usr/bin/env python
    
    import os
    import subprocess
    import sys
    import time
    
    gitconfig = {
        '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('
    ')]
        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:
    	%s [commit_message]' % sys.argv[0])
        main()
    
    
  • 相关阅读:
    javascript计算两个时间差
    angular 倒计时15 minute的方法封装
    一个页面多个倒计时的封装
    网站倒计时
    angularjs定时任务的设置与清除
    浏览器Event Loop 是个什么鬼
    一个图片测试的小网站:dummyimage.com
    在vscode 一行的末尾按下tab键 快速生成代码 很爽
    VSCODE 快捷键
    weex 在iOS 平台上的整合
  • 原文地址:https://www.cnblogs.com/Akkuman/p/9519200.html
Copyright © 2011-2022 走看看