]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/__init__.py
1 # Copyright 2021 Oliver Smith
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 # PYTHON_ARGCOMPLETE_OK
13 from .helpers
import logging
as tools_logging
17 def actionNeedRoot(action
):
20 "Action \"{}\" needs root access".format(action
))
22 # Wrap everything to display nice error messages
26 # Parse arguments, set up logging
27 args
= helpers
.arguments()
29 args
.work
= config
.defaults
["work"]
30 args
.config
= args
.work
+ "/waydroid.cfg"
31 args
.log
= args
.work
+ "/waydroid.log"
32 args
.sudo_timer
= True
35 if not actions
.initializer
.is_initialized(args
):
36 if args
.action
and (args
.action
not in ("init", "first-launch", "log")):
37 if not args
.wait_for_init
:
38 print('ERROR: WayDroid is not initialized, run "waydroid init"')
41 print('WayDroid waiting for initialization...')
42 while helpers
.ipc
.listen(channel
="init") != "done":
45 elif os
.geteuid() == 0 and args
.action
== "init":
46 if not os
.path
.exists(args
.work
):
49 # This branch is taken if:
50 # - waydroid is not yet initialized
51 # - waydroid is invoked with no command or with log
52 if not os
.path
.exists(args
.log
):
53 # The log could have been already created if init was used and failed, if its not the case we use a temporary one
54 args
.log
= "/tmp/tools.log"
56 tools_logging
.init(args
)
58 # Initialize or require config
59 if args
.action
== "init":
60 actionNeedRoot(args
.action
)
62 elif args
.action
== "upgrade":
63 actionNeedRoot(args
.action
)
65 elif args
.action
== "session":
66 if args
.subaction
== "start":
67 actions
.session_manager
.start(args
)
68 elif args
.subaction
== "stop":
69 actions
.session_manager
.stop(args
)
72 "Run waydroid {} -h for usage information.".format(args
.action
))
73 elif args
.action
== "container":
74 actionNeedRoot(args
.action
)
75 if args
.subaction
== "start":
76 actions
.container_manager
.start(args
)
77 elif args
.subaction
== "stop":
78 actions
.container_manager
.stop(args
)
79 elif args
.subaction
== "restart":
80 actions
.container_manager
.restart(args
)
81 elif args
.subaction
== "freeze":
82 actions
.container_manager
.freeze(args
)
83 elif args
.subaction
== "unfreeze":
84 actions
.container_manager
.unfreeze(args
)
87 "Run waydroid {} -h for usage information.".format(args
.action
))
88 elif args
.action
== "app":
89 if args
.subaction
== "install":
90 actions
.app_manager
.install(args
)
91 elif args
.subaction
== "remove":
92 actions
.app_manager
.remove(args
)
93 elif args
.subaction
== "launch":
94 actions
.app_manager
.launch(args
)
95 elif args
.subaction
== "intent":
96 actions
.app_manager
.intent(args
)
97 elif args
.subaction
== "list":
98 actions
.app_manager
.list(args
)
101 "Run waydroid {} -h for usage information.".format(args
.action
))
102 elif args
.action
== "prop":
103 if args
.subaction
== "get":
104 ret
= helpers
.props
.get(args
, args
.key
)
107 elif args
.subaction
== "set":
108 helpers
.props
.set(args
, args
.key
, args
.value
)
111 "Run waydroid {} -h for usage information.".format(args
.action
))
112 elif args
.action
== "shell":
113 actionNeedRoot(args
.action
)
114 helpers
.lxc
.shell(args
)
115 elif args
.action
== "logcat":
116 actionNeedRoot(args
.action
)
117 helpers
.lxc
.logcat(args
)
118 elif args
.action
== "show-full-ui":
119 actions
.app_manager
.showFullUI(args
)
120 elif args
.action
== "first-launch":
121 subprocess
.run(["pkexec", sys
.argv
[0], "init", "--gui"])
122 if actions
.initializer
.is_initialized(args
):
123 actions
.app_manager
.showFullUI(args
)
124 elif args
.action
== "status":
125 actions
.status
.print_status(args
)
126 elif args
.action
== "log":
128 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
131 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
132 except KeyboardInterrupt:
135 logging
.info("Run waydroid -h for usage information.")
137 #logging.info("Done")
139 except Exception as e
:
140 # Dump log to stdout when args (and therefore logging) init failed
142 logging
.getLogger().setLevel(logging
.DEBUG
)
144 logging
.info("ERROR: " + str(e
))
145 logging
.info("See also: <https://github.com/waydroid>")
146 logging
.debug(traceback
.format_exc())
148 # Hints about the log file (print to stdout only)
149 log_hint
= "Run 'waydroid log' for details."
150 if not args
or not os
.path
.exists(args
.log
):
151 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
152 " get more output, e.g. 'waydroid"
153 " --details-to-stdout init'.")
158 if __name__
== "__main__":