1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
import os import subprocess import sys import time
gitconfig = { 'cwd': './blog/public', 'git': { 'github': ['[email protected]:akkuman/akkuman.github.io.git', 'master'], 'coding': ['[email protected]:Akkuman/Akkuman.git', 'coding-pages'], } }
def (): global gitconfig
os.chdir(gitconfig.get('cwd', '.'))
if '.git' not in os.listdir(): subprocess.check_call(['git', 'init'])
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]])
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]) 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:nt%s [commit_message]' % sys.argv[0]) main()
|
近期评论