forked from github/pelican
Fabfile improvements
- Remove gratuitous Unixisms so that fabfile will work on Windows - Docstrings for tasks so `fab --list` is more useful. - Add `gh_pages` task for publishing to GitHub Pages using [ghp-import](https://github.com/davisp/ghp-import)
This commit is contained in:
parent
4add2d344b
commit
8cc2f99ec4
1 changed files with 28 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from fabric.api import *
|
from fabric.api import *
|
||||||
import fabric.contrib.project as project
|
import fabric.contrib.project as project
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import SimpleHTTPServer
|
import SimpleHTTPServer
|
||||||
import SocketServer
|
import SocketServer
|
||||||
|
|
@ -18,26 +19,35 @@ env.cloudfiles_username = '$cloudfiles_username'
|
||||||
env.cloudfiles_api_key = '$cloudfiles_api_key'
|
env.cloudfiles_api_key = '$cloudfiles_api_key'
|
||||||
env.cloudfiles_container = '$cloudfiles_container'
|
env.cloudfiles_container = '$cloudfiles_container'
|
||||||
|
|
||||||
|
# Github Pages configuration
|
||||||
|
env.github_pages_branch = "gh-pages"
|
||||||
|
|
||||||
|
# Port for `serve`
|
||||||
|
PORT = 8000
|
||||||
|
|
||||||
def clean():
|
def clean():
|
||||||
|
"""Remove generated files"""
|
||||||
if os.path.isdir(DEPLOY_PATH):
|
if os.path.isdir(DEPLOY_PATH):
|
||||||
local('rm -rf {deploy_path}'.format(**env))
|
shutil.rmtree(DEPLOY_PATH)
|
||||||
local('mkdir {deploy_path}'.format(**env))
|
os.makedirs(DEPLOY_PATH)
|
||||||
|
|
||||||
def build():
|
def build():
|
||||||
|
"""Build local version of site"""
|
||||||
local('pelican -s pelicanconf.py')
|
local('pelican -s pelicanconf.py')
|
||||||
|
|
||||||
def rebuild():
|
def rebuild():
|
||||||
|
"""`clean` then `build`"""
|
||||||
clean()
|
clean()
|
||||||
build()
|
build()
|
||||||
|
|
||||||
def regenerate():
|
def regenerate():
|
||||||
|
"""Automatically regenerate site upon file modification"""
|
||||||
local('pelican -r -s pelicanconf.py')
|
local('pelican -r -s pelicanconf.py')
|
||||||
|
|
||||||
def serve():
|
def serve():
|
||||||
|
"""Serve site at http://localhost:8000/"""
|
||||||
os.chdir(env.deploy_path)
|
os.chdir(env.deploy_path)
|
||||||
|
|
||||||
PORT = 8000
|
|
||||||
class AddressReuseTCPServer(SocketServer.TCPServer):
|
class AddressReuseTCPServer(SocketServer.TCPServer):
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
|
|
||||||
|
|
@ -47,22 +57,26 @@ def serve():
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
|
|
||||||
def reserve():
|
def reserve():
|
||||||
|
"""`build`, then `serve`"""
|
||||||
build()
|
build()
|
||||||
serve()
|
serve()
|
||||||
|
|
||||||
def preview():
|
def preview():
|
||||||
|
"""Build production version of site"""
|
||||||
local('pelican -s publishconf.py')
|
local('pelican -s publishconf.py')
|
||||||
|
|
||||||
def cf_upload():
|
def cf_upload():
|
||||||
|
"""Publish to Rackspace Cloud Files"""
|
||||||
rebuild()
|
rebuild()
|
||||||
local('cd {deploy_path} && '
|
with lcd(DEPLOY_PATH):
|
||||||
'swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
|
local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
|
||||||
'-U {cloudfiles_username} '
|
'-U {cloudfiles_username} '
|
||||||
'-K {cloudfiles_api_key} '
|
'-K {cloudfiles_api_key} '
|
||||||
'upload -c {cloudfiles_container} .'.format(**env))
|
'upload -c {cloudfiles_container} .'.format(**env))
|
||||||
|
|
||||||
@hosts(production)
|
@hosts(production)
|
||||||
def publish():
|
def publish():
|
||||||
|
"""Publish to production via rsync"""
|
||||||
local('pelican -s publishconf.py')
|
local('pelican -s publishconf.py')
|
||||||
project.rsync_project(
|
project.rsync_project(
|
||||||
remote_dir=dest_path,
|
remote_dir=dest_path,
|
||||||
|
|
@ -71,3 +85,9 @@ def publish():
|
||||||
delete=True,
|
delete=True,
|
||||||
extra_opts='-c',
|
extra_opts='-c',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def gh_pages():
|
||||||
|
"""Publish to GitHub Pages"""
|
||||||
|
rebuild()
|
||||||
|
local("ghp-import -b {github_pages_branch} {deploy_path}".format(**env))
|
||||||
|
local("git push origin {github_pages_branch}".format(**env))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue