浏览代码

Merge branch 'review_dynamic_loading' into dev

monf 8 年之前
父节点
当前提交
b157fc9bb7

+ 1 - 1
core/MainController.py

@@ -11,7 +11,7 @@ from core.OrderListener import OrderListener
 from core.Players import Mplayer
 from core.RestAPI.FlaskAPI import FlaskAPI
 from core.TriggerLauncher import TriggerLauncher
-from neurons import Say
+from neurons.say.say import Say
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")

+ 1 - 1
core/ShellGui.py

@@ -11,7 +11,7 @@ from core import OrderListener
 from core.ConfigurationManager import SettingLoader
 from core.SynapseLauncher import SynapseLauncher
 from core.Utils import Utils
-from neurons import Say
+from neurons.say.say import Say
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")

+ 8 - 2
core/Utils.py

@@ -62,13 +62,19 @@ class Utils(object):
     def get_dynamic_class_instantiation(cls, package_name, module_name, parameters=None):
         """
         Load a python class dynamically
+
+        from my_package.my_module import my_class
+        mod = __import__('my_package.my_module', fromlist=['my_class'])
+        klass = getattr(mod, 'my_class')
+
         :param package_name: name of the package where we will find the module to load (neurons, tts, stt, trigger)
-        :param module_name: name of the module from the package_name to load
+        :param module_name: name of the module from the package_name to load. This one is capitalized. Eg: Snowboy
         :param parameters:  dict parameters to send as argument to the module
         :return:
         """
         logger.debug("Run plugin %s with parameter %s" % (module_name, parameters))
-        mod = __import__(package_name, fromlist=[module_name])
+        module_name_with_path = package_name + "." + module_name.lower() + "." + module_name.lower()
+        mod = __import__(module_name_with_path, fromlist=[module_name])
         try:
             klass = getattr(mod, module_name)
         except AttributeError:

+ 0 - 16
neurons/__init__.py

@@ -1,16 +0,0 @@
-from ansible_playbook import Ansible_playbook
-from shell import Shell
-from kill_switch import Kill_switch
-from say import Say
-from script import Script
-from sleep import Sleep
-from systemdate import Systemdate
-from gmail_checker import Gmail_checker
-from push_message import Push_message
-from openweathermap import Openweathermap
-from tasker_autoremote import Tasker_autoremote
-from wake_on_lan import Wake_on_lan
-from twitter import Twitter
-from neurotransmitter import Neurotransmitter
-from wikipedia import Wikipedia
-

+ 0 - 5
stt/__init__.py

@@ -1,5 +0,0 @@
-from google import Google
-from wit import Wit
-from bing import Bing
-from apiai import Apiai
-from houndify import Houndify

+ 1 - 1
stt/apiai/__init__.py

@@ -1 +1 @@
-from Apiai import Apiai
+from apiai import Apiai

+ 0 - 0
stt/apiai/Apiai.py → stt/apiai/apiai.py


+ 1 - 1
stt/bing/__init__.py

@@ -1 +1 @@
-from Bing import Bing
+from bing import Bing

+ 0 - 0
stt/bing/Bing.py → stt/bing/bing.py


+ 1 - 1
stt/google/__init__.py

@@ -1 +1 @@
-from Google import Google
+from google import Google

+ 0 - 0
stt/google/Google.py → stt/google/google.py


+ 1 - 1
stt/houndify/__init__.py

@@ -1 +1 @@
-from Houndify import Houndify
+from houndify import Houndify

+ 0 - 0
stt/houndify/Houndify.py → stt/houndify/houndify.py


+ 1 - 1
stt/wit/__init__.py

@@ -1 +1 @@
-from Wit import Wit
+from wit import Wit

+ 0 - 0
stt/wit/Wit.py → stt/wit/wit.py


+ 0 - 1
trigger/__init__.py

@@ -1 +0,0 @@
-from snowboy.snowboy import Snowboy

+ 0 - 5
tts/__init__.py

@@ -1,5 +0,0 @@
-from voxygen import Voxygen
-from pico2wave import Pico2wave
-from voicerss import Voicerss
-from googletts import Googletts
-from acapela import Acapela