Browse Source

Stop on '_example' profile, now load actions

Profile will now stop after it's made the example profile

Profile will now load it's config, and process actions in the keys
directory (ignoring non-toml files, and those considered hidden, or
directories)
apollo 5 days ago
parent
commit
3e4b732b27
1 changed files with 22 additions and 3 deletions
  1. 22 3
      tyrell.py

+ 22 - 3
tyrell.py

@@ -69,7 +69,7 @@ else:
     # We can simply use the mouse module under WINDOWS and MACOS
     from mouse import press as _mouse_down, release as _mouse_up, click as _click
 
-from toml import load as _toml_load
+from toml import load as _toml_load, TomlDecodeError as _TomlDecodeError
 
 from asyncio import run as _run, sleep as _asleep
 from asyncio.tasks import gather as _task_group
@@ -343,6 +343,9 @@ class Profile:
             if not _exists(_join(self.name, "keys")):
                 _write_example(self.name)
                 _write_example_mirror(self.name)
+        if self.name == "_example":
+            _print_warn("Got example profile, creation only")
+            return # Done with example code
         # Load toml config
         with open(_join(self.name, self.name+".toml"), "r") as f:
             dat = _toml_load(f)
@@ -371,10 +374,26 @@ class Profile:
                     self.activator = str(val)
                 elif key == "helper":
                     self.helper = str(val)
+        # Locate and "load" actions
+        for entry in _listdir(_join(self.name, "keys")):
+            if entry.startswith(".") or _isdir(entry) or not entry.endswith(".toml"):
+                _print_info(f"{_join(self.name, "keys", entry)} => skipped")
+                continue
+            # Must be a toml file, probably an action
+            file = _join(self.name, "keys", entry)
+            try:
+                data = _toml_load(file)
+                a = Action(data)
+                if a.kind != 'mirror':
+                    _print_ok(f"{file} => '{a.kind}' action, trigger on '{a.key}'")
+                else:
+                    _print_ok(f"{file} => '{a.kind}' action, trigger on '{a.mirror}' (toggle with '{a.key}')")
+            except _TomlDecodeError:
+                _print_warn(f"{file} => invalid toml")
 
 if __name__ == "__main__":
     if not _exists("_example"):
         _print_warn("Missing '_example' profile, creating...")
-        p = Profile("_example")
+        Profile("_example")
         _print_ok("")
-    _print_ok("")
+    p = Profile("_test")