-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
211 lines (163 loc) · 7.96 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"""
cli.py
Command line interface definitions using 'argparse' Python core library.
"""
import argparse
import actions
class Cli(object):
"""
Cli class.
Defines parser attributes and usage logic.
"""
def __init__(self):
self.basic_parser = None
self.build_parser = None
self.download_parser = None
self.xml_parser = None
def configure_basic_parser(self):
"""
Parser options for the 'lfsbuilder.py' main script.
"""
self.basic_parser = argparse.ArgumentParser()
# description = "LFSBuilder")
# usage = """lfsbuilder.py [<options>] <command> [<args>]
# Options:
# Commands:
# build Build specified builders
# parse Generate XML commands file for specified builder
# download Download
# """)
# Arguments definition
# .- verbose
self.basic_parser.add_argument("-v", "--verbose",
help="Output verbose messages",
action="store_true")
# .- debug scripts
self.basic_parser.add_argument("--debug-scripts",
help="Debug scripts when running",
action="store_true")
# .- base directory
self.basic_parser.add_argument("--base-directory",
help="Set base directory",
action=actions.SetConfigOption)
# .- non privileged username
self.basic_parser.add_argument("--non-privileged-username",
help="Set non privileged username",
action=actions.SetConfigOption)
# .- sources orig directory
self.basic_parser.add_argument("--sources-orig-directory",
help="Set origin directory for sources",
action=actions.SetConfigOption)
# .- makeflags
self.basic_parser.add_argument("--makeflags",
help="Set MAKEFLAGS value",
action=actions.SetConfigOption)
# .- restore XML backups file
self.basic_parser.add_argument("--restore-xml-backups",
help="Restore XML backups files",
action=actions.SetConfigOption)
# .- timezone
self.basic_parser.add_argument("--lfs-version",
help="Version of the book",
action=actions.SetConfigOption)
# .- command. Save all the arguments starting from the command name until
# the end of the 'argv' values into a list
self.basic_parser.add_argument("command",
help="Subcommand to run",
choices=['build', 'download', 'parse'],
nargs=argparse.REMAINDER)
# Return configured parser
return self.basic_parser
def configure_build_parser(self):
"""
Parser options for the 'build' command.
"""
self.build_parser = argparse.ArgumentParser(description="Build specified builders")
# Arguments definition
# .- generate-img-file
group_gen_img_file = self.build_parser.add_mutually_exclusive_group()
group_gen_img_file.add_argument("--generate-img-file",
action="store_true")
group_gen_img_file.add_argument("--no-generate-img-file",
action="store_true")
# .- no mount sources
group_mount_sources = self.build_parser.add_mutually_exclusive_group()
group_mount_sources.add_argument("--mount-sources",
action="store_true")
group_mount_sources.add_argument("--no-mount-sources",
action="store_true")
# .- mount-img-file
group_mount_img_file = self.build_parser.add_mutually_exclusive_group()
group_mount_img_file.add_argument("--mount-img-file",
action="store_true")
group_mount_img_file.add_argument("--no-mount-img-file",
action="store_true")
# .- builders list
self.build_parser.add_argument("builders_list",
action=actions.ModifyBuildersList,
nargs=argparse.REMAINDER)
# .- mount-system-directories
group_mount_system_dir = self.build_parser.add_mutually_exclusive_group()
group_mount_system_dir.add_argument("--mount-system-directories",
action="store_true")
group_mount_system_dir.add_argument("--no-mount-system-directories",
action="store_true")
# .- generate data files
group_data_files = self.build_parser.add_mutually_exclusive_group()
group_data_files.add_argument("--generate-data-files",
action="store_true")
group_data_files.add_argument("--no-generate-data-files",
action="store_true")
# .- boot_manager
group_boot_manager = self.build_parser.add_mutually_exclusive_group()
group_boot_manager.add_argument("--sysv",
action="store_true")
group_boot_manager.add_argument("--systemd",
action="store_true")
# .- meson builder
group_meson_builder = self.build_parser.add_mutually_exclusive_group()
group_meson_builder.add_argument("--include-meson-builder",
action="store_true")
group_meson_builder.add_argument("--no-include-meson-builder",
action="store_true")
# .- continue-at
self.build_parser.add_argument("--continue-at",
action=actions.SetConfigOption)
# .- save toolchain
group_save_toolchain = self.build_parser.add_mutually_exclusive_group()
group_save_toolchain.add_argument("--save-toolchain",
action="store_true")
group_save_toolchain.add_argument("--no-save-toolchain",
action="store_true")
# .- delete tools
group_delete_tools = self.build_parser.add_mutually_exclusive_group()
group_delete_tools.add_argument("--delete-tools",
action="store_true")
group_delete_tools.add_argument("--no-delete-tools",
action="store_true")
# Return configured parser
return self.build_parser
def configure_download_parser(self):
"""
Parser options for the 'download' command.
"""
# Parse command line arguments
self.download_parser = argparse.ArgumentParser(description="Download XML and sources")
# Arguments
self.download_parser.add_argument("--sources",
action="store_true")
self.download_parser.add_argument("--xml",
action="store_true")
self.download_parser.add_argument("--lfs-version",
action=actions.SetConfigOption)
self.download_parser.add_argument("book_name")
# Return configured parser
return self.download_parser
def configure_xml_parser(self):
"""
Parser options form the 'parse' command.
"""
# 'build_parser' already has the required config
self.xml_parser = self.configure_build_parser()
# Return configured parser
return self.xml_parser