nuovo sito fatto con pelican
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tasks.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import shutil
  4. import sys
  5. import datetime
  6. from invoke import task
  7. from invoke.util import cd
  8. from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
  9. CONFIG = {
  10. # Local path configuration (can be absolute or relative to tasks.py)
  11. 'deploy_path': 'output',
  12. # Remote server configuration
  13. 'production': 'root@abbiamoundominio.org:22',
  14. 'dest_path': '/var/www/unit.abbiamoundominio.org/',
  15. # Port for `serve`
  16. 'port': 8000,
  17. }
  18. @task
  19. def clean(c):
  20. """Remove generated files"""
  21. if os.path.isdir(CONFIG['deploy_path']):
  22. shutil.rmtree(CONFIG['deploy_path'])
  23. os.makedirs(CONFIG['deploy_path'])
  24. @task
  25. def build(c):
  26. """Build local version of site"""
  27. c.run('pelican -s pelicanconf.py')
  28. @task
  29. def rebuild(c):
  30. """`build` with the delete switch"""
  31. c.run('pelican -d -s pelicanconf.py')
  32. @task
  33. def regenerate(c):
  34. """Automatically regenerate site upon file modification"""
  35. c.run('pelican -r -s pelicanconf.py')
  36. @task
  37. def serve(c):
  38. """Serve site at http://localhost:8000/"""
  39. class AddressReuseTCPServer(RootedHTTPServer):
  40. allow_reuse_address = True
  41. server = AddressReuseTCPServer(
  42. CONFIG['deploy_path'],
  43. ('', CONFIG['port']),
  44. ComplexHTTPRequestHandler)
  45. sys.stderr.write('Serving on port {port} ...\n'.format(**CONFIG))
  46. server.serve_forever()
  47. @task
  48. def reserve(c):
  49. """`build`, then `serve`"""
  50. build(c)
  51. serve(c)
  52. @task
  53. def preview(c):
  54. """Build production version of site"""
  55. c.run('pelican -s publishconf.py')
  56. @task
  57. def publish(c):
  58. """Publish to production via rsync"""
  59. c.run('pelican -s publishconf.py')
  60. c.run(
  61. 'rsync --delete --exclude ".DS_Store" -pthrvz -c '
  62. '{} {production}:{dest_path}'.format(
  63. CONFIG['deploy_path'].rstrip('/') + '/',
  64. **CONFIG))