def load_all(site): """ Loads plugins based on the configuration. Assigns the plugins to 'site.plugins' """ site.plugins = [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 = next(iter(site.config.publisher.__dict__.keys())) 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 find_template(site): """ Reads the configuration to find the appropriate template. """ template_object = site.config.get('template', DEFAULT_TEMPLATE) template_cls = load_python_object(template_object) template = template_cls(site.sitepath) return template
def test_can_load_locals(): file_class = load_python_object('fswrap.File') assert file_class f = file_class(__file__) assert f assert f.name == os.path.basename(__file__)
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(cls, project_name, env='build', context=None, conf_path=None): if project_name in __PROJECTS__: return __PROJECTS__[project_name] settings = __ENV__.get(env, None) if not settings: file_name = env + '.yaml' if conf_path: file_name = Folder(conf_path).child(file_name) settings = yinja.load(file_name, context=context) __ENV__[env] = settings config = ConfigDict() config.update(settings.config) config.patch(settings.projects.get(project_name, dict())) project_type = config.get('type_name', 'gitbot.lib.build.Project') project_class = load_python_object(project_type) project = project_class(project_name, config, env, settings, context, conf_path) __PROJECTS__[project_name] = project return project
def test_can_load_from_python_path(): markdown = load_python_object('markdown.markdown') assert markdown assert "<h3>h3</h3>" == markdown("### h3")
def load_plugin(name): plugin_name = PLUGINS_OLD_AND_NEW.get(name, name) return load_python_object(plugin_name)(site)
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