]>
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
28 # Parse arguments, set up logging
29 args
= helpers
.arguments()
31 args
.work
= config
.defaults
["work"]
32 args
.config
= args
.work
+ "/waydroid.cfg"
33 args
.log
= args
.work
+ "/waydroid.log"
34 args
.sudo_timer
= True
38 if not os
.path
.exists(args
.work
):
40 elif not os
.path
.exists(args
.log
):
41 args
.log
= "/tmp/tools.log"
43 tools_logging
.init(args
)
45 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
46 dbus
.mainloop
.glib
.threads_init()
47 dbus_name_scope
= None
49 if not actions
.initializer
.is_initialized(args
) and \
50 args
.action
and args
.action
not in ("init", "first-launch", "log"):
51 if args
.wait_for_init
:
53 dbus_name_scope
= dbus
.service
.BusName("id.waydro.Container", dbus
.SystemBus(), do_not_queue
=True)
54 actions
.wait_for_init(args
)
55 except dbus
.exceptions
.NameExistsException
:
56 print('ERROR: WayDroid service is already awaiting initialization')
59 print('ERROR: WayDroid is not initialized, run "waydroid init"')
62 # Initialize or require config
63 if args
.action
== "init":
64 actionNeedRoot(args
.action
)
66 elif args
.action
== "upgrade":
67 actionNeedRoot(args
.action
)
69 elif args
.action
== "session":
70 if args
.subaction
== "start":
71 actions
.session_manager
.start(args
)
72 elif args
.subaction
== "stop":
73 actions
.session_manager
.stop(args
)
76 "Run waydroid {} -h for usage information.".format(args
.action
))
77 elif args
.action
== "container":
78 actionNeedRoot(args
.action
)
79 if args
.subaction
== "start":
80 if dbus_name_scope
is None:
82 dbus_name_scope
= dbus
.service
.BusName("id.waydro.Container", dbus
.SystemBus(), do_not_queue
=True)
83 except dbus
.exceptions
.NameExistsException
:
84 print('ERROR: WayDroid container service is already running')
86 actions
.container_manager
.start(args
)
87 elif args
.subaction
== "stop":
88 actions
.container_manager
.stop(args
)
89 elif args
.subaction
== "restart":
90 actions
.container_manager
.restart(args
)
91 elif args
.subaction
== "freeze":
92 actions
.container_manager
.freeze(args
)
93 elif args
.subaction
== "unfreeze":
94 actions
.container_manager
.unfreeze(args
)
97 "Run waydroid {} -h for usage information.".format(args
.action
))
98 elif args
.action
== "app":
99 if args
.subaction
== "install":
100 actions
.app_manager
.install(args
)
101 elif args
.subaction
== "remove":
102 actions
.app_manager
.remove(args
)
103 elif args
.subaction
== "launch":
104 actions
.app_manager
.launch(args
)
105 elif args
.subaction
== "intent":
106 actions
.app_manager
.intent(args
)
107 elif args
.subaction
== "list":
108 actions
.app_manager
.list(args
)
111 "Run waydroid {} -h for usage information.".format(args
.action
))
112 elif args
.action
== "prop":
113 if args
.subaction
== "get":
114 ret
= helpers
.props
.get(args
, args
.key
)
117 elif args
.subaction
== "set":
118 helpers
.props
.set(args
, args
.key
, args
.value
)
121 "Run waydroid {} -h for usage information.".format(args
.action
))
122 elif args
.action
== "shell":
123 actionNeedRoot(args
.action
)
124 helpers
.lxc
.shell(args
)
125 elif args
.action
== "logcat":
126 actionNeedRoot(args
.action
)
127 helpers
.lxc
.logcat(args
)
128 elif args
.action
== "show-full-ui":
129 actions
.app_manager
.showFullUI(args
)
130 elif args
.action
== "first-launch":
131 actions
.remote_init_client(args
)
132 if actions
.initializer
.is_initialized(args
):
133 actions
.app_manager
.showFullUI(args
)
134 elif args
.action
== "status":
135 actions
.status
.print_status(args
)
136 elif args
.action
== "log":
138 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
141 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
142 except KeyboardInterrupt:
145 logging
.info("Run waydroid -h for usage information.")
147 #logging.info("Done")
149 except Exception as e
:
150 # Dump log to stdout when args (and therefore logging) init failed
152 logging
.getLogger().setLevel(logging
.DEBUG
)
154 logging
.info("ERROR: " + str(e
))
155 logging
.info("See also: <https://github.com/waydroid>")
156 logging
.debug(traceback
.format_exc())
158 # Hints about the log file (print to stdout only)
159 log_hint
= "Run 'waydroid log' for details."
160 if not args
or not os
.path
.exists(args
.log
):
161 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
162 " get more output, e.g. 'waydroid"
163 " --details-to-stdout init'.")
168 if __name__
== "__main__":