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.
 
 
 

64 lines
2.0 KiB

  1. import abc
  2. from operator import attrgetter
  3. from commando.util import getLoggerWithNullHandler, load_python_object
  4. from hyde._compat import with_metaclass
  5. """
  6. Contains abstract classes and utilities that help publishing a website to a
  7. server.
  8. """
  9. class Publisher(with_metaclass(abc.ABCMeta)):
  10. """
  11. The abstract base class for publishers.
  12. """
  13. def __init__(self, site, settings, message):
  14. super(Publisher, self).__init__()
  15. self.logger = getLoggerWithNullHandler(
  16. 'hyde.engine.%s' % self.__class__.__name__)
  17. self.site = site
  18. self.message = message
  19. self.initialize(settings)
  20. @abc.abstractmethod
  21. def initialize(self, settings):
  22. pass
  23. @abc.abstractmethod
  24. def publish(self):
  25. if not self.site.config.deploy_root_path.exists:
  26. raise Exception("Please generate the site first")
  27. @staticmethod
  28. def load_publisher(site, publisher, message):
  29. logger = getLoggerWithNullHandler('hyde.engine.publisher')
  30. try:
  31. settings = attrgetter("publisher.%s" % publisher)(site.config)
  32. except AttributeError:
  33. settings = False
  34. if not settings:
  35. # Find the first configured publisher
  36. try:
  37. publisher = site.config.publisher.__dict__.iterkeys().next()
  38. logger.warning(
  39. "No default publisher configured. Using: %s" % publisher)
  40. settings = attrgetter("publisher.%s" % publisher)(site.config)
  41. except (AttributeError, StopIteration):
  42. logger.error(
  43. "Cannot find the publisher configuration: %s" % publisher)
  44. raise
  45. if not hasattr(settings, 'type'):
  46. logger.error(
  47. "Publisher type not specified: %s" % publisher)
  48. raise Exception("Please specify the publisher type in config.")
  49. pub_class = load_python_object(settings.type)
  50. return pub_class(site, settings, message)