blob: b3a022206fd5069e03a0cffcf96f85446ad463ad [file] [log] [blame]
Luigi Santivettid93cb0f2020-02-17 22:21:28 +00001from 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 """`build` with the delete switch"""
41 local('pelican -d -s pelicanconf.py')
42
43def regenerate():
44 """Automatically regenerate site upon file modification"""
45 local('pelican -r -s pelicanconf.py')
46
47def serve():
48 """Serve site at http://localhost:8000/"""
49 os.chdir(env.deploy_path)
50
51 class AddressReuseTCPServer(SocketServer.TCPServer):
52 allow_reuse_address = True
53
54 server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)
55
56 sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
57 server.serve_forever()
58
59def reserve():
60 """`build`, then `serve`"""
61 build()
62 serve()
63
64def preview():
65 """Build production version of site"""
66 local('pelican -s publishconf.py')
67
68def cf_upload():
69 """Publish to Rackspace Cloud Files"""
70 rebuild()
71 with lcd(DEPLOY_PATH):
72 local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
73 '-U {cloudfiles_username} '
74 '-K {cloudfiles_api_key} '
75 'upload -c {cloudfiles_container} .'.format(**env))
76
77@hosts(production)
78def publish():
79 """Publish to production via rsync"""
80 local('pelican -s publishconf.py')
81 project.rsync_project(
82 remote_dir=dest_path,
83 exclude=".DS_Store",
84 local_dir=DEPLOY_PATH.rstrip('/') + '/',
85 delete=True,
86 extra_opts='-c',
87 )
88
89def gh_pages():
90 """Publish to GitHub Pages"""
91 rebuild()
92 local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))