]>
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
34 if not actions
.initializer
.is_initialized(args
):
35 if args
.action
and (args
.action
!= "init" and args
.action
!= "log"):
36 if not args
.wait_for_init
:
37 print('ERROR: WayDroid is not initialized, run "waydroid init"')
40 print('WayDroid waiting for initialization...')
41 while helpers
.ipc
.listen(channel
="init") != "done":
44 elif os
.geteuid() == 0 and args
.action
== "init":
45 if not os
.path
.exists(args
.work
):
48 # This branch is taken if:
49 # - waydroid is not yet initialized
50 # - waydroid is invoked with no command or with log
51 if not os
.path
.exists(args
.log
):
52 # The log could have been already created if init was used and failed, if its not the case we use a temporary one
53 args
.log
= "/tmp/tools.log"
55 tools_logging
.init(args
)
57 # Initialize or require config
58 if args
.action
== "init":
59 actionNeedRoot(args
.action
)
61 elif args
.action
== "upgrade":
62 actionNeedRoot(args
.action
)
64 elif args
.action
== "session":
65 if args
.subaction
== "start":
66 actions
.session_manager
.start(args
)
67 elif args
.subaction
== "stop":
68 actions
.session_manager
.stop(args
)
71 "Run waydroid {} -h for usage information.".format(args
.action
))
72 elif args
.action
== "container":
73 actionNeedRoot(args
.action
)
74 if args
.subaction
== "start":
75 actions
.container_manager
.start(args
)
76 elif args
.subaction
== "stop":
77 actions
.container_manager
.stop(args
)
78 elif args
.subaction
== "restart":
79 actions
.container_manager
.restart(args
)
80 elif args
.subaction
== "freeze":
81 actions
.container_manager
.freeze(args
)
82 elif args
.subaction
== "unfreeze":
83 actions
.container_manager
.unfreeze(args
)
86 "Run waydroid {} -h for usage information.".format(args
.action
))
87 elif args
.action
== "app":
88 if args
.subaction
== "install":
89 actions
.app_manager
.install(args
)
90 elif args
.subaction
== "remove":
91 actions
.app_manager
.remove(args
)
92 elif args
.subaction
== "launch":
93 actions
.app_manager
.launch(args
)
94 elif args
.subaction
== "intent":
95 actions
.app_manager
.intent(args
)
96 elif args
.subaction
== "list":
97 actions
.app_manager
.list(args
)
100 "Run waydroid {} -h for usage information.".format(args
.action
))
101 elif args
.action
== "prop":
102 if args
.subaction
== "get":
103 ret
= helpers
.props
.get(args
, args
.key
)
106 elif args
.subaction
== "set":
107 helpers
.props
.set(args
, args
.key
, args
.value
)
110 "Run waydroid {} -h for usage information.".format(args
.action
))
111 elif args
.action
== "shell":
112 actionNeedRoot(args
.action
)
113 helpers
.lxc
.shell(args
)
114 elif args
.action
== "logcat":
115 actionNeedRoot(args
.action
)
116 helpers
.lxc
.logcat(args
)
117 elif args
.action
== "show-full-ui":
118 actions
.app_manager
.showFullUI(args
)
119 elif args
.action
== "status":
120 actions
.status
.print_status(args
)
121 elif args
.action
== "log":
123 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
126 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
127 except KeyboardInterrupt:
130 logging
.info("Run waydroid -h for usage information.")
132 #logging.info("Done")
134 except Exception as e
:
135 # Dump log to stdout when args (and therefore logging) init failed
137 logging
.getLogger().setLevel(logging
.DEBUG
)
139 logging
.info("ERROR: " + str(e
))
140 logging
.info("See also: <https://github.com/waydroid>")
141 logging
.debug(traceback
.format_exc())
143 # Hints about the log file (print to stdout only)
144 log_hint
= "Run 'waydroid log' for details."
145 if not args
or not os
.path
.exists(args
.log
):
146 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
147 " get more output, e.g. 'waydroid"
148 " --details-to-stdout init'.")
153 if __name__
== "__main__":