NeuroneLauncher.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class NeuroneNotFoundError(Exception):
  2. pass
  3. def _run_plugin(plugin, parameters=None):
  4. """
  5. Dynamic loading of a module
  6. :param plugin: Module name to load
  7. :param parameters: Parameter of the module
  8. :return:
  9. """
  10. print "Run plugin %s with parameter %s" % (plugin, parameters)
  11. mod = __import__('neurons', fromlist=[plugin])
  12. try:
  13. klass = getattr(mod, plugin)
  14. except AttributeError:
  15. print "Error: No module named %s " % plugin
  16. raise NeuroneNotFoundError
  17. if klass is not None:
  18. # run the plugin
  19. if not parameters:
  20. klass()
  21. elif isinstance(parameters, dict):
  22. klass(**parameters)
  23. else:
  24. klass(parameters)
  25. class NeuroneLauncher:
  26. def __init__(self):
  27. pass
  28. @classmethod
  29. def start_neurone(cls, neuron):
  30. """
  31. Start a neuron plugin
  32. :param neuron: neuron object
  33. :type neuron: Neurone
  34. :return:
  35. """
  36. plugin = neuron.name.capitalize()
  37. plugin = plugin.capitalize()
  38. _run_plugin(plugin, neuron.parameters)
  39. # if isinstance(neuron, dict):
  40. # for plugin, parameters in neuron.items():
  41. # # capitalizes the first letter (because classes have first letter upper case)
  42. # plugin = plugin.capitalize()
  43. # _run_plugin(plugin, parameters)
  44. # else:
  45. # plugin = neuron
  46. # # capitalizes the first letter (because classes have first letter upper case)
  47. # plugin = plugin.capitalize()
  48. # _run_plugin(plugin)