]>
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
12 from .helpers
import logging
as tools_logging
16 def actionNeedRoot(action
):
19 "Action \"{}\" needs root access".format(action
))
21 # Wrap everything to display nice error messages
25 # Parse arguments, set up logging
26 args
= helpers
.arguments()
28 args
.work
= config
.defaults
["work"]
29 args
.config
= args
.work
+ "/waydroid.cfg"
30 args
.log
= args
.work
+ "/waydroid.log"
31 args
.sudo_timer
= True
35 if not os
.path
.exists(args
.work
):
37 elif not os
.path
.exists(args
.log
):
38 args
.log
= "/tmp/tools.log"
40 tools_logging
.init(args
)
42 if not actions
.initializer
.is_initialized(args
) and \
43 args
.action
and args
.action
not in ("init", "first-launch", "log"):
44 if args
.wait_for_init
:
45 actions
.wait_for_init(args
)
47 print('ERROR: WayDroid is not initialized, run "waydroid init"')
50 # Initialize or require config
51 if args
.action
== "init":
52 actionNeedRoot(args
.action
)
54 elif args
.action
== "upgrade":
55 actionNeedRoot(args
.action
)
57 elif args
.action
== "session":
58 if args
.subaction
== "start":
59 actions
.session_manager
.start(args
)
60 elif args
.subaction
== "stop":
61 actions
.session_manager
.stop(args
)
64 "Run waydroid {} -h for usage information.".format(args
.action
))
65 elif args
.action
== "container":
66 actionNeedRoot(args
.action
)
67 if args
.subaction
== "start":
68 actions
.container_manager
.start(args
)
69 elif args
.subaction
== "stop":
70 actions
.container_manager
.stop(args
)
71 elif args
.subaction
== "restart":
72 actions
.container_manager
.restart(args
)
73 elif args
.subaction
== "freeze":
74 actions
.container_manager
.freeze(args
)
75 elif args
.subaction
== "unfreeze":
76 actions
.container_manager
.unfreeze(args
)
79 "Run waydroid {} -h for usage information.".format(args
.action
))
80 elif args
.action
== "app":
81 if args
.subaction
== "install":
82 actions
.app_manager
.install(args
)
83 elif args
.subaction
== "remove":
84 actions
.app_manager
.remove(args
)
85 elif args
.subaction
== "launch":
86 actions
.app_manager
.launch(args
)
87 elif args
.subaction
== "intent":
88 actions
.app_manager
.intent(args
)
89 elif args
.subaction
== "list":
90 actions
.app_manager
.list(args
)
93 "Run waydroid {} -h for usage information.".format(args
.action
))
94 elif args
.action
== "prop":
95 if args
.subaction
== "get":
96 ret
= helpers
.props
.get(args
, args
.key
)
99 elif args
.subaction
== "set":
100 helpers
.props
.set(args
, args
.key
, args
.value
)
103 "Run waydroid {} -h for usage information.".format(args
.action
))
104 elif args
.action
== "shell":
105 actionNeedRoot(args
.action
)
106 helpers
.lxc
.shell(args
)
107 elif args
.action
== "logcat":
108 actionNeedRoot(args
.action
)
109 helpers
.lxc
.logcat(args
)
110 elif args
.action
== "show-full-ui":
111 actions
.app_manager
.showFullUI(args
)
112 elif args
.action
== "first-launch":
113 actions
.remote_init_client(args
)
114 if actions
.initializer
.is_initialized(args
):
115 actions
.app_manager
.showFullUI(args
)
116 elif args
.action
== "status":
117 actions
.status
.print_status(args
)
118 elif args
.action
== "log":
120 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
123 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
124 except KeyboardInterrupt:
127 logging
.info("Run waydroid -h for usage information.")
129 #logging.info("Done")
131 except Exception as e
:
132 # Dump log to stdout when args (and therefore logging) init failed
134 logging
.getLogger().setLevel(logging
.DEBUG
)
136 logging
.info("ERROR: " + str(e
))
137 logging
.info("See also: <https://github.com/waydroid>")
138 logging
.debug(traceback
.format_exc())
140 # Hints about the log file (print to stdout only)
141 log_hint
= "Run 'waydroid log' for details."
142 if not args
or not os
.path
.exists(args
.log
):
143 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
144 " get more output, e.g. 'waydroid"
145 " --details-to-stdout init'.")
150 if __name__
== "__main__":