-
Notifications
You must be signed in to change notification settings - Fork 5
/
fabfile.py
64 lines (51 loc) · 1.7 KB
/
fabfile.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fabric.api import local, lcd
from os import walk
from os.path import isdir
skip = 5
def generate_file(page_no, template, pages):
pskip = skip * page_no
prev = page_no - 1 if page_no > 0 else -1
npage = page_no + 1 if page_no < pages - 1 else -1
with open('ro/news_%d.markdown' % page_no, 'w') as f:
f.write(template.format(ppp=skip, ps=pskip, prev_page=prev, next_page=npage))
def read_template():
with open('ro/_news_template', 'r') as f:
template = f.read()
return template
def get_num_pages():
count = 0
for root, dirs, files in walk('ro/_posts'):
count += len(files)
count += skip if count % skip else 0
return count / skip
def create_paginations():
template = read_template()
pages = get_num_pages()
for i in range(pages):
generate_file(i, template, pages)
def devel():
create_paginations()
local('jekyll serve 8000')
def build():
create_paginations()
local('jekyll build')
def deploy_old():
build()
local('rsync -rtv _site/ [email protected]:public_html')
local('rsync -rtv files/ [email protected]:public_html/files/')
def deploy():
git = lambda x: local('git --git-dir=../.git_deploy --work-tree=./ '+x)
if not isdir('.git_deploy'):
print 'Trying to clone the deploy repo on my own.'
local('rm -rf _site')
local("git clone -b gh-pages --separate-git-dir=.git_deploy `git remote -v|grep 'origin.*push'| tr ' ' '\t'|cut -f2` _site")
with lcd('_site'):
git('status')
git('pull')
build()
with lcd('_site'):
git('status')
git('add -f *')
git('status')
git('commit -a -m "`git log -n1 --oneline`" ')
git('push')