]>
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 elif args
.subaction
== "freeze":
67 actions
.container_manager
.freeze(args
)
68 elif args
.subaction
== "unfreeze":
69 actions
.container_manager
.unfreeze(args
)
72 "Run waydroid {} -h for usage information.".format(args
.action
))
73 elif args
.action
== "app":
74 if args
.subaction
== "install":
75 actions
.app_manager
.install(args
)
76 elif args
.subaction
== "remove":
77 actions
.app_manager
.remove(args
)
78 elif args
.subaction
== "launch":
79 actions
.app_manager
.launch(args
)
80 elif args
.subaction
== "list":
81 actions
.app_manager
.list(args
)
84 "Run waydroid {} -h for usage information.".format(args
.action
))
85 elif args
.action
== "prop":
86 if args
.subaction
== "get":
87 ret
= helpers
.props
.get(args
, args
.key
)
90 elif args
.subaction
== "set":
91 helpers
.props
.set(args
, args
.key
, args
.value
)
94 "Run waydroid {} -h for usage information.".format(args
.action
))
95 elif args
.action
== "shell":
96 actionNeedRoot(args
.action
)
97 helpers
.lxc
.shell(args
)
98 elif args
.action
== "logcat":
99 actionNeedRoot(args
.action
)
100 helpers
.lxc
.logcat(args
)
101 elif args
.action
== "show-full-ui":
102 actions
.app_manager
.showFullUI(args
)
103 elif args
.action
== "status":
104 actions
.status
.print_status(args
)
105 elif args
.action
== "log":
107 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
109 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
111 logging
.info("Run waydroid -h for usage information.")
113 #logging.info("Done")
115 except Exception as e
:
116 # Dump log to stdout when args (and therefore logging) init failed
118 logging
.getLogger().setLevel(logging
.DEBUG
)
120 logging
.info("ERROR: " + str(e
))
121 logging
.info("See also: <https://github.com/waydroid>")
122 logging
.debug(traceback
.format_exc())
124 # Hints about the log file (print to stdout only)
125 log_hint
= "Run 'waydroid log' for details."
126 if not args
or not os
.path
.exists(args
.log
):
127 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
128 " get more output, e.g. 'waydroid"
129 " --details-to-stdout init'.")
134 if __name__
== "__main__":