Просмотр исходного кода

[Review] rename start_options to options in settings

ThiBuff 7 лет назад
Родитель
Сommit
bbf560fef4

+ 1 - 1
Docs/rest_api.md

@@ -410,7 +410,7 @@ Output example:
 ```
 
 ### Switch deaf status
-Kalliope can switch to 'deaf' mode, so it can not ear you anymore, the trigger/hotword is desactivated.
+Kalliope can switch to 'deaf' mode, so she can not ear you anymore, the trigger/hotword is desactivated.
 However Kalliope continues to process synapses.
 
 Normal response codes: 200

+ 1 - 1
Docs/settings.md

@@ -461,7 +461,7 @@ Options that can be defined when kalliope starts.
 
 Example config
 ```yaml
-start_options:
+options:
   muted: True
 ```
 

+ 1 - 1
Tests/settings/settings_test.yml

@@ -113,6 +113,6 @@ resource_directory:
 var_files:
   - "../Tests/settings/variables.yml"
 
-start_options:
+options:
   deaf: True
   mute: False

+ 4 - 4
Tests/test_models.py

@@ -259,7 +259,7 @@ class TestModels(unittest.TestCase):
                                 resources=None,
                                 variables={"key1": "val1"},
                                 recognition_options=recognition_options,
-                                start_options={'deaf': False})
+                                options={'deaf': False, 'mute': False})
             setting1.kalliope_version = "0.4.5"
 
             setting2 = Settings(default_tts_name="accapela",
@@ -274,7 +274,7 @@ class TestModels(unittest.TestCase):
                                 resources=None,
                                 variables={"key1": "val1"},
                                 recognition_options=recognition_options,
-                                start_options={'deaf': False})
+                                options={'deaf': False, 'mute': False})
             setting2.kalliope_version = "0.4.5"
 
             setting3 = Settings(default_tts_name="pico2wav",
@@ -290,7 +290,7 @@ class TestModels(unittest.TestCase):
                                 resources=None,
                                 variables={"key1": "val1"},
                                 recognition_options=recognition_options,
-                                start_options={'deaf': False})
+                                options={'deaf': False, 'mute': False})
             setting3.kalliope_version = "0.4.5"
 
             expected_result_serialize = {
@@ -318,7 +318,7 @@ class TestModels(unittest.TestCase):
                 'triggers': ['snowboy'],
                 'players': ['mplayer'],
                 'recognition_options': {'energy_threshold': 4000, 'adjust_for_ambient_noise_second': 0},
-                'start_options': {'deaf': False}
+                'options': {'deaf': False, 'mute': False}
             }
 
             self.maxDiff = None

+ 4 - 4
Tests/test_settings_loader.py

@@ -51,7 +51,7 @@ class TestSettingLoader(unittest.TestCase):
                 {'voxygen': {'voice': 'Agnes', 'cache': True}}
                 ],
             'var_files': ["../Tests/settings/variables.yml"],
-            'start_options': {'deaf': True, 'mute': False},
+            'options': {'deaf': True, 'mute': False},
             'hooks': {'on_waiting_for_trigger': 'test',
                       'on_stop_listening': None,
                       'on_start_listening': None,
@@ -123,7 +123,7 @@ class TestSettingLoader(unittest.TestCase):
             "test_number": 60,
             "test": "kalliope"
         }
-        settings_object.start_options = {
+        settings_object.options = {
             "deaf": True,
             "mute": False
         }
@@ -222,14 +222,14 @@ class TestSettingLoader(unittest.TestCase):
         self.assertEqual(expected_result,
                          sl._get_variables(self.settings_dict))
 
-    def test_get_start_options(self):
+    def test_get_options(self):
         expected_result = {
             "deaf": True,
             "mute": False
         }
         sl = SettingLoader(file_path=self.settings_file_to_test)
         self.assertEqual(expected_result,
-                         sl._get_start_options(self.settings_dict))
+                         sl._get_options(self.settings_dict))
 
     def test_get_hooks(self):
 

+ 1 - 1
kalliope/__init__.py

@@ -157,7 +157,7 @@ def main():
         if (parser.run_synapse is None) and (parser.run_order is None):
             # if --deaf
             if parser.deaf:
-                settings.start_options['deaf'] = True
+                settings.options['deaf'] = True
 
             # start rest api
             start_rest_api(settings, brain)

+ 11 - 10
kalliope/core/ConfigurationManager/SettingLoader.py

@@ -112,7 +112,7 @@ class SettingLoader(with_metaclass(Singleton, object)):
         resources = self._get_resources(settings)
         variables = self._get_variables(settings)
         recognition_options = self._get_recognition_options(settings)
-        start_options = self._get_start_options(settings)
+        options = self._get_options(settings)
         hooks = self._get_hooks(settings)
 
         # Load the setting singleton with the parameters
@@ -129,7 +129,7 @@ class SettingLoader(with_metaclass(Singleton, object)):
         setting_object.resources = resources
         setting_object.variables = variables
         setting_object.recognition_options = recognition_options
-        setting_object.start_options = start_options
+        setting_object.options = options
         setting_object.hooks = hooks
 
         return setting_object
@@ -632,7 +632,7 @@ class SettingLoader(with_metaclass(Singleton, object)):
         return recognition_options
 
     @staticmethod
-    def _get_start_options(settings):
+    def _get_options(settings):
         """
         Return the start options settings
 
@@ -641,20 +641,21 @@ class SettingLoader(with_metaclass(Singleton, object)):
         :return: A dict containing the start options
         :rtype: dict
         """
+
         options = dict()
         deaf = False
         mute = False
 
         try:
-            start_options = settings["start_options"]
+            options = settings["options"]
         except KeyError:
-            start_options = None
+            options = None
 
-        if start_options is not None:
-            if start_options['deaf']:
-                deaf = start_options['deaf']
-            if start_options['mute']:
-                mute = start_options['mute']
+        if options is not None:
+            if options['deaf']:
+                deaf = options['deaf']
+            if options['mute']:
+                mute = options['mute']
 
         options['deaf'] = deaf
         options['mute'] = mute

+ 3 - 3
kalliope/core/Models/Settings.py

@@ -22,7 +22,7 @@ class Settings(object):
                  resources=None,
                  variables=None,
                  recognition_options=None,
-                 start_options=None,
+                 options=None,
                  hooks=None):
 
         self.default_tts_name = default_tts_name
@@ -40,7 +40,7 @@ class Settings(object):
         self.machine = platform.machine()   # can be x86_64 or armv7l
         self.kalliope_version = current_kalliope_version
         self.recognition_options = recognition_options
-        self.start_options = start_options
+        self.options = options
         self.hooks = hooks
 
     def serialize(self):
@@ -67,7 +67,7 @@ class Settings(object):
             'machine': self.machine,
             'kalliope_version': self.kalliope_version,
             'recognition_options': self.recognition_options.serialize() if self.recognition_options is not None else None,
-            'start_options': self.start_options,
+            'options': self.options,
             'hooks': self.hooks
         }
 

+ 1 - 1
kalliope/core/NeuronModule.py

@@ -170,7 +170,7 @@ class NeuronModule(object):
             Cortex.save("kalliope_last_tts_message", tts_message)
 
             # process the audio only if the mute flag is false
-            if self.settings.start_options["mute"]:
+            if self.settings.options["mute"]:
                 logger.debug("[NeuronModule] mute is True, Kalliope is muted")
             else:
                 logger.debug("[NeuronModule] mute is False, make Kalliope speaking")

+ 15 - 15
kalliope/core/RestAPI/FlaskAPI.py

@@ -159,10 +159,10 @@ class FlaskAPI(threading.Thread):
         synapse_target = BrainLoader().brain.get_synapse_by_name(synapse_name=synapse_name)
 
         # Store the mute value, then apply depending of the request parameters
-        old_mute_value = self.settings.start_options["mute"]
+        old_mute_value = self.settings.options["mute"]
         mute = self.get_boolean_flag_from_request(request, boolean_flag_to_find="mute")
         if mute is not None:
-            self.settings.start_options["mute"] = mute
+            self.settings.options["mute"] = mute
 
         # get parameters
         parameters = self.get_parameters_from_request(request)
@@ -171,7 +171,7 @@ class FlaskAPI(threading.Thread):
             data = {
                 "synapse name not found": "%s" % synapse_name
             }
-            self.settings.start_options["mute"] = old_mute_value
+            self.settings.options["mute"] = old_mute_value
             return jsonify(error=data), 404
         else:
             # generate a MatchedSynapse from the synapse
@@ -181,7 +181,7 @@ class FlaskAPI(threading.Thread):
             lifo_buffer.add_synapse_list_to_lifo([matched_synapse])
             response = lifo_buffer.execute(is_api_call=True)
             data = jsonify(response)
-            self.settings.start_options["mute"] = old_mute_value
+            self.settings.options["mute"] = old_mute_value
             return data, 201
 
     @requires_auth
@@ -210,10 +210,10 @@ class FlaskAPI(threading.Thread):
         order = request.get_json('order')
 
         # Store the mute value, then apply depending of the request parameters
-        old_mute_value = self.settings.start_options["mute"]
+        old_mute_value = self.settings.options["mute"]
         mute = self.get_boolean_flag_from_request(request, boolean_flag_to_find="mute")
         if mute is not None:
-            self.settings.start_options["mute"] = mute
+            self.settings.options["mute"] = mute
 
         if order is not None:
             # get the order
@@ -225,13 +225,13 @@ class FlaskAPI(threading.Thread):
                                                                            is_api_call=True)
 
             data = jsonify(api_response)
-            self.settings.start_options["mute"] = old_mute_value
+            self.settings.options["mute"] = old_mute_value
             return data, 201
         else:
             data = {
                 "error": "order cannot be null"
             }
-            self.settings.start_options["mute"] = old_mute_value
+            self.settings.options["mute"] = old_mute_value
             return jsonify(error=data), 400
 
     @requires_auth
@@ -263,9 +263,9 @@ class FlaskAPI(threading.Thread):
             return jsonify(error=data), 400
 
         # Store the mute value, then apply depending of the request parameters
-        old_mute_value = self.settings.start_options["mute"]
+        old_mute_value = self.settings.options["mute"]
         if request.form.get("mute"):
-            self.settings.start_options["mute"] = self.str_to_bool(request.form.get("mute"))
+            self.settings.options["mute"] = self.str_to_bool(request.form.get("mute"))
 
         # save the file
         filename = secure_filename(uploaded_file.filename)
@@ -288,13 +288,13 @@ class FlaskAPI(threading.Thread):
             data = jsonify(self.api_response)
             self.api_response = None
             logger.debug("[FlaskAPI] run_synapse_by_audio: data %s" % data)
-            self.settings.start_options["mute"] = old_mute_value
+            self.settings.options["mute"] = old_mute_value
             return data, 201
         else:
             data = {
                 "error": "The given order doesn't match any synapses"
             }
-            self.settings.start_options["mute"] = old_mute_value
+            self.settings.options["mute"] = old_mute_value
             return jsonify(error=data), 400
 
     @staticmethod
@@ -386,9 +386,9 @@ class FlaskAPI(threading.Thread):
         """
 
         # find the order signal and call the deaf method
-        if self.settings.start_options["mute"] is not None:
+        if self.settings.options["mute"] is not None:
             data = {
-                "mute": self.settings.start_options["mute"]
+                "mute": self.settings.options["mute"]
             }
             return jsonify(data), 200
 
@@ -414,7 +414,7 @@ class FlaskAPI(threading.Thread):
         # get mute if present
         mute = self.get_boolean_flag_from_request(request, boolean_flag_to_find="mute")
 
-        self.settings.start_options["mute"] = mute
+        self.settings.options["mute"] = mute
         data = {
             "mute": mute
         }

+ 4 - 4
kalliope/settings.yml

@@ -162,8 +162,8 @@ rest_api:
 #  - variables2.yml
 
 # -------------
-# Start options
+# Options
 # -------------
-#start_options:
-#  deaf: False
-#  mute: False
+options:
+  deaf: False
+  mute: False

+ 1 - 1
kalliope/signals/order/order.py

@@ -48,7 +48,7 @@ class Order(Thread):
         # save an instance of the trigger
         self.trigger_instance = None
         self.trigger_callback_called = False
-        self.is_trigger_deaf = self.settings.start_options['deaf']
+        self.is_trigger_deaf = self.settings.options['deaf']
 
         # save the current order listener
         self.order_listener = None