/
deploy.py
43 lines (32 loc) · 1.32 KB
/
deploy.py
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
import subprocess
import os
import sys
import time
commit_msg = "Publication on {date}"
path_pages = "../ghpages"
source_dir = "_output/"
#git_branch_pages = "gh-pages"
git_branch_pages = "gh-pages:gh-pages"
git_origin = "origin"
"""
git_status = subprocess.check_output("git status", shell=True)
git_status = git_status.splitlines()[1:] #first line is which branch
if not "nothing to commit" or not "directory clean" in git_status[0]:
print "Awaiting changes"
exit()
"""
if not os.path.exists(path_pages) or not os.path.exists(source_dir):
print (" directory doesn't exist")
exit()
# get commit message
user_input = raw_input(" commit message (default: " + commit_msg + "): \n ")
if user_input:
commit_msg = user_input
commit_msg = commit_msg.format(date=time.strftime("%Y-%m-%d", time.localtime()))
# sync source and destination
subprocess.check_call("rsync -rav --delete --exclude=.git --exclude='Thumbs.db' {source} {dest}".format(source=source_dir,dest=path_pages), shell=True)
# go to destination and do git stuff
os.chdir(path_pages)
subprocess.check_call("git add .", shell=True)
subprocess.check_call('git commit -am "{msg}"'.format(msg=commit_msg), shell=True)
subprocess.check_call("git push {origin} {branch}".format(origin=git_origin, branch=git_branch_pages), shell=True)