]>
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 os
.path
.isfile(args
.config
):
35 if args
.action
and (args
.action
!= "init" and args
.action
!= "log"):
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 # This branch is taken if:
43 # - waydroid is not yet initialized
44 # - waydroid is invoked with no command or with log
45 if not os
.path
.exists(args
.log
):
46 # The log could have been already created if init was used and failed, if its not the case we use a temporary one
47 args
.log
= "/tmp/tools.log"
49 tools_logging
.init(args
)
51 # Initialize or require config
52 if args
.action
== "init":
53 actionNeedRoot(args
.action
)
55 elif args
.action
== "upgrade":
56 actionNeedRoot(args
.action
)
58 elif args
.action
== "session":
59 if args
.subaction
== "start":
60 actions
.session_manager
.start(args
)
61 elif args
.subaction
== "stop":
62 actions
.session_manager
.stop(args
)
65 "Run waydroid {} -h for usage information.".format(args
.action
))
66 elif args
.action
== "container":
67 actionNeedRoot(args
.action
)
68 if args
.subaction
== "start":
69 actions
.container_manager
.start(args
)
70 elif args
.subaction
== "stop":
71 actions
.container_manager
.stop(args
)
72 elif args
.subaction
== "restart":
73 actions
.container_manager
.restart(args
)
74 elif args
.subaction
== "freeze":
75 actions
.container_manager
.freeze(args
)
76 elif args
.subaction
== "unfreeze":
77 actions
.container_manager
.unfreeze(args
)
80 "Run waydroid {} -h for usage information.".format(args
.action
))
81 elif args
.action
== "app":
82 if args
.subaction
== "install":
83 actions
.app_manager
.install(args
)
84 elif args
.subaction
== "remove":
85 actions
.app_manager
.remove(args
)
86 elif args
.subaction
== "launch":
87 actions
.app_manager
.launch(args
)
88 elif args
.subaction
== "list":
89 actions
.app_manager
.list(args
)
92 "Run waydroid {} -h for usage information.".format(args
.action
))
93 elif args
.action
== "prop":
94 if args
.subaction
== "get":
95 ret
= helpers
.props
.get(args
, args
.key
)
98 elif args
.subaction
== "set":
99 helpers
.props
.set(args
, args
.key
, args
.value
)
102 "Run waydroid {} -h for usage information.".format(args
.action
))
103 elif args
.action
== "shell":
104 actionNeedRoot(args
.action
)
105 helpers
.lxc
.shell(args
)
106 elif args
.action
== "logcat":
107 actionNeedRoot(args
.action
)
108 helpers
.lxc
.logcat(args
)
109 elif args
.action
== "show-full-ui":
110 actions
.app_manager
.showFullUI(args
)
111 elif args
.action
== "status":
112 actions
.status
.print_status(args
)
113 elif args
.action
== "log":
115 helpers
.run
.user(args
, ["truncate", "-s", "0", args
.log
])
118 args
, ["tail", "-n", args
.lines
, "-F", args
.log
], output
="tui")
119 except KeyboardInterrupt:
122 logging
.info("Run waydroid -h for usage information.")
124 #logging.info("Done")
126 except Exception as e
:
127 # Dump log to stdout when args (and therefore logging) init failed
129 logging
.getLogger().setLevel(logging
.DEBUG
)
131 logging
.info("ERROR: " + str(e
))
132 logging
.info("See also: <https://github.com/waydroid>")
133 logging
.debug(traceback
.format_exc())
135 # Hints about the log file (print to stdout only)
136 log_hint
= "Run 'waydroid log' for details."
137 if not args
or not os
.path
.exists(args
.log
):
138 log_hint
+= (" Alternatively you can use '--details-to-stdout' to"
139 " get more output, e.g. 'waydroid"
140 " --details-to-stdout init'.")
145 if __name__
== "__main__":