summaryrefslogtreecommitdiff
path: root/fabfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'fabfile.py')
-rw-r--r--fabfile.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/fabfile.py b/fabfile.py
new file mode 100644
index 0000000..95796b5
--- /dev/null
+++ b/fabfile.py
@@ -0,0 +1,94 @@
1from fabric.api import *
2import fabric.contrib.project as project
3import os
4import shutil
5import sys
6import SocketServer
7
8from pelican.server import ComplexHTTPRequestHandler
9
10# Local path configuration (can be absolute or relative to fabfile)
11env.deploy_path = 'output'
12DEPLOY_PATH = env.deploy_path
13
14# Remote server configuration
15production = 'root@localhost:22'
16dest_path = '/var/www'
17
18# Rackspace Cloud Files configuration settings
19env.cloudfiles_username = 'my_rackspace_username'
20env.cloudfiles_api_key = 'my_rackspace_api_key'
21env.cloudfiles_container = 'my_cloudfiles_container'
22
23# Github Pages configuration
24env.github_pages_branch = "gh-pages"
25
26# Port for `serve`
27PORT = 8000
28
29def clean():
30 """Remove generated files"""
31 if os.path.isdir(DEPLOY_PATH):
32 shutil.rmtree(DEPLOY_PATH)
33 os.makedirs(DEPLOY_PATH)
34
35def build():
36 """Build local version of site"""
37 local('pelican -s pelicanconf.py')
38
39def rebuild():
40 """`clean` then `build`"""
41 clean()
42 build()
43
44def regenerate():
45 """Automatically regenerate site upon file modification"""
46 local('pelican -r -s pelicanconf.py')
47
48def serve():
49 """Serve site at http://localhost:8000/"""
50 os.chdir(env.deploy_path)
51
52 class AddressReuseTCPServer(SocketServer.TCPServer):
53 allow_reuse_address = True
54
55 server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)
56
57 sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
58 server.serve_forever()
59
60def reserve():
61 """`build`, then `serve`"""
62 build()
63 serve()
64
65def preview():
66 """Build production version of site"""
67 local('pelican -s publishconf.py')
68
69def cf_upload():
70 """Publish to Rackspace Cloud Files"""
71 rebuild()
72 with lcd(DEPLOY_PATH):
73 local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
74 '-U {cloudfiles_username} '
75 '-K {cloudfiles_api_key} '
76 'upload -c {cloudfiles_container} .'.format(**env))
77
78@hosts(production)
79def publish():
80 """Publish to production via rsync"""
81 local('pelican -s publishconf.py')
82 project.rsync_project(
83 remote_dir=dest_path,
84 exclude=".DS_Store",
85 local_dir=DEPLOY_PATH.rstrip('/') + '/',
86 delete=True,
87 extra_opts='-c',
88 )
89
90def gh_pages():
91 """Publish to GitHub Pages"""
92 rebuild()
93 local("ghp-import -b {github_pages_branch} {deploy_path}".format(**env))
94 local("git push origin {github_pages_branch}".format(**env))