From c5b73e80c7b9f413d7595a989229309094ea93e1 Mon Sep 17 00:00:00 2001 From: Lakshmi Vyasarajan Date: Wed, 9 Nov 2011 19:49:41 +0530 Subject: [PATCH] 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 --- hyde/engine.py | 2 +- hyde/publisher.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hyde/engine.py b/hyde/engine.py index 00d334e..53f4aaa 100644 --- a/hyde/engine.py +++ b/hyde/engine.py @@ -150,7 +150,7 @@ class Engine(Application): @subcommand('publish', help='Publish the website') @store('-c', '--config-path', default='site.yaml', dest='config', 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.') @store('-m', '--message', dest='message', help='Optional message.') diff --git a/hyde/publisher.py b/hyde/publisher.py index 6d68fa8..7eea9b2 100644 --- a/hyde/publisher.py +++ b/hyde/publisher.py @@ -34,16 +34,25 @@ class Publisher(object): @staticmethod def load_publisher(site, publisher, message): + logger = getLoggerWithNullHandler('hyde.engine.publisher') try: settings = attrgetter("publisher.%s" % publisher)(site.config) 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'): logger.error( "Publisher type not specified: %s" % publisher) raise Exception("Please specify the publisher type in config.") + pub_class = load_python_object(settings.type) return pub_class(site, settings, message) \ No newline at end of file