]>
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":
39 if not os
.path
.exists(args
.work
):
42 args
.log
= "/tmp/tools.log"
44 tools_logging
.init(args
)
46 # Initialize or require config
47 if args
.action
== "init":
48 actionNeedRoot(args
.action
)
50 elif args
.action
== "upgrade":
51 actionNeedRoot(args
.action
)
53 elif args
.action
== "session":
54 if args
.subaction
== "start":
55 actions
.session_manager
.start(args
)
56 elif args
.subaction
== "stop":
57 actions
.session_manager
.stop(args
)
60 "Run waydroid {} -h for usage information.".format(args
.action
))
61 elif args
.action
== "container":
62 actionNeedRoot(args
.action
)
63 if args
.subaction
== "start":
64 actions
.container_manager
.start(args
)
65 elif args
.subaction
== "stop":
66 actions
.container_manager
.stop(args
)
67 elif args
.subaction
== "restart":
68 actions
.container_manager
.restart(args
)
69 elif args
.subaction
== "freeze":
70 actions
.container_manager
.freeze(args
)
71 elif args
.subaction
== "unfreeze":
72 actions
.container_manager
.unfreeze(args
)
75 "Run waydroid {} -h for usage information.".format(args
.action
))
76 elif args
.action
== "app":
77 if args
.subaction
== "install":
78 actions
.app_manager
.install(args
)
79 elif args
.subaction
== "remove":
80 actions
.app_manager
.remove(args
)
81 elif args
.subaction
== "launch":
82 actions
.app_manager
.launch(args
)
83 elif args
.subaction
== "list":
84 actions
.app_manager
.list(args
)
87 "Run waydroid {} -h for usage information.".format(args
.action
))
88 elif args
.action
== "prop":
89 if args
.subaction
== "get":
90 ret
= helpers
.props
.get(args
, args
.key
)
93 elif args
.subaction
== "set":
94 helpers
.props
.set(args
, args
.key
, args
.value
)
97 "Run waydroid {} -h for usage information.".format(args
.action
))
98 elif args
.action
== "shell":
99 actionNeedRoot(args
.action
)
100 helpers
.lxc
.shell(args
)
101 elif args
.action
== "logcat":
102 actionNeedRoot(args
.action
)
103 helpers
.lxc
.logcat(args
)
104 elif args
.action
== "show-full-ui":
105 actions
.app_manager
.showFullUI(args
)
106 elif args
.action
== "status":
107 actions
.status
.print_status(args
)
108 elif args
.action
== "log":
110 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
112 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
114 logging
.info("Run waydroid -h for usage information.")
116 #logging.info("Done")
118 except Exception as e
:
119 # Dump log to stdout when args (and therefore logging) init failed
121 logging
.getLogger().setLevel(logging
.DEBUG
)
123 logging
.info("ERROR: " + str(e
))
124 logging
.info("See also: <https://github.com/waydroid>")
125 logging
.debug(traceback
.format_exc())
127 # Hints about the log file (print to stdout only)
128 log_hint
= "Run 'waydroid log' for details."
129 if not args
or not os
.path
.exists(args
.log
):
130 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
131 " get more output, e.g. 'waydroid"
132 " --details-to-stdout init'.")
137 if __name__
== "__main__":