Ver código fonte

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 anos atrás
pai
commit
c46bcf3a1a
5 arquivos alterados com 24 adições e 8 exclusões
  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 Ver arquivo

@@ -27,9 +27,14 @@ class Kaylee:
27 27
         self.config = Config()
28 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 35
         # Load plugins
31 36
         self.plugins = []
32
-        for plugin in self.options['plugins'].keys():
37
+        for plugin in self.config.plugins.keys():
33 38
             pmod = importlib.import_module(plugin, 'kayleevc.plugins')
34 39
             self.plugins.append(pmod.Plugin(self.config, plugin))
35 40
 

+ 1
- 1
kayleevc/plugins/pluginbase.py Ver arquivo

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

+ 11
- 0
kayleevc/util.py Ver arquivo

@@ -27,6 +27,7 @@ class Config:
27 27
 
28 28
     # Configuration files
29 29
     opt_file = os.path.join(conf_dir, "options.json")
30
+    plugins_file = os.path.join(conf_dir, "plugins.json")
30 31
 
31 32
     # Cache files
32 33
     history_file = os.path.join(cache_dir, program_name + "history")
@@ -76,6 +77,9 @@ class Config:
76 77
         # Parse command-line arguments, overriding config file as appropriate
77 78
         self._parser.parse_args(namespace=self.options)
78 79
 
80
+        # Read the plugins file
81
+        self._read_plugins_file()
82
+
79 83
     def _make_dir(self, directory):
80 84
         if not os.path.exists(directory):
81 85
             os.makedirs(directory)
@@ -89,6 +93,13 @@ class Config:
89 93
             # Make an empty options namespace
90 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 104
 class Hasher:
94 105
     """Keep track of hashes for Kaylee"""

+ 0
- 6
options.json.tmp Ver arquivo

@@ -1,10 +1,4 @@
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 2
     "continuous": false,
9 3
     "history": null,
10 4
     "microphone": null,

+ 6
- 0
plugins.json.tmp Ver arquivo

@@ -0,0 +1,6 @@
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
+}

Carregando…
Cancelar
Salvar