|  | @@ -2,7 +2,6 @@ import logging
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  from YAMLLoader import YAMLLoader
 | 
	
		
			
				|  |  |  from core.FileManager import FileManager
 | 
	
		
			
				|  |  | -from core.Models import Singleton
 | 
	
		
			
				|  |  |  from core.Models.RestAPI import RestAPI
 | 
	
		
			
				|  |  |  from core.Models.Settings import Settings
 | 
	
		
			
				|  |  |  from core.Models.Stt import Stt
 | 
	
	
		
			
				|  | @@ -16,24 +15,56 @@ logger = logging.getLogger("kalliope")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class SettingInvalidException(Exception):
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    Some data must match the expected value/type
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    .. seealso:: Settings
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  |      pass
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class NullSettingException(Exception):
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    Some Attributes can not be Null
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    .. seealso:: Settings
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  |      pass
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class SettingNotFound(Exception):
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    Some Attributes are missing
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    .. seealso:: Settings
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  |      pass
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class SettingLoader(object):
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +    This Class is used to get the Settings YAML and the Settings as an object
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def __init__(self):
 | 
	
		
			
				|  |  |          pass
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def get_yaml_config(cls, file_path=None):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        Class Methods which loads default or the provided YAML file and return it as a String
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param file_path: the setting file path to load if None takes default
 | 
	
		
			
				|  |  | +        :type file_path: str
 | 
	
		
			
				|  |  | +        :return: The loaded settings YAML
 | 
	
		
			
				|  |  | +        :rtype: dict
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +            settings_yaml = SettingLoader.get_yaml_config(/var/tmp/settings.yml)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          if file_path is None:
 | 
	
		
			
				|  |  |              file_path = FILE_NAME
 | 
	
		
			
				|  |  |          return YAMLLoader.get_config(file_path)
 | 
	
	
		
			
				|  | @@ -41,8 +72,19 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def get_settings(cls, file_path=None):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | -        Return a Settings object from settings.yml file
 | 
	
		
			
				|  |  | -        :return:
 | 
	
		
			
				|  |  | +        Class Methods which loads default or the provided YAML file and return a Settings Object
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param file_path: the setting file path to load
 | 
	
		
			
				|  |  | +        :type file_path: str
 | 
	
		
			
				|  |  | +        :return: The loaded Settings
 | 
	
		
			
				|  |  | +        :rtype: Settings
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            settings = SettingLoader.get_settings(file_path="/var/tmp/settings.yml")
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Settings
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          # create a new setting
 | 
	
	
		
			
				|  | @@ -64,16 +106,16 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |              cache_path = cls._get_cache_path(settings)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              # Load the setting singleton with the parameters
 | 
	
		
			
				|  |  | -            setting_object.default_tts_name=default_tts_name
 | 
	
		
			
				|  |  | -            setting_object.default_stt_name=default_stt_name
 | 
	
		
			
				|  |  | -            setting_object.default_trigger_name=default_trigger_name
 | 
	
		
			
				|  |  | -            setting_object.stts=stts
 | 
	
		
			
				|  |  | -            setting_object.ttss=ttss
 | 
	
		
			
				|  |  | -            setting_object.triggers=triggers
 | 
	
		
			
				|  |  | -            setting_object.random_wake_up_answers=random_wake_up_answers
 | 
	
		
			
				|  |  | -            setting_object.random_wake_up_sounds=random_wake_up_sounds
 | 
	
		
			
				|  |  | -            setting_object.rest_api=rest_api
 | 
	
		
			
				|  |  | -            setting_object.cache_path=cache_path
 | 
	
		
			
				|  |  | +            setting_object.default_tts_name = default_tts_name
 | 
	
		
			
				|  |  | +            setting_object.default_stt_name = default_stt_name
 | 
	
		
			
				|  |  | +            setting_object.default_trigger_name = default_trigger_name
 | 
	
		
			
				|  |  | +            setting_object.stts = stts
 | 
	
		
			
				|  |  | +            setting_object.ttss = ttss
 | 
	
		
			
				|  |  | +            setting_object.triggers = triggers
 | 
	
		
			
				|  |  | +            setting_object.random_wake_up_answers = random_wake_up_answers
 | 
	
		
			
				|  |  | +            setting_object.random_wake_up_sounds = random_wake_up_sounds
 | 
	
		
			
				|  |  | +            setting_object.rest_api = rest_api
 | 
	
		
			
				|  |  | +            setting_object.cache_path = cache_path
 | 
	
		
			
				|  |  |              # The Settings Singleton is loaded
 | 
	
		
			
				|  |  |              setting_object.is_loaded = True
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -81,6 +123,22 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @staticmethod
 | 
	
		
			
				|  |  |      def _get_default_speech_to_text(settings):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        Get the default speech to text defined in the settings.yml file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: the default speech to text
 | 
	
		
			
				|  |  | +        :rtype: str
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            default_stt_name = cls._get_default_speech_to_text(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Stt
 | 
	
		
			
				|  |  | +        .. raises:: NullSettingException, SettingNotFound
 | 
	
		
			
				|  |  | +        .. warnings:: Static and Private
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              default_speech_to_text = settings["default_speech_to_text"]
 | 
	
	
		
			
				|  | @@ -93,6 +151,23 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @staticmethod
 | 
	
		
			
				|  |  |      def _get_default_text_to_speech(settings):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        Get the default text to speech defined in the settings.yml file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: the default text to speech
 | 
	
		
			
				|  |  | +        :rtype: str
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            default_tts_name = cls._get_default_text_to_speech(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Tts
 | 
	
		
			
				|  |  | +        .. raises:: NullSettingException, SettingNotFound
 | 
	
		
			
				|  |  | +        .. warnings:: Static and Private
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              default_text_to_speech = settings["default_text_to_speech"]
 | 
	
		
			
				|  |  |              if default_text_to_speech is None:
 | 
	
	
		
			
				|  | @@ -104,6 +179,22 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @staticmethod
 | 
	
		
			
				|  |  |      def _get_default_trigger(settings):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        Get the default trigger defined in the settings.yml file
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: the default trigger
 | 
	
		
			
				|  |  | +        :rtype: str
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            default_trigger_name = cls._get_default_trigger(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Trigger
 | 
	
		
			
				|  |  | +        .. raises:: NullSettingException, SettingNotFound
 | 
	
		
			
				|  |  | +        .. warnings:: Static and Private
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              default_trigger = settings["default_trigger"]
 | 
	
		
			
				|  |  |              if default_trigger is None:
 | 
	
	
		
			
				|  | @@ -117,13 +208,25 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |      def _get_stts(cls, settings):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          Return a list of stt object
 | 
	
		
			
				|  |  | -        :param settings: loaded settings file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  |          :return: List of Stt
 | 
	
		
			
				|  |  | +        :rtype: list
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            stts = cls._get_stts(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Stt
 | 
	
		
			
				|  |  | +        .. raises:: SettingNotFound
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              speechs_to_text_list = settings["speech_to_text"]
 | 
	
		
			
				|  |  |          except KeyError:
 | 
	
		
			
				|  |  | -            raise NullSettingException("speech_to_text settings not found")
 | 
	
		
			
				|  |  | +            raise SettingNotFound("speech_to_text settings not found")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          stts = list()
 | 
	
		
			
				|  |  |          for speechs_to_text_el in speechs_to_text_list:
 | 
	
	
		
			
				|  | @@ -143,10 +246,23 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def _get_ttss(cls, settings):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | -        Return a list of Tts object
 | 
	
		
			
				|  |  | -        :param settings: loaded settings file
 | 
	
		
			
				|  |  | -        :return: List of Tts
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Return a list of stt object
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: List of Ttss
 | 
	
		
			
				|  |  | +        :rtype: list
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            ttss = cls._get_ttss(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Tts
 | 
	
		
			
				|  |  | +        .. raises:: SettingNotFound
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              text_to_speech_list = settings["text_to_speech"]
 | 
	
		
			
				|  |  |          except KeyError, e:
 | 
	
	
		
			
				|  | @@ -171,9 +287,21 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |      def _get_triggers(cls, settings):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |          Return a list of Trigger object
 | 
	
		
			
				|  |  | -        :param settings: loaded settings file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  |          :return: List of Trigger
 | 
	
		
			
				|  |  | +        :rtype: list
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            triggers = cls._get_triggers(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: Trigger
 | 
	
		
			
				|  |  | +        .. raises:: SettingNotFound
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              triggers_list = settings["triggers"]
 | 
	
		
			
				|  |  |          except KeyError, e:
 | 
	
	
		
			
				|  | @@ -197,10 +325,22 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def _get_random_wake_up_answers(cls, settings):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | -        return a list of string
 | 
	
		
			
				|  |  | -        :param settings:
 | 
	
		
			
				|  |  | -        :return:
 | 
	
		
			
				|  |  | +        Return a list of the wake up answers set up on the settings.yml file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: List of wake up answers
 | 
	
		
			
				|  |  | +        :rtype: list of str
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            wakeup = cls._get_random_wake_up_answers(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso::
 | 
	
		
			
				|  |  | +        .. raises:: NullSettingException
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              random_wake_up_answers_list = settings["random_wake_up_answers"]
 | 
	
		
			
				|  |  |          except KeyError:
 | 
	
	
		
			
				|  | @@ -216,10 +356,22 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def _get_random_wake_up_sounds(cls, settings):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | -        return a list of string
 | 
	
		
			
				|  |  | -        :param settings:
 | 
	
		
			
				|  |  | -        :return: List of string
 | 
	
		
			
				|  |  | +        Return a list of the wake up sounds set up on the settings.yml file
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: list of wake up sounds
 | 
	
		
			
				|  |  | +        :rtype: list of str
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            wakeup_sounds = cls._get_random_wake_up_sounds(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso::
 | 
	
		
			
				|  |  | +        .. raises:: NullSettingException
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              random_wake_up_sounds_list = settings["random_wake_up_sounds"]
 | 
	
		
			
				|  |  |          except KeyError:
 | 
	
	
		
			
				|  | @@ -234,6 +386,23 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def _get_rest_api(cls, settings):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        Return the settings of the RestApi
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: the RestApi object
 | 
	
		
			
				|  |  | +        :rtype: RestApi
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            rest_api = cls._get_rest_api(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso:: RestApi
 | 
	
		
			
				|  |  | +        .. raises:: SettingNotFound, NullSettingException, SettingInvalidException
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              rest_api = settings["rest_api"]
 | 
	
		
			
				|  |  |          except KeyError, e:
 | 
	
	
		
			
				|  | @@ -271,13 +440,31 @@ class SettingLoader(object):
 | 
	
		
			
				|  |  |                  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)
 | 
	
		
			
				|  |  | +            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")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @classmethod
 | 
	
		
			
				|  |  |      def _get_cache_path(cls, settings):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        Return the path where to store the cache
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :param settings: The YAML settings file
 | 
	
		
			
				|  |  | +        :type settings: dict
 | 
	
		
			
				|  |  | +        :return: the path to store the cache
 | 
	
		
			
				|  |  | +        :rtype: String
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        :Example:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            cache_path = cls._get_cache_path(settings)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        .. seealso::
 | 
	
		
			
				|  |  | +        .. raises:: SettingNotFound, NullSettingException, SettingInvalidException
 | 
	
		
			
				|  |  | +        .. warnings:: Class Method and Private
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          try:
 | 
	
		
			
				|  |  |              cache_path = settings["cache_path"]
 | 
	
		
			
				|  |  |          except KeyError, e:
 |