]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/__init__.py
init: Always redownload the image when changing parameters
[waydroid.git] / tools / __init__.py
index 13a6110b15ec0e266957376a4a5977d22bfb8271..2443e6ebb5d6a7a5c2f580bdbca6288094fe5896 100644 (file)
@@ -27,18 +27,30 @@ def main():
         args.cache = {}
         args.work = config.defaults["work"]
         args.config = args.work + "/waydroid.cfg"
-        args.log = args.work + "/tools.log"
+        args.log = args.work + "/waydroid.log"
         args.sudo_timer = True
         args.timeout = 1800
 
-        if not os.path.isfile(args.config):
-            if args.action and args.action != "init":
-                print('ERROR: WayDroid is not initialized, run "waydroid init"')
-                return 0
+        if not actions.initializer.is_initialized(args):
+            if args.action and (args.action != "init" and args.action != "log"):
+                if not args.wait_for_init:
+                    print('ERROR: WayDroid is not initialized, run "waydroid init"')
+                    return 0
+
+                print('WayDroid waiting for initialization...')
+                while helpers.ipc.listen(channel="init") != "done":
+                    pass
+
             elif os.geteuid() == 0 and args.action == "init":
-                os.mkdir(args.work)
+                if not os.path.exists(args.work):
+                    os.mkdir(args.work)
             else:
-                args.log = "/tmp/tools.log"
+                # This branch is taken if:
+                # - waydroid is not yet initialized
+                # - waydroid is invoked with no command or with log
+                if not os.path.exists(args.log):
+                    # The log could have been already created if init was used and failed, if its not the case we use a temporary one
+                    args.log = "/tmp/tools.log"
 
         tools_logging.init(args)
 
@@ -63,7 +75,7 @@ def main():
                 actions.container_manager.start(args)
             elif args.subaction == "stop":
                 actions.container_manager.stop(args)
-            if args.subaction == "restart":
+            elif args.subaction == "restart":
                 actions.container_manager.restart(args)
             elif args.subaction == "freeze":
                 actions.container_manager.freeze(args)
@@ -79,6 +91,8 @@ def main():
                 actions.app_manager.remove(args)
             elif args.subaction == "launch":
                 actions.app_manager.launch(args)
+            elif args.subaction == "intent":
+                actions.app_manager.intent(args)
             elif args.subaction == "list":
                 actions.app_manager.list(args)
             else:
@@ -107,8 +121,11 @@ def main():
         elif args.action == "log":
             if args.clear_log:
                 helpers.run.user(args, ["truncate", "-s", "0", args.log])
-            helpers.run.user(
-                args, ["tail", "-n", args.lines, "-F", args.log], output="tui")
+            try:
+                helpers.run.user(
+                    args, ["tail", "-n", args.lines, "-F", args.log], output="tui")
+            except KeyboardInterrupt:
+                pass
         else:
             logging.info("Run waydroid -h for usage information.")