]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/arguments.py
arch: Separately identify arm64_only CPUs without AArch32 support
[waydroid.git] / tools / helpers / arguments.py
1 # Copyright 2021 Oliver Smith
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import argparse
4
5 try:
6 import argcomplete
7 except ImportError:
8 argcomplete = False
9
10 import tools.config
11
12 """ This file is about parsing command line arguments passed to waydroid, as
13 well as generating the help pages (waydroid -h). All this is done with
14 Python's argparse. The parsed arguments get extended and finally stored in
15 the "args" variable, which is prominently passed to most functions all
16 over the waydroid code base.
17
18 See tools/helpers/args.py for more information about the args variable. """
19
20 def arguments_init(subparser):
21 ret = subparser.add_parser("init", help="set up waydroid specific"
22 " configs and install images")
23 ret.add_argument("-i", "--images_path",
24 help="custom path to waydroid images (default in"
25 " /var/lib/waydroid/images)")
26 ret.add_argument("-f", "--force", action="store_true",
27 help="re-initialize configs and images")
28 ret.add_argument("-c", "--system_channel",
29 help="custom system channel (options: OTA channel URL; default is Official OTA server)")
30 ret.add_argument("-v", "--vendor_channel",
31 help="custom vendor channel (options: OTA channel URL; default is Official OTA server)")
32 ret.add_argument("-r", "--rom_type",
33 help="rom type (options: \"lineage\", \"bliss\" or OTA channel URL; default is LineageOS)")
34 ret.add_argument("-s", "--system_type",
35 help="system type (options: VANILLA, FOSS or GAPPS; default is VANILLA)")
36 return ret
37
38 def arguments_status(subparser):
39 ret = subparser.add_parser("status",
40 help="quick check for the waydroid")
41 return ret
42
43 def arguments_upgrade(subparser):
44 ret = subparser.add_parser("upgrade", help="upgrade images")
45 ret.add_argument("-o", "--offline", action="store_true",
46 help="just for updating configs")
47 return ret
48
49 def arguments_log(subparser):
50 ret = subparser.add_parser("log", help="follow the waydroid logfile")
51 ret.add_argument("-n", "--lines", default="60",
52 help="count of initial output lines")
53 ret.add_argument("-c", "--clear", help="clear the log",
54 action="store_true", dest="clear_log")
55 return ret
56
57 def arguments_session(subparser):
58 ret = subparser.add_parser("session", help="session controller")
59 sub = ret.add_subparsers(title="subaction", dest="subaction")
60 sub.add_parser("start", help="start session")
61 sub.add_parser("stop", help="stop session")
62 return ret
63
64 def arguments_container(subparser):
65 ret = subparser.add_parser("container", help="container controller")
66 sub = ret.add_subparsers(title="subaction", dest="subaction")
67 sub.add_parser("start", help="start container")
68 sub.add_parser("stop", help="stop container")
69 sub.add_parser("restart", help="restart container")
70 sub.add_parser("freeze", help="freeze container")
71 sub.add_parser("unfreeze", help="unfreeze container")
72 return ret
73
74 def arguments_app(subparser):
75 ret = subparser.add_parser("app", help="applications controller")
76 sub = ret.add_subparsers(title="subaction", dest="subaction")
77 install = sub.add_parser(
78 "install", help="push a single package to the container and install it")
79 install.add_argument('PACKAGE', help="path to apk file")
80 remove = sub.add_parser(
81 "remove", help="remove single app package from the container")
82 remove.add_argument('PACKAGE', help="package name of app to remove")
83 launch = sub.add_parser("launch", help="start single application")
84 launch.add_argument('PACKAGE', help="package name of app to launch")
85 intent = sub.add_parser("intent", help="start single application")
86 intent.add_argument('ACTION', help="action name")
87 intent.add_argument('URI', help="data uri")
88 sub.add_parser("list", help="list installed applications")
89 return ret
90
91 def arguments_prop(subparser):
92 ret = subparser.add_parser("prop", help="android properties controller")
93 sub = ret.add_subparsers(title="subaction", dest="subaction")
94 get = sub.add_parser(
95 "get", help="get value of property from container")
96 get.add_argument('key', help="key of the property to get")
97 set = sub.add_parser(
98 "set", help="set value to property on container")
99 set.add_argument('key', help="key of the property to set")
100 set.add_argument('value', help="value of the property to set")
101 return ret
102
103 def arguments_fullUI(subparser):
104 ret = subparser.add_parser("show-full-ui", help="show android full screen in window")
105 return ret
106
107 def arguments_firstLaunch(subparser):
108 ret = subparser.add_parser("first-launch", help="initialize waydroid and start it")
109 return ret
110
111 def arguments_shell(subparser):
112 ret = subparser.add_parser("shell", help="run remote shell command")
113 ret.add_argument("-u", "--uid", help="the UID to run as (also sets GID to the same value if -g is not set)")
114 ret.add_argument("-g", "--gid", help="the GID to run as")
115 ret.add_argument("-s", "--context", help="transition to the specified SELinux or AppArmor security context. No-op if -L is supplied.")
116 ret.add_argument("-L", "--nolsm", action="store_true", help="tell LXC not to perform security domain transition related to mandatory access control (e.g. SELinux, AppArmor). If this option is supplied, LXC won't apply a container-wide seccomp filter to the executed program. This is a dangerous option that can result in leaking privileges to the container!!!")
117 ret.add_argument("-C", "--allcaps", action="store_true", help="tell LXC not to drop capabilities. This is a dangerous option that can result in leaking privileges to the container!!!")
118 ret.add_argument("-G", "--nocgroup", action="store_true", help="tell LXC not to switch to the container cgroup. This is a dangerous option that can result in leaking privileges to the container!!!")
119 ret.add_argument('COMMAND', nargs='*', help="command to run")
120 return ret
121
122 def arguments_logcat(subparser):
123 ret = subparser.add_parser("logcat", help="show android logcat")
124 return ret
125
126 def arguments():
127 parser = argparse.ArgumentParser(prog="waydroid")
128
129 # Other
130 parser.add_argument("-V", "--version", action="version",
131 version=tools.config.version)
132
133 # Logging
134 parser.add_argument("-l", "--log", dest="log", default=None,
135 help="path to log file")
136 parser.add_argument("--details-to-stdout", dest="details_to_stdout",
137 help="print details (e.g. build output) to stdout,"
138 " instead of writing to the log",
139 action="store_true")
140 parser.add_argument("-v", "--verbose", dest="verbose",
141 action="store_true", help="write even more to the"
142 " logfiles (this may reduce performance)")
143 parser.add_argument("-q", "--quiet", dest="quiet", action="store_true",
144 help="do not output any log messages")
145 parser.add_argument("-w", "--wait", dest="wait_for_init", action="store_true",
146 help="wait for init before running")
147
148 # Actions
149 sub = parser.add_subparsers(title="action", dest="action")
150
151 arguments_status(sub)
152 arguments_log(sub)
153 arguments_init(sub)
154 arguments_upgrade(sub)
155 arguments_session(sub)
156 arguments_container(sub)
157 arguments_app(sub)
158 arguments_prop(sub)
159 arguments_fullUI(sub)
160 arguments_firstLaunch(sub)
161 arguments_shell(sub)
162 arguments_logcat(sub)
163
164 if argcomplete:
165 argcomplete.autocomplete(parser, always_complete_options="long")
166
167 # Parse and extend arguments (also backup unmodified result from argparse)
168 args = parser.parse_args()
169 return args