A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Generic loader of extensions (plugins & templates)
  4. """
  5. import sys
  6. from hyde.exceptions import HydeException
  7. from hyde.util import getLoggerWithNullHandler
  8. logger = getLoggerWithNullHandler('hyde.engine')
  9. plugins = {}
  10. templates = {}
  11. def load_python_object(name):
  12. """
  13. Loads a python module from string
  14. """
  15. (module_name, _, object_name) = name.rpartition(".")
  16. if module_name == '':
  17. (module_name, object_name) = (object_name, module_name)
  18. try:
  19. logger.debug('Loading module [%s]' % module_name)
  20. module = __import__(module_name)
  21. except ImportError:
  22. raise HydeException("The given module name [%s] is invalid." %
  23. module_name)
  24. if object_name == '':
  25. return module
  26. try:
  27. module = sys.modules[module_name]
  28. except KeyError:
  29. raise HydeException("Error occured when loading module [%s]" %
  30. module_name)
  31. try:
  32. logger.debug('Getting object [%s] from module [%s]' %
  33. (object_name, module_name))
  34. return getattr(module, object_name)
  35. except AttributeError:
  36. raise HydeException("Cannot load the specified plugin [%s]. "
  37. "The given module [%s] does not contain the "
  38. "desired object [%s]. Please fix the "
  39. "configuration or ensure that the module is "
  40. "installed properly" %
  41. (name, module_name, object_name))