]>
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
+ "/tools.log"
31 args
.sudo_timer
= True
34 if not os
.path
.isfile(args
.config
):
35 if args
.action
and args
.action
!= "init":
36 print('ERROR: WayDroid is not initialized, run "waydroid init"')
38 elif os
.geteuid() == 0 and args
.action
== "init":
41 args
.log
= "/tmp/tools.log"
43 tools_logging
.init(args
)
45 # Initialize or require config
46 if args
.action
== "init":
47 actionNeedRoot(args
.action
)
49 elif args
.action
== "upgrade":
50 actionNeedRoot(args
.action
)
52 elif args
.action
== "session":
53 if args
.subaction
== "start":
54 actions
.session_manager
.start(args
)
55 elif args
.subaction
== "stop":
56 actions
.session_manager
.stop(args
)
59 "Run waydroid {} -h for usage information.".format(args
.action
))
60 elif args
.action
== "container":
61 actionNeedRoot(args
.action
)
62 if args
.subaction
== "start":
63 actions
.container_manager
.start(args
)
64 elif args
.subaction
== "stop":
65 actions
.container_manager
.stop(args
)
66 if args
.subaction
== "restart":
67 actions
.container_manager
.restart(args
)
68 elif args
.subaction
== "freeze":
69 actions
.container_manager
.freeze(args
)
70 elif args
.subaction
== "unfreeze":
71 actions
.container_manager
.unfreeze(args
)
74 "Run waydroid {} -h for usage information.".format(args
.action
))
75 elif args
.action
== "app":
76 if args
.subaction
== "install":
77 actions
.app_manager
.install(args
)
78 elif args
.subaction
== "remove":
79 actions
.app_manager
.remove(args
)
80 elif args
.subaction
== "launch":
81 actions
.app_manager
.launch(args
)
82 elif args
.subaction
== "list":
83 actions
.app_manager
.list(args
)
86 "Run waydroid {} -h for usage information.".format(args
.action
))
87 elif args
.action
== "prop":
88 if args
.subaction
== "get":
89 ret
= helpers
.props
.get(args
, args
.key
)
92 elif args
.subaction
== "set":
93 helpers
.props
.set(args
, args
.key
, args
.value
)
96 "Run waydroid {} -h for usage information.".format(args
.action
))
97 elif args
.action
== "shell":
98 actionNeedRoot(args
.action
)
99 helpers
.lxc
.shell(args
)
100 elif args
.action
== "logcat":
101 actionNeedRoot(args
.action
)
102 helpers
.lxc
.logcat(args
)
103 elif args
.action
== "show-full-ui":
104 actions
.app_manager
.showFullUI(args
)
105 elif args
.action
== "status":
106 actions
.status
.print_status(args
)
107 elif args
.action
== "log":
109 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
111 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
113 logging
.info("Run waydroid -h for usage information.")
115 #logging.info("Done")
117 except Exception as e
:
118 # Dump log to stdout when args (and therefore logging) init failed
120 logging
.getLogger().setLevel(logging
.DEBUG
)
122 logging
.info("ERROR: " + str(e
))
123 logging
.info("See also: <https://github.com/waydroid>")
124 logging
.debug(traceback
.format_exc())
126 # Hints about the log file (print to stdout only)
127 log_hint
= "Run 'waydroid log' for details."
128 if not args
or not os
.path
.exists(args
.log
):
129 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
130 " get more output, e.g. 'waydroid"
131 " --details-to-stdout init'.")
136 if __name__
== "__main__":