The git repo behind my blog.

fabfile.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. from pelican.server import ComplexHTTPRequestHandler
  8. # Local path configuration (can be absolute or relative to fabfile)
  9. env.deploy_path = 'output'
  10. DEPLOY_PATH = env.deploy_path
  11. # Remote server configuration
  12. production = 'root@localhost:22'
  13. dest_path = '/var/www'
  14. # Rackspace Cloud Files configuration settings
  15. env.cloudfiles_username = 'my_rackspace_username'
  16. env.cloudfiles_api_key = 'my_rackspace_api_key'
  17. env.cloudfiles_container = 'my_cloudfiles_container'
  18. # Github Pages configuration
  19. env.github_pages_branch = "gh-pages"
  20. # Port for `serve`
  21. PORT = 8000
  22. def clean():
  23. """Remove generated files"""
  24. if os.path.isdir(DEPLOY_PATH):
  25. shutil.rmtree(DEPLOY_PATH)
  26. os.makedirs(DEPLOY_PATH)
  27. def build():
  28. """Build local version of site"""
  29. local('pelican -s pelicanconf.py')
  30. def rebuild():
  31. """`build` with the delete switch"""
  32. local('pelican -d -s pelicanconf.py')
  33. def regenerate():
  34. """Automatically regenerate site upon file modification"""
  35. local('pelican -r -s pelicanconf.py')
  36. def serve():
  37. """Serve site at http://localhost:8000/"""
  38. os.chdir(env.deploy_path)
  39. class AddressReuseTCPServer(SocketServer.TCPServer):
  40. allow_reuse_address = True
  41. server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)
  42. sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
  43. server.serve_forever()
  44. def reserve():
  45. """`build`, then `serve`"""
  46. build()
  47. serve()
  48. def preview():
  49. """Build production version of site"""
  50. local('pelican -s publishconf.py')
  51. def cf_upload():
  52. """Publish to Rackspace Cloud Files"""
  53. rebuild()
  54. with lcd(DEPLOY_PATH):
  55. local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
  56. '-U {cloudfiles_username} '
  57. '-K {cloudfiles_api_key} '
  58. 'upload -c {cloudfiles_container} .'.format(**env))
  59. @hosts(production)
  60. def publish():
  61. """Publish to production via rsync"""
  62. local('pelican -s publishconf.py')
  63. project.rsync_project(
  64. remote_dir=dest_path,
  65. exclude=".DS_Store",
  66. local_dir=DEPLOY_PATH.rstrip('/') + '/',
  67. delete=True,
  68. extra_opts='-c',
  69. )
  70. def gh_pages():
  71. """Publish to GitHub Pages"""
  72. rebuild()
  73. local("ghp-import -b {github_pages_branch} {deploy_path} -p".format(**env))