fabfile.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from fabric.api import *
  2. import fabric.contrib.project as project
  3. import os
  4. import sys
  5. import SimpleHTTPServer
  6. import SocketServer
  7. # Local path configuration (can be absolute or relative to fabfile)
  8. env.deploy_path = 'output'
  9. DEPLOY_PATH = env.deploy_path
  10. # Remote server configuration
  11. production = 'root@localhost:22'
  12. dest_path = '/var/www'
  13. # Rackspace Cloud Files configuration settings
  14. env.cloudfiles_username = 'my_rackspace_username'
  15. env.cloudfiles_api_key = 'my_rackspace_api_key'
  16. env.cloudfiles_container = 'my_cloudfiles_container'
  17. def clean():
  18. if os.path.isdir(DEPLOY_PATH):
  19. local('rm -rf {deploy_path}'.format(**env))
  20. local('mkdir {deploy_path}'.format(**env))
  21. def build():
  22. local('pelican -s pelicanconf.py')
  23. def rebuild():
  24. clean()
  25. build()
  26. def regenerate():
  27. local('pelican -r -s pelicanconf.py')
  28. def serve():
  29. os.chdir(env.deploy_path)
  30. PORT = 8000
  31. class AddressReuseTCPServer(SocketServer.TCPServer):
  32. allow_reuse_address = True
  33. server = AddressReuseTCPServer(('', PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
  34. sys.stderr.write('Serving on port {0} ...\n'.format(PORT))
  35. server.serve_forever()
  36. def reserve():
  37. build()
  38. serve()
  39. def preview():
  40. local('pelican -s publishconf.py')
  41. def cf_upload():
  42. rebuild()
  43. local('cd {deploy_path} && '
  44. 'swift -v -A https://auth.api.rackspacecloud.com/v1.0 '
  45. '-U {cloudfiles_username} '
  46. '-K {cloudfiles_api_key} '
  47. 'upload -c {cloudfiles_container} .'.format(**env))
  48. @hosts(production)
  49. def publish():
  50. local('pelican -s publishconf.py')
  51. project.rsync_project(
  52. remote_dir=dest_path,
  53. exclude=".DS_Store",
  54. local_dir=DEPLOY_PATH.rstrip('/') + '/',
  55. delete=True,
  56. extra_opts='-c',
  57. )