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.
 
 
 

59 lines
1.9 KiB

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