def load_all(site): """ Loads plugins based on the configuration. Assigns the plugins to 'site.plugins' """ site.plugins = [loader.load_python_object(name)(site) for name in site.config.plugins]
def load_publisher(site, publisher, message): logger = getLoggerWithNullHandler('hyde.engine.publisher') try: settings = attrgetter("publisher.%s" % publisher)(site.config) except AttributeError: settings = False if not settings: # Find the first configured publisher try: publisher = site.config.publisher.__dict__.iterkeys().next() logger.warning("No default publisher configured. Using: %s" % publisher) settings = attrgetter("publisher.%s" % publisher)(site.config) 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)
def load_publisher(site, publisher, message): logger = getLoggerWithNullHandler('hyde.engine.publisher') try: settings = attrgetter("publisher.%s" % publisher)(site.config) except AttributeError: settings = False if not settings: # Find the first configured publisher try: publisher = site.config.publisher.__dict__.iterkeys().next() logger.warning("No default publisher configured. Using: %s" % publisher) settings = attrgetter("publisher.%s" % publisher)(site.config) 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)
def test_can_load_locals(): file_class = load_python_object('hyde.fs.File') assert file_class f = file_class(__file__) assert f assert f.name == os.path.basename(__file__)
def find_template(site): """ Reads the configuration to find the appropriate template. """ #Find the appropriate template environment if site.config.template: template = loader.load_python_object(site.config.template)(site.sitepath) else: template = Jinja2Template(site.sitepath) return template
def test_can_load_module_without_dot(): yaml = load_python_object('yaml') abc = yaml.load(""" d: efg l: mno """) assert abc['d'] == 'efg' assert abc['l'] == 'mno'
def load_publisher(site, publisher, message): 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 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)
def load_publisher(site, publisher, message): 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 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)
def test_exception_raised_for_invalid_object(): load_python_object("markdown.junk") assert False
def test_exception_raised_for_invalid_module(): load_python_object("junk.junk.junk") assert False
def test_can_load_from_python_path(): markdown = load_python_object('markdown.markdown') assert markdown assert "<h3>h3</h3>" == markdown("### h3")