diff options
Diffstat (limited to 'fabfile.py')
-rw-r--r-- | fabfile.py | 94 |
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 @@ | |||
1 | from fabric.api import * | ||
2 | import fabric.contrib.project as project | ||
3 | import os | ||
4 | import shutil | ||
5 | import sys | ||
6 | import SocketServer | ||
7 | |||
8 | from pelican.server import ComplexHTTPRequestHandler | ||
9 | |||
10 | # Local path configuration (can be absolute or relative to fabfile) | ||
11 | env.deploy_path = 'output' | ||
12 | DEPLOY_PATH = env.deploy_path | ||
13 | |||
14 | # Remote server configuration | ||
15 | production = 'root@localhost:22' | ||
16 | dest_path = '/var/www' | ||
17 | |||
18 | # Rackspace Cloud Files configuration settings | ||
19 | env.cloudfiles_username = 'my_rackspace_username' | ||
20 | env.cloudfiles_api_key = 'my_rackspace_api_key' | ||
21 | env.cloudfiles_container = 'my_cloudfiles_container' | ||
22 | |||
23 | # Github Pages configuration | ||
24 | env.github_pages_branch = "gh-pages" | ||
25 | |||
26 | # Port for `serve` | ||
27 | PORT = 8000 | ||
28 | |||
29 | def clean(): | ||
30 | """Remove generated files""" | ||
31 | if os.path.isdir(DEPLOY_PATH): | ||
32 | shutil.rmtree(DEPLOY_PATH) | ||
33 | os.makedirs(DEPLOY_PATH) | ||
34 | |||
35 | def build(): | ||
36 | """Build local version of site""" | ||
37 | local('pelican -s pelicanconf.py') | ||
38 | |||
39 | def rebuild(): | ||
40 | """`clean` then `build`""" | ||
41 | clean() | ||
42 | build() | ||
43 | |||
44 | def regenerate(): | ||
45 | """Automatically regenerate site upon file modification""" | ||
46 | local('pelican -r -s pelicanconf.py') | ||
47 | |||
48 | def 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 | |||
60 | def reserve(): | ||
61 | """`build`, then `serve`""" | ||
62 | build() | ||
63 | serve() | ||
64 | |||
65 | def preview(): | ||
66 | """Build production version of site""" | ||
67 | local('pelican -s publishconf.py') | ||
68 | |||
69 | def 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) | ||
79 | def 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 | |||
90 | def 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)) | ||