]>
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
8 import dbus
.mainloop
.glib
10 import dbus
.exceptions
15 from .helpers
import logging
as tools_logging
19 def actionNeedRoot(action
):
22 "Action \"{}\" needs root access".format(action
))
24 # Wrap everything to display nice error messages
27 # Parse arguments, set up logging
28 args
= helpers
.arguments()
30 args
.work
= config
.defaults
["work"]
31 args
.config
= args
.work
+ "/waydroid.cfg"
32 args
.log
= args
.work
+ "/waydroid.log"
33 args
.sudo_timer
= True
37 if not os
.path
.exists(args
.work
):
39 elif not os
.path
.exists(args
.log
):
40 args
.log
= "/tmp/tools.log"
42 tools_logging
.init(args
)
44 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
45 dbus
.mainloop
.glib
.threads_init()
46 dbus_name_scope
= None
48 if not actions
.initializer
.is_initialized(args
) and \
49 args
.action
and args
.action
not in ("init", "first-launch", "log"):
50 if args
.wait_for_init
:
52 dbus_name_scope
= dbus
.service
.BusName("id.waydro.Container", dbus
.SystemBus(), do_not_queue
=True)
53 actions
.wait_for_init(args
)
54 except dbus
.exceptions
.NameExistsException
:
55 print('ERROR: WayDroid service is already awaiting initialization')
58 print('ERROR: WayDroid is not initialized, run "waydroid init"')
61 # Initialize or require config
62 if args
.action
== "init":
63 actionNeedRoot(args
.action
)
65 elif args
.action
== "upgrade":
66 actionNeedRoot(args
.action
)
68 elif args
.action
== "session":
69 if args
.subaction
== "start":
70 actions
.session_manager
.start(args
)
71 elif args
.subaction
== "stop":
72 actions
.session_manager
.stop(args
)
75 "Run waydroid {} -h for usage information.".format(args
.action
))
76 elif args
.action
== "container":
77 actionNeedRoot(args
.action
)
78 if args
.subaction
== "start":
79 if dbus_name_scope
is None:
81 dbus_name_scope
= dbus
.service
.BusName("id.waydro.Container", dbus
.SystemBus(), do_not_queue
=True)
82 except dbus
.exceptions
.NameExistsException
:
83 print('ERROR: WayDroid container service is already running')
85 actions
.container_manager
.start(args
)
86 elif args
.subaction
== "stop":
87 actions
.container_manager
.stop(args
)
88 elif args
.subaction
== "restart":
89 actions
.container_manager
.restart(args
)
90 elif args
.subaction
== "freeze":
91 actions
.container_manager
.freeze(args
)
92 elif args
.subaction
== "unfreeze":
93 actions
.container_manager
.unfreeze(args
)
96 "Run waydroid {} -h for usage information.".format(args
.action
))
97 elif args
.action
== "app":
98 if args
.subaction
== "install":
99 actions
.app_manager
.install(args
)
100 elif args
.subaction
== "remove":
101 actions
.app_manager
.remove(args
)
102 elif args
.subaction
== "launch":
103 actions
.app_manager
.launch(args
)
104 elif args
.subaction
== "intent":
105 actions
.app_manager
.intent(args
)
106 elif args
.subaction
== "list":
107 actions
.app_manager
.list(args
)
110 "Run waydroid {} -h for usage information.".format(args
.action
))
111 elif args
.action
== "prop":
112 if args
.subaction
== "get":
113 actions
.prop
.get(args
)
114 elif args
.subaction
== "set":
115 actions
.prop
.set(args
)
118 "Run waydroid {} -h for usage information.".format(args
.action
))
119 elif args
.action
== "shell":
120 actionNeedRoot(args
.action
)
121 helpers
.lxc
.shell(args
)
122 elif args
.action
== "logcat":
123 actionNeedRoot(args
.action
)
124 helpers
.lxc
.logcat(args
)
125 elif args
.action
== "show-full-ui":
126 actions
.app_manager
.showFullUI(args
)
127 elif args
.action
== "first-launch":
128 actions
.remote_init_client(args
)
129 if actions
.initializer
.is_initialized(args
):
130 actions
.app_manager
.showFullUI(args
)
131 elif args
.action
== "status":
132 actions
.status
.print_status(args
)
133 elif args
.action
== "adb":
134 if args
.subaction
== "connect":
135 helpers
.net
.adb_connect(args
)
136 elif args
.subaction
== "disconnect":
137 helpers
.net
.adb_disconnect(args
)
139 logging
.info("Run waydroid {} -h for usage information.".format(args
.action
))
140 elif args
.action
== "log":
142 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
145 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
146 except KeyboardInterrupt:
149 logging
.info("Run waydroid -h for usage information.")
151 #logging.info("Done")
153 except Exception as e
:
154 # Dump log to stdout when args (and therefore logging) init failed
156 logging
.getLogger().setLevel(logging
.DEBUG
)
158 logging
.info("ERROR: " + str(e
))
159 logging
.info("See also: <https://github.com/waydroid>")
160 logging
.debug(traceback
.format_exc())
162 # Hints about the log file (print to stdout only)
163 log_hint
= "Run 'waydroid log' for details."
164 if not args
or not os
.path
.exists(args
.log
):
165 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
166 " get more output, e.g. 'waydroid"
167 " --details-to-stdout init'.")
172 if __name__
== "__main__":