fabfile.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = 'demure@demu.red:500'
  13. dest_path = '/var/www/pelican'
  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. """`clean` then `build`"""
  32. clean()
  33. build()
  34. def regenerate():
  35. """Automatically regenerate site upon file modification"""
  36. local('pelican -r -s pelicanconf.py')
  37. def serve():
  38. """Serve site at http://localhost:8000/"""
  39. os.chdir(env.deploy_path)
  40. class AddressReuseTCPServer(SocketServer.TCPServer):
  41. allow_reuse_address = True
  42. server = AddressReuseTCPServer(('', PORT), ComplexHTTPRequestHandler)
  43. sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
  44. server.serve_forever()
  45. def reserve():
  46. """`build`, then `serve`"""
  47. build()
  48. serve()
  49. def preview():
  50. """Build production version of site"""
  51. local('pelican -s publishconf.py')
  52. def cf_upload():
  53. """Publish to Rackspace Cloud Files"""
  54. rebuild()
  55. with lcd(DEPLOY_PATH):
  56. local('swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
  57. '-U {cloudfiles_username} '
  58. '-K {cloudfiles_api_key} '
  59. 'upload -c {cloudfiles_container} .'.format(**env))
  60. @hosts(production)
  61. def publish():
  62. """Publish to production via rsync"""
  63. local('pelican -s publishconf.py')
  64. project.rsync_project(
  65. remote_dir=dest_path,
  66. exclude=".DS_Store",
  67. local_dir=DEPLOY_PATH.rstrip('/') + '/',
  68. delete=True,
  69. extra_opts='-c',
  70. )
  71. def gh_pages():
  72. """Publish to GitHub Pages"""
  73. rebuild()
  74. local("ghp-import -b {github_pages_branch} {deploy_path}".format(**env))
  75. local("git push origin {github_pages_branch}".format(**env))