tools: ratbagctl.devel: do not spawn a subprocess to run a python script
We do not really care using the actual ratbagctl command, we just want
to run it. So we can simply call out the python functions directly
and live happily ever after.
import os
import toolbox
-import subprocess
import sys
@@ -35,15 +34,19 @@ def main(argv):
if not os.geteuid() == 0:
sys.exit('Script must be run as root')
- ratbagd = toolbox.start_ratbagd()
+ if not argv:
+ argv = ["list"]
- try:
- ratbagctl = subprocess.Popen(" ".join([toolbox.RATBAGCTL_PATH, *sys.argv[1:]]))
+ ratbagd_process = toolbox.start_ratbagd()
+
+ ratbagd = toolbox.open_ratbagd()
+ parser = toolbox.get_parser()
- ratbagctl.wait()
- except KeyboardInterrupt:
- pass
- toolbox.terminate_ratbagd(ratbagd)
+ try:
+ cmd = parser.parse(argv)
+ cmd.func(ratbagd, cmd)
+ finally:
+ toolbox.terminate_ratbagd(ratbagd_process)
if __name__ == "__main__":
