]>
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
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
36 if not os
.path
.exists(args
.work
):
38 elif not os
.path
.exists(args
.log
):
39 args
.log
= "/tmp/tools.log"
41 tools_logging
.init(args
)
43 dbus
.mainloop
.glib
.DBusGMainLoop(set_as_default
=True)
44 dbus
.mainloop
.glib
.threads_init()
46 if not actions
.initializer
.is_initialized(args
) and \
47 args
.action
and args
.action
not in ("init", "first-launch", "log"):
48 if args
.wait_for_init
:
49 actions
.wait_for_init(args
)
51 print('ERROR: WayDroid is not initialized, run "waydroid init"')
54 # Initialize or require config
55 if args
.action
== "init":
56 actionNeedRoot(args
.action
)
58 elif args
.action
== "upgrade":
59 actionNeedRoot(args
.action
)
61 elif args
.action
== "session":
62 if args
.subaction
== "start":
63 actions
.session_manager
.start(args
)
64 elif args
.subaction
== "stop":
65 actions
.session_manager
.stop(args
)
68 "Run waydroid {} -h for usage information.".format(args
.action
))
69 elif args
.action
== "container":
70 actionNeedRoot(args
.action
)
71 if args
.subaction
== "start":
72 actions
.container_manager
.start(args
)
73 elif args
.subaction
== "stop":
74 actions
.container_manager
.stop(args
)
75 elif args
.subaction
== "restart":
76 actions
.container_manager
.restart(args
)
77 elif args
.subaction
== "freeze":
78 actions
.container_manager
.freeze(args
)
79 elif args
.subaction
== "unfreeze":
80 actions
.container_manager
.unfreeze(args
)
83 "Run waydroid {} -h for usage information.".format(args
.action
))
84 elif args
.action
== "app":
85 if args
.subaction
== "install":
86 actions
.app_manager
.install(args
)
87 elif args
.subaction
== "remove":
88 actions
.app_manager
.remove(args
)
89 elif args
.subaction
== "launch":
90 actions
.app_manager
.launch(args
)
91 elif args
.subaction
== "intent":
92 actions
.app_manager
.intent(args
)
93 elif args
.subaction
== "list":
94 actions
.app_manager
.list(args
)
97 "Run waydroid {} -h for usage information.".format(args
.action
))
98 elif args
.action
== "prop":
99 if args
.subaction
== "get":
100 ret
= helpers
.props
.get(args
, args
.key
)
103 elif args
.subaction
== "set":
104 helpers
.props
.set(args
, args
.key
, args
.value
)
107 "Run waydroid {} -h for usage information.".format(args
.action
))
108 elif args
.action
== "shell":
109 actionNeedRoot(args
.action
)
110 helpers
.lxc
.shell(args
)
111 elif args
.action
== "logcat":
112 actionNeedRoot(args
.action
)
113 helpers
.lxc
.logcat(args
)
114 elif args
.action
== "show-full-ui":
115 actions
.app_manager
.showFullUI(args
)
116 elif args
.action
== "first-launch":
117 actions
.remote_init_client(args
)
118 if actions
.initializer
.is_initialized(args
):
119 actions
.app_manager
.showFullUI(args
)
120 elif args
.action
== "status":
121 actions
.status
.print_status(args
)
122 elif args
.action
== "log":
124 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
127 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
128 except KeyboardInterrupt:
131 logging
.info("Run waydroid -h for usage information.")
133 #logging.info("Done")
135 except Exception as e
:
136 # Dump log to stdout when args (and therefore logging) init failed
138 logging
.getLogger().setLevel(logging
.DEBUG
)
140 logging
.info("ERROR: " + str(e
))
141 logging
.info("See also: <https://github.com/waydroid>")
142 logging
.debug(traceback
.format_exc())
144 # Hints about the log file (print to stdout only)
145 log_hint
= "Run 'waydroid log' for details."
146 if not args
or not os
.path
.exists(args
.log
):
147 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
148 " get more output, e.g. 'waydroid"
149 " --details-to-stdout init'.")
154 if __name__
== "__main__":