A fork of hyde, the static site generation. Some patches will be pushed upstream.
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.
 
 
 

89 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Implements the hyde entry point commands
  4. """
  5. from commando import *
  6. from hyde.exceptions import HydeException
  7. from hyde.fs import File, Folder
  8. from hyde.layout import Layout, HYDE_DATA
  9. from hyde.model import Config
  10. from hyde.site import Site
  11. from hyde.version import __version__
  12. import logging
  13. import os
  14. import yaml
  15. HYDE_LAYOUTS = "HYDE_LAYOUTS"
  16. logger = logging.getLogger('hyde.engine')
  17. logger.setLevel(logging.DEBUG)
  18. import sys
  19. logger.addHandler(logging.StreamHandler(sys.stdout))
  20. class Engine(Application):
  21. """
  22. The Hyde Application
  23. """
  24. @command(description='hyde - a python static website generator',
  25. epilog='Use %(prog)s {command} -h to get help on individual commands')
  26. @version('-v', '--version', version='%(prog)s ' + __version__)
  27. @store('-s', '--sitepath', default='.', help="Location of the hyde site")
  28. def main(self, args):
  29. """
  30. Will not be executed. A sub command is required. This function exists
  31. to provide common parameters for the subcommands and some generic stuff
  32. like version and metadata
  33. """
  34. pass
  35. @subcommand('create', help='Create a new hyde site')
  36. @store('-l', '--layout', default='basic', help='Layout for the new site')
  37. @true('-f', '--force', default=False, dest='overwrite',
  38. help='Overwrite the current site if it exists')
  39. def create(self, args):
  40. """
  41. The create command. Creates a new site from the template at the given
  42. sitepath.
  43. """
  44. sitepath = Folder(args.sitepath)
  45. if sitepath.exists and not args.overwrite:
  46. raise HydeException(
  47. "The given site path[%s] is not empty" % sitepath)
  48. layout = Layout.find_layout(args.layout)
  49. logger.info(
  50. "Creating site at [%s] with layout [%s]" % (sitepath, layout))
  51. if not layout or not layout.exists:
  52. raise HydeException(
  53. "The given layout is invalid. Please check if you have the"
  54. " `layout` in the right place and the environment variable(%s)"
  55. " has been setup properly if you are using custom path for"
  56. " layouts" % HYDE_DATA)
  57. layout.copy_contents_to(args.sitepath)
  58. logger.info("Site creation complete")
  59. @subcommand('gen', help='Generate the site')
  60. @store('-c', '--config-path', default='site.yaml', dest='config',
  61. help='The configuration used to generate the site')
  62. @store('-d', '--deploy-path', default='deploy',
  63. help='Where should the site be generated?')
  64. def gen(self, args):
  65. """
  66. The generate command. Generates the site at the given
  67. deployment directory.
  68. """
  69. sitepath = Folder(args.sitepath)
  70. config_file = sitepath.child(args.config)
  71. logger.info("Reading site configuration from [%s]", config_file)
  72. conf = {}
  73. with open(config_file) as stream:
  74. conf = yaml.load(stream)
  75. site = Site(sitepath, Config(sitepath, conf))
  76. from hyde.generator import Generator
  77. gen = Generator(site)
  78. gen.generate_all()