Browse Source

Moved plugin configuration to plugins.json

After listening to HPR 1284 today, I realized that it's important to
keep configuration of what Kaylee *does* separate from other
configuration.  Specifically, once TTS integration is done, voice
configuration will need to be separate from configuration of actions,
because it's common to have several computers with the same actions but
different voices.  Therefore, I've moved all configuration about plugins
into a new file called plugins.json.
Clara Hobbs 7 years ago
parent
commit
c46bcf3a1a
5 changed files with 24 additions and 8 deletions
  1. 6
    1
      kayleevc/kaylee.py
  2. 1
    1
      kayleevc/plugins/pluginbase.py
  3. 11
    0
      kayleevc/util.py
  4. 0
    6
      options.json.tmp
  5. 6
    0
      plugins.json.tmp

+ 6
- 1
kayleevc/kaylee.py View File

27
         self.config = Config()
27
         self.config = Config()
28
         self.options = vars(self.config.options)
28
         self.options = vars(self.config.options)
29
 
29
 
30
+        # Make sure some plugins are configured to be loaded
31
+        if self.config.plugins is None:
32
+            print("error: no plugins configured", file=sys.stderr)
33
+            sys.exit(1)
34
+
30
         # Load plugins
35
         # Load plugins
31
         self.plugins = []
36
         self.plugins = []
32
-        for plugin in self.options['plugins'].keys():
37
+        for plugin in self.config.plugins.keys():
33
             pmod = importlib.import_module(plugin, 'kayleevc.plugins')
38
             pmod = importlib.import_module(plugin, 'kayleevc.plugins')
34
             self.plugins.append(pmod.Plugin(self.config, plugin))
39
             self.plugins.append(pmod.Plugin(self.config, plugin))
35
 
40
 

+ 1
- 1
kayleevc/plugins/pluginbase.py View File

29
         super().__init__()
29
         super().__init__()
30
         self.config = config
30
         self.config = config
31
         self.name = name
31
         self.name = name
32
-        self.options = config.options.plugins[name]
32
+        self.options = config.plugins[name]
33
         self.corpus_strings = set()
33
         self.corpus_strings = set()
34
 
34
 
35
     def recognizer_finished(self, recognizer, text):
35
     def recognizer_finished(self, recognizer, text):

+ 11
- 0
kayleevc/util.py View File

27
 
27
 
28
     # Configuration files
28
     # Configuration files
29
     opt_file = os.path.join(conf_dir, "options.json")
29
     opt_file = os.path.join(conf_dir, "options.json")
30
+    plugins_file = os.path.join(conf_dir, "plugins.json")
30
 
31
 
31
     # Cache files
32
     # Cache files
32
     history_file = os.path.join(cache_dir, program_name + "history")
33
     history_file = os.path.join(cache_dir, program_name + "history")
76
         # Parse command-line arguments, overriding config file as appropriate
77
         # Parse command-line arguments, overriding config file as appropriate
77
         self._parser.parse_args(namespace=self.options)
78
         self._parser.parse_args(namespace=self.options)
78
 
79
 
80
+        # Read the plugins file
81
+        self._read_plugins_file()
82
+
79
     def _make_dir(self, directory):
83
     def _make_dir(self, directory):
80
         if not os.path.exists(directory):
84
         if not os.path.exists(directory):
81
             os.makedirs(directory)
85
             os.makedirs(directory)
89
             # Make an empty options namespace
93
             # Make an empty options namespace
90
             self.options = Namespace()
94
             self.options = Namespace()
91
 
95
 
96
+    def _read_plugins_file(self):
97
+        try:
98
+            with open(self.plugins_file, 'r') as f:
99
+                self.plugins = json.load(f, object_pairs_hook=OrderedDict)
100
+        except FileNotFoundError:
101
+            self.plugins = None
102
+
92
 
103
 
93
 class Hasher:
104
 class Hasher:
94
     """Keep track of hashes for Kaylee"""
105
     """Keep track of hashes for Kaylee"""

+ 0
- 6
options.json.tmp View File

1
 {
1
 {
2
-    "plugins": {
3
-        ".shell": {
4
-            "hello world": "echo \"hello world\"",
5
-            "start a %d minute timer": "(echo {0} minute timer started && sleep {0}m && echo {0} minute timer ended) &"
6
-        }
7
-    },
8
     "continuous": false,
2
     "continuous": false,
9
     "history": null,
3
     "history": null,
10
     "microphone": null,
4
     "microphone": null,

+ 6
- 0
plugins.json.tmp View File

1
+{
2
+    ".shell": {
3
+        "hello world": "echo \"hello world\"",
4
+        "start a %d minute timer": "(echo {0} minute timer started && sleep {0}m && echo {0} minute timer ended) &"
5
+    }
6
+}

Loading…
Cancel
Save