示例#1
0
文件: plugin.py 项目: dbravender/hyde
 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]
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
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__)
示例#5
0
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__)
示例#6
0
 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
示例#7
0
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'
示例#8
0
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'
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
def test_exception_raised_for_invalid_object():
    load_python_object("markdown.junk")
    assert False
示例#12
0
def test_exception_raised_for_invalid_module():
    load_python_object("junk.junk.junk")
    assert False
示例#13
0
def test_can_load_from_python_path():

    markdown = load_python_object('markdown.markdown')
    assert markdown

    assert "<h3>h3</h3>" == markdown("### h3")
示例#14
0
def test_exception_raised_for_invalid_object():
    load_python_object("markdown.junk")
    assert False
示例#15
0
def test_exception_raised_for_invalid_module():
    load_python_object("junk.junk.junk")
    assert False
示例#16
0
def test_can_load_from_python_path():

    markdown = load_python_object('markdown.markdown')
    assert markdown

    assert "<h3>h3</h3>" == markdown("### h3")