Browse Source

Issue #83: Added support for default publisher.

* You can add a publisher with `default` as the name
* If no publisher named `default` is found, one of the publishers will be used by default(non deterministic order)
* If neither of the above results in something useable, an error is raised
main
Lakshmi Vyasarajan 13 years ago
parent
commit
c5b73e80c7
2 changed files with 14 additions and 5 deletions
  1. +1
    -1
      hyde/engine.py
  2. +13
    -4
      hyde/publisher.py

+ 1
- 1
hyde/engine.py View File

@@ -150,7 +150,7 @@ class Engine(Application):
@subcommand('publish', help='Publish the website') @subcommand('publish', help='Publish the website')
@store('-c', '--config-path', default='site.yaml', dest='config', @store('-c', '--config-path', default='site.yaml', dest='config',
help='The configuration used to generate the site') help='The configuration used to generate the site')
@store('-p', '--publisher', dest='publisher', required=True,
@store('-p', '--publisher', dest='publisher', default='default',
help='Points to the publisher configuration.') help='Points to the publisher configuration.')
@store('-m', '--message', dest='message', @store('-m', '--message', dest='message',
help='Optional message.') help='Optional message.')


+ 13
- 4
hyde/publisher.py View File

@@ -34,16 +34,25 @@ class Publisher(object):


@staticmethod @staticmethod
def load_publisher(site, publisher, message): def load_publisher(site, publisher, message):
logger = getLoggerWithNullHandler('hyde.engine.publisher')
try: try:
settings = attrgetter("publisher.%s" % publisher)(site.config) settings = attrgetter("publisher.%s" % publisher)(site.config)
except AttributeError: except AttributeError:
logger = getLoggerWithNullHandler('hyde.engine.publisher')
logger.error(
"Cannot find the publisher configuration: %s" % publisher)
raise
# Find the first configured publisher
settings = False

if not settings:
try:
settings = site.config.publisher.__dict__.itervalues().next()
except (AttributeError, StopIteration):
logger.error(
"Cannot find the publisher configuration: %s" % publisher)
raise

if not hasattr(settings, 'type'): if not hasattr(settings, 'type'):
logger.error( logger.error(
"Publisher type not specified: %s" % publisher) "Publisher type not specified: %s" % publisher)
raise Exception("Please specify the publisher type in config.") raise Exception("Please specify the publisher type in config.")

pub_class = load_python_object(settings.type) pub_class = load_python_object(settings.type)
return pub_class(site, settings, message) return pub_class(site, settings, message)

Loading…
Cancel
Save