|
@@ -1,6 +1,7 @@
|
|
|
from YAMLLoader import YAMLLoader
|
|
|
import logging
|
|
|
|
|
|
+from core.Models.RestAPI import RestAPI
|
|
|
from core.Models.Settings import Settings
|
|
|
from core.Models.Stt import Stt
|
|
|
from core.Models.Trigger import Trigger
|
|
@@ -12,6 +13,10 @@ logging.basicConfig()
|
|
|
logger = logging.getLogger("kalliope")
|
|
|
|
|
|
|
|
|
+class SettingInvalidException(Exception):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
class NullSettingException(Exception):
|
|
|
pass
|
|
|
|
|
@@ -46,6 +51,7 @@ class SettingLoader(object):
|
|
|
triggers = cls._get_triggers(settings)
|
|
|
random_wake_up_answers = cls._get_random_wake_up_answers(settings)
|
|
|
random_wake_up_sounds = cls._get_random_wake_up_sounds(settings)
|
|
|
+ rest_api = cls._get_rest_api(settings)
|
|
|
|
|
|
# create a setting object
|
|
|
setting_object = Settings(default_stt_name=default_stt_name,
|
|
@@ -55,7 +61,8 @@ class SettingLoader(object):
|
|
|
ttss=ttss,
|
|
|
triggers=triggers,
|
|
|
random_wake_up_answers=random_wake_up_answers,
|
|
|
- random_wake_up_sounds=random_wake_up_sounds)
|
|
|
+ random_wake_up_sounds=random_wake_up_sounds,
|
|
|
+ rest_api=rest_api)
|
|
|
return setting_object
|
|
|
|
|
|
@staticmethod
|
|
@@ -67,8 +74,8 @@ class SettingLoader(object):
|
|
|
raise NullSettingException("Attribute default_speech_to_text is null")
|
|
|
logger.debug("Default STT: %s" % default_speech_to_text)
|
|
|
return default_speech_to_text
|
|
|
- except KeyError:
|
|
|
- raise SettingNotFound("Attribute default_speech_to_text not found in settings")
|
|
|
+ except KeyError, e:
|
|
|
+ raise SettingNotFound("%s setting not found" % e)
|
|
|
|
|
|
@staticmethod
|
|
|
def _get_default_text_to_speech(settings):
|
|
@@ -78,8 +85,8 @@ class SettingLoader(object):
|
|
|
raise NullSettingException("Attribute default_text_to_speech is null")
|
|
|
logger.debug("Default TTS: %s" % default_text_to_speech)
|
|
|
return default_text_to_speech
|
|
|
- except KeyError:
|
|
|
- raise SettingNotFound("Attribute default_text_to_speech not found in settings")
|
|
|
+ except KeyError, e:
|
|
|
+ raise SettingNotFound("%s setting not found" % e)
|
|
|
|
|
|
@staticmethod
|
|
|
def _get_default_trigger(settings):
|
|
@@ -89,8 +96,8 @@ class SettingLoader(object):
|
|
|
raise NullSettingException("Attribute default_trigger is null")
|
|
|
logger.debug("Default Trigger name: %s" % default_trigger)
|
|
|
return default_trigger
|
|
|
- except KeyError:
|
|
|
- raise SettingNotFound("Attribute default_trigger not found in settings")
|
|
|
+ except KeyError, e:
|
|
|
+ raise SettingNotFound("%s setting not found" % e)
|
|
|
|
|
|
@classmethod
|
|
|
def _get_stts(cls, settings):
|
|
@@ -128,8 +135,8 @@ class SettingLoader(object):
|
|
|
"""
|
|
|
try:
|
|
|
text_to_speech_list = settings["text_to_speech"]
|
|
|
- except KeyError:
|
|
|
- raise SettingNotFound("text_to_speech settings not found")
|
|
|
+ except KeyError, e:
|
|
|
+ raise SettingNotFound("%s setting not found" % e)
|
|
|
|
|
|
ttss = list()
|
|
|
for text_to_speech_el in text_to_speech_list:
|
|
@@ -155,8 +162,8 @@ class SettingLoader(object):
|
|
|
"""
|
|
|
try:
|
|
|
triggers_list = settings["triggers"]
|
|
|
- except KeyError:
|
|
|
- raise SettingNotFound("text_to_speech settings not found")
|
|
|
+ except KeyError, e:
|
|
|
+ raise SettingNotFound("%s setting not found" % e)
|
|
|
|
|
|
triggers = list()
|
|
|
for trigger_el in triggers_list:
|
|
@@ -210,3 +217,47 @@ class SettingLoader(object):
|
|
|
raise NullSettingException("random_wake_up_sounds settings is empty")
|
|
|
|
|
|
return random_wake_up_sounds_list
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def _get_rest_api(cls, settings):
|
|
|
+ try:
|
|
|
+ rest_api = settings["rest_api"]
|
|
|
+ except KeyError, e:
|
|
|
+ raise SettingNotFound("%s setting not found" % e)
|
|
|
+
|
|
|
+ if rest_api is not None:
|
|
|
+ try:
|
|
|
+ password_protected = rest_api["password_protected"]
|
|
|
+ if password_protected is None:
|
|
|
+ raise NullSettingException("password_protected setting cannot be null")
|
|
|
+ login = rest_api["login"]
|
|
|
+ password = rest_api["password"]
|
|
|
+ if password_protected:
|
|
|
+ if login is None:
|
|
|
+ raise NullSettingException("login setting cannot be null if password_protected is True")
|
|
|
+ if login is None:
|
|
|
+ raise NullSettingException("password setting cannot be null if password_protected is True")
|
|
|
+ active = rest_api["active"]
|
|
|
+ if active is None:
|
|
|
+ raise NullSettingException("active setting cannot be null")
|
|
|
+ port = rest_api["port"]
|
|
|
+ if port is None:
|
|
|
+ raise NullSettingException("port setting cannot be null")
|
|
|
+ # check that the port in an integer
|
|
|
+ try:
|
|
|
+ port = int(port)
|
|
|
+ except ValueError:
|
|
|
+ raise SettingInvalidException("port must be an integer")
|
|
|
+ # check the port is a valid port number
|
|
|
+ if not 1024 <= port <= 65535:
|
|
|
+ raise SettingInvalidException("port must be in range 1024-65535")
|
|
|
+
|
|
|
+ except KeyError, e:
|
|
|
+ print e
|
|
|
+ raise SettingNotFound("%s settings not found" % e)
|
|
|
+
|
|
|
+ # config ok, we can return the rest api object
|
|
|
+ rest_api_obj = RestAPI(password_protected=password_protected, login=login, password=password, active=active, port=port)
|
|
|
+ return rest_api_obj
|
|
|
+ else:
|
|
|
+ raise NullSettingException("rest_api settings cannot be null")
|