Skip to content

Instantly share code, notes, and snippets.

@lyrixx
Created November 12, 2012 21:44
Show Gist options
  • Save lyrixx/4062134 to your computer and use it in GitHub Desktop.
Save lyrixx/4062134 to your computer and use it in GitHub Desktop.
fab-doc
from fabric.api import local, abort, lcd, settings
from fabric.colors import red, green
from fabric.decorators import task
import os
@task
def post_commit(sha1=None, push=False):
"""
Call this task after a commit.
Sample of post-commit hook:
fab -f .../fabfile.py post_commit:sha1=`git log -1 HEAD --pretty="%H"`
"""
with lcd(get_current_project_path()):
ret = local('git status --porcelain | \grep -v "??" | wc -l', capture=True)
if (int(ret) > 0):
local('notify-send "%s" "Directory (git) not clean"' % get_current_project_name())
abort(red('Project is not clean. Impossible to commit anything'))
update_doc()
commit(sha1)
local('notify-send "%s" "Doc Packaged"' % get_current_project_name())
if (push):
push()
local('notify-send "%s" "Doc Pushed"' % get_current_project_name())
green('Doc built and commited')
@task
def update_doc():
with lcd(get_current_project_path()):
with settings(warn_only=True):
local('php vendor/bin/sami.php update _sami/sami.php --no-ansi --quiet --force')
@task
def commit(sha1=None):
with lcd(get_current_project_path()):
local('git add api')
if (sha1):
message = 'Updated doc for \'%s\'' % sha1
else:
message = 'Updated doc'
local('git ci -m "%s"' % message)
@task
def push():
with lcd(get_current_project_path()):
local('git push origin gh-pages')
def get_current_project_name():
return os.path.basename(get_current_project_path())
def get_current_project_path():
return os.path.dirname(__file__)
#!/bin/sh
# php /home/lyrixx/dev/sismo-ci/sismo build lifestream `git log -1 HEAD --pretty="%H"` --force --quiet &
fab -f /home/lyrixx/dev/lifestream-doc/fabfile.py post_commit:sha1=`git log -1 HEAD --pretty="%H"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment