Merge ~alexmurray/ubuntu-security-tools:umt-argparse into ubuntu-security-tools:master
- Git
- lp:~alexmurray/ubuntu-security-tools
- umt-argparse
- Merge into master
Proposed by
Alex Murray
Status: | Merged |
---|---|
Merged at revision: | ea1c49b769e572fc1ce6dcd463e1287df9564ca1 |
Proposed branch: | ~alexmurray/ubuntu-security-tools:umt-argparse |
Merge into: | ubuntu-security-tools:master |
Diff against target: |
992 lines (+368/-369) 1 file modified
build-tools/umt (+368/-369) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Steve Beattie | Pending | ||
Review via email: mp+407579@code.launchpad.net |
Commit message
Description of the change
Convert umt to use argparse instead of optparse and then use this to validate QRT backends for umt qrt (as suggested by sbeattie in https:/
To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/build-tools/umt b/build-tools/umt |
2 | index d347cb3..01421af 100755 |
3 | --- a/build-tools/umt |
4 | +++ b/build-tools/umt |
5 | @@ -19,7 +19,7 @@ uct_path = os.getenv("UCT") |
6 | if uct_path is not None: |
7 | sys.path.append(os.path.join(uct_path, "scripts")) |
8 | import source_map |
9 | -import re, optparse, subprocess, tempfile, glob, shutil, collections |
10 | +import re, argparse, subprocess, tempfile, glob, shutil, collections |
11 | import resource |
12 | import requests |
13 | import time |
14 | @@ -235,27 +235,27 @@ def success(msg): |
15 | def cmd_download(): |
16 | '''Get source packages and unpack in proper tree''' |
17 | |
18 | - parser = umt_optparse("usage: %prog download [options] package [package ...]") |
19 | + parser = umt_argparse("usage: %(prog)s download [options] package [package ...]") |
20 | |
21 | - parser.add_option("-r", "--releases", dest="releases", default=None, metavar="REL,REL,...", |
22 | - help="comma separated list of releases to download (Default: All)") |
23 | + parser.add_argument("-r", "--releases", dest="releases", default=None, metavar="REL,REL,...", |
24 | + help="comma separated list of releases to download (Default: All)") |
25 | |
26 | - parser.add_option("-d", "--devel", dest="devel", default=False, action='store_true', |
27 | - help="Also download source package for development release") |
28 | + parser.add_argument("-d", "--devel", dest="devel", default=False, action='store_true', |
29 | + help="Also download source package for development release") |
30 | |
31 | - parser.add_option("--debug", default=False, action='store_true', |
32 | - help="Report additional debug details before and after download") |
33 | + parser.add_argument("--debug", default=False, action='store_true', |
34 | + help="Report additional debug details before and after download") |
35 | |
36 | - parser.add_option("-f", "--force", dest="force", default=False, action='store_true', |
37 | - help="Force overwriting existing directories.") |
38 | + parser.add_argument("-f", "--force", dest="force", default=False, action='store_true', |
39 | + help="Force overwriting existing directories.") |
40 | |
41 | - parser.add_option("-p", "--proposed", dest="proposed", default=False, action='store_true', |
42 | - help="include -proposed packages in downloads") |
43 | + parser.add_argument("-p", "--proposed", dest="proposed", default=False, action='store_true', |
44 | + help="include -proposed packages in downloads") |
45 | |
46 | - parser.add_option("-b", "--backports", dest="backports", default=False, action='store_true', |
47 | - help="include -backports packages in downloads") |
48 | + parser.add_argument("-b", "--backports", dest="backports", default=False, action='store_true', |
49 | + help="include -backports packages in downloads") |
50 | |
51 | - (opt, args) = parser.parse_args() |
52 | + (opt, args) = parser.parse_known_args() |
53 | |
54 | if len(args) == 0: |
55 | err("Need to specify the source package.\n") |
56 | @@ -281,24 +281,24 @@ def cmd_download(): |
57 | def cmd_changelog(): |
58 | '''sdch-like new entry creation or extraction of changelog from prior release (dch-repeat-like)''' |
59 | |
60 | - parser = umt_optparse("usage: %prog changelog [options]") |
61 | - |
62 | - parser.add_option("-i", "--increment", dest="increment", default=None, metavar="VERSION", |
63 | - help="Print an incremented version for the provided string") |
64 | - parser.add_option("-r", "--repeat", dest="repeat", default=False, action='store_true', |
65 | - help="Repeat the changelog from one distro release newer") |
66 | - parser.add_option("--release", dest="release", default=None, action='store', |
67 | - help="Repeat the changelog from specific release") |
68 | - parser.add_option("--build", default=False, action='store_true', |
69 | - help="Use 'build*'-style versioning") |
70 | - parser.add_option("--note", action='store', metavar='NOTE', |
71 | - help="Use NOTE as changelog item entry, instead of using interactive 'dch'") |
72 | - parser.add_option("--esm", default=False, action='store_true', |
73 | - help="Generate changelog for ESM") |
74 | - parser.add_option("-t", "--template", dest="template", default=False, action='store_true', |
75 | - help="Fulfill changelog using security template") |
76 | - |
77 | - (opt, args) = parser.parse_args() |
78 | + parser = umt_argparse("usage: %(prog)s changelog [options]") |
79 | + |
80 | + parser.add_argument("-i", "--increment", dest="increment", default=None, metavar="VERSION", |
81 | + help="Print an incremented version for the provided string") |
82 | + parser.add_argument("-r", "--repeat", dest="repeat", default=False, action='store_true', |
83 | + help="Repeat the changelog from one distro release newer") |
84 | + parser.add_argument("--release", dest="release", default=None, action='store', |
85 | + help="Repeat the changelog from specific release") |
86 | + parser.add_argument("--build", default=False, action='store_true', |
87 | + help="Use 'build*'-style versioning") |
88 | + parser.add_argument("--note", action='store', metavar='NOTE', |
89 | + help="Use NOTE as changelog item entry, instead of using interactive 'dch'") |
90 | + parser.add_argument("--esm", default=False, action='store_true', |
91 | + help="Generate changelog for ESM") |
92 | + parser.add_argument("-t", "--template", dest="template", default=False, action='store_true', |
93 | + help="Fulfill changelog using security template") |
94 | + |
95 | + (opt, args) = parser.parse_known_args() |
96 | |
97 | repeat_note = "" |
98 | release = None |
99 | @@ -443,15 +443,15 @@ def prepare_build(opt): |
100 | def cmd_source(): |
101 | '''Produces source package from current directory of unpacked source''' |
102 | |
103 | - parser = umt_optparse("usage: %prog source [options]") |
104 | + parser = umt_argparse("usage: %(prog)s source [options]") |
105 | |
106 | add_common_build_opts(parser) |
107 | - parser.add_option("-v", "--start-version", dest="start_version", default="", metavar="VERSION", |
108 | - help="Use changelog information from all versions strictly later VERSION (use -vVERSION)") |
109 | + parser.add_argument("-v", "--start-version", dest="start_version", default="", metavar="VERSION", |
110 | + help="Use changelog information from all versions strictly later VERSION (use -vVERSION)") |
111 | |
112 | add_source_build_opts(parser) |
113 | |
114 | - (opt, args) = parser.parse_args() |
115 | + (opt, args) = parser.parse_known_args() |
116 | if opt.force_sa and opt.force_sd: |
117 | err("Cannot specify both --force-orig and --force-no-orig. Aborting.") |
118 | sys.exit(1) |
119 | @@ -531,12 +531,12 @@ def perform_source_build(details, opt): |
120 | def cmd_binary(): |
121 | '''Produces binary packages and other outputs from ../source source bits''' |
122 | |
123 | - parser = umt_optparse("usage: %prog binary [options]") |
124 | + parser = umt_argparse("usage: %(prog)s binary [options]") |
125 | |
126 | add_common_build_opts(parser) |
127 | add_binary_build_opts(parser) |
128 | |
129 | - (opt, args) = parser.parse_args() |
130 | + (opt, args) = parser.parse_known_args() |
131 | |
132 | details = prepare_build(opt) |
133 | perform_binary_build(details, opt) |
134 | @@ -643,16 +643,16 @@ def perform_binary_build(details, opt): |
135 | def cmd_build(): |
136 | '''Do both source and binary commands''' |
137 | |
138 | - parser = umt_optparse("usage: %prog build [options]") |
139 | + parser = umt_argparse("usage: %(prog)s build [options]") |
140 | |
141 | add_common_build_opts(parser) |
142 | - parser.add_option("-v", "--start-version", dest="start_version", default="", metavar="VERSION", |
143 | - help="Use changelog information from all versions strictly later VERSION (use -vVERSION)") |
144 | + parser.add_argument("-v", "--start-version", dest="start_version", default="", metavar="VERSION", |
145 | + help="Use changelog information from all versions strictly later VERSION (use -vVERSION)") |
146 | |
147 | add_source_build_opts(parser) |
148 | add_binary_build_opts(parser) |
149 | |
150 | - (opt, args) = parser.parse_args() |
151 | + (opt, args) = parser.parse_known_args() |
152 | |
153 | details = prepare_build(opt) |
154 | perform_source_build(details, opt) |
155 | @@ -661,20 +661,20 @@ def cmd_build(): |
156 | def cmd_build_orig(): |
157 | '''Build binaries of the previous package version''' |
158 | |
159 | - parser = umt_optparse("usage: %prog build-orig [options]") |
160 | + parser = umt_argparse("usage: %(prog)s build-orig [options]") |
161 | |
162 | add_common_build_opts(parser) |
163 | - parser.add_option("--start-version", dest="start_version", default="", metavar="VERSION", |
164 | - help="Use changelog information from all versions strictly later VERSION (use -vVERSION)") |
165 | + parser.add_argument("--start-version", dest="start_version", default="", metavar="VERSION", |
166 | + help="Use changelog information from all versions strictly later VERSION (use -vVERSION)") |
167 | add_source_build_opts(parser) |
168 | add_binary_build_opts(parser) |
169 | |
170 | - parser.add_option("-l", "--leave", dest="leave", default=False, action='store_true', |
171 | - help="leave previous version build directory in place") |
172 | - parser.add_option("-v", "--previous-version", dest="previous_version", default=None, metavar="VERSION", |
173 | - help="build specified version") |
174 | + parser.add_argument("-l", "--leave", dest="leave", default=False, action='store_true', |
175 | + help="leave previous version build directory in place") |
176 | + parser.add_argument("-v", "--previous-version", dest="previous_version", default=None, metavar="VERSION", |
177 | + help="build specified version") |
178 | |
179 | - (opt, args) = parser.parse_args() |
180 | + (opt, args) = parser.parse_known_args() |
181 | |
182 | details = prepare_build(opt) |
183 | |
184 | @@ -729,15 +729,15 @@ def cmd_build_orig(): |
185 | def cmd_sign(): |
186 | '''Sign the packages''' |
187 | |
188 | - parser = umt_optparse("usage: %prog sign [options]") |
189 | + parser = umt_argparse("usage: %(prog)s sign [options]") |
190 | |
191 | - parser.add_option("-f", "--file", dest="file", default=None, metavar="CHANGES_FILE", |
192 | - help="specify a changes file to sign") |
193 | + parser.add_argument("-f", "--file", dest="file", default=None, metavar="CHANGES_FILE", |
194 | + help="specify a changes file to sign") |
195 | |
196 | - parser.add_option("-k", "--key", dest="key", default=False, action='store_true', |
197 | - help="sign packages with your own key") |
198 | + parser.add_argument("-k", "--key", dest="key", default=False, action='store_true', |
199 | + help="sign packages with your own key") |
200 | |
201 | - (opt, args) = parser.parse_args() |
202 | + (opt, args) = parser.parse_known_args() |
203 | |
204 | if opt.file: |
205 | changes_file = opt.file |
206 | @@ -802,30 +802,30 @@ def cmd_read(): |
207 | def cmd_check(): |
208 | '''Do a check-source-package''' |
209 | check_type = [] |
210 | - parser = umt_optparse("usage: %prog check [options] [-- [check-source-package options]]") |
211 | + parser = umt_argparse("usage: %(prog)s check [options] [-- [check-source-package options]]") |
212 | |
213 | - parser.add_option("-s", dest="check_type", action='append_const', const='-s', |
214 | - help="security upload") |
215 | + parser.add_argument("-s", dest="check_type", action='append_const', const='-s', |
216 | + help="security upload") |
217 | |
218 | - parser.add_option("-S", dest="check_type", action='append_const', const='-S', |
219 | - help="sponsored security upload") |
220 | + parser.add_argument("-S", dest="check_type", action='append_const', const='-S', |
221 | + help="sponsored security upload") |
222 | |
223 | - parser.add_option("-m", dest="check_type", action='append_const', const='-m', |
224 | - help="maintainer upload") |
225 | + parser.add_argument("-m", dest="check_type", action='append_const', const='-m', |
226 | + help="maintainer upload") |
227 | |
228 | - parser.add_option("-M", dest="check_type", action='append_const', const='-M', |
229 | - help="sponsored maintainer upload") |
230 | + parser.add_argument("-M", dest="check_type", action='append_const', const='-M', |
231 | + help="sponsored maintainer upload") |
232 | |
233 | - parser.add_option("-f", "--file", dest="file", default=None, metavar="DSC_FILE", |
234 | - help="specify a dsc file to check") |
235 | - parser.add_option("-b", "--binary-dir", dest="binary_dir", default=None, metavar="BINARY_DIR", |
236 | - help="specify the directory containing the binaries") |
237 | + parser.add_argument("-f", "--file", dest="file", default=None, metavar="DSC_FILE", |
238 | + help="specify a dsc file to check") |
239 | + parser.add_argument("-b", "--binary-dir", dest="binary_dir", default=None, metavar="BINARY_DIR", |
240 | + help="specify the directory containing the binaries") |
241 | |
242 | - parser.add_option("-A", "--add-extra-checks", dest="extra_checks", default=False, action='store_true', |
243 | - help="perform extra checks on the package") |
244 | + parser.add_argument("-A", "--add-extra-checks", dest="extra_checks", default=False, action='store_true', |
245 | + help="perform extra checks on the package") |
246 | |
247 | |
248 | - (opt, args) = parser.parse_args() |
249 | + (opt, args) = parser.parse_known_args() |
250 | |
251 | if opt.check_type: |
252 | check_type = opt.check_type |
253 | @@ -944,25 +944,25 @@ def find_build_log(pkg, ver, arch): |
254 | |
255 | def cmd_compare_log(): |
256 | '''Compare build log with prior version''' |
257 | - parser = umt_optparse("usage: %prog compare-log [options]") |
258 | - parser.add_option("-b", "--balance", dest="balance", default=False, action='store_true', |
259 | - help="try and balance out +/- lines in diff chunks") |
260 | - parser.add_option("--deparallel", dest="deparallel", |
261 | - default=False, action='store_true', |
262 | - help="Deparallelize the build log (experimental)") |
263 | - parser.add_option("-v", "--previous-version", dest="previous_version", |
264 | - default=False, metavar="PREVIOUS", |
265 | - help="compare against previous version") |
266 | - parser.add_option("--stdout", dest="dump_to_stdout", |
267 | - default=False, action='store_true', |
268 | - help="dump to stdout instead of displaying in an editor") |
269 | - parser.add_option("-a", "--arch", dest="arch", |
270 | - default=False, metavar="ARCH", |
271 | - help="only compare logs of specific architecture") |
272 | - parser.add_option("-p", "--previous-logfile", dest="previous_logfile", |
273 | - default=None, metavar="PREVIOUS_LOGFILE", |
274 | - help="Compare against the specified log file as the previous build") |
275 | - (opt, args) = parser.parse_args() |
276 | + parser = umt_argparse("usage: %(prog)s compare-log [options]") |
277 | + parser.add_argument("-b", "--balance", dest="balance", default=False, action='store_true', |
278 | + help="try and balance out +/- lines in diff chunks") |
279 | + parser.add_argument("--deparallel", dest="deparallel", |
280 | + default=False, action='store_true', |
281 | + help="Deparallelize the build log (experimental)") |
282 | + parser.add_argument("-v", "--previous-version", dest="previous_version", |
283 | + default=False, metavar="PREVIOUS", |
284 | + help="compare against previous version") |
285 | + parser.add_argument("--stdout", dest="dump_to_stdout", |
286 | + default=False, action='store_true', |
287 | + help="dump to stdout instead of displaying in an editor") |
288 | + parser.add_argument("-a", "--arch", dest="arch", |
289 | + default=False, metavar="ARCH", |
290 | + help="only compare logs of specific architecture") |
291 | + parser.add_argument("-p", "--previous-logfile", dest="previous_logfile", |
292 | + default=None, metavar="PREVIOUS_LOGFILE", |
293 | + help="Compare against the specified log file as the previous build") |
294 | + (opt, args) = parser.parse_known_args() |
295 | |
296 | # Basically, a pythonification of u-log-compare... |
297 | |
298 | @@ -1376,52 +1376,52 @@ Acquire::Languages "none"; |
299 | |
300 | return BinaryPackages(binaries, pkg_versions) |
301 | |
302 | - parser = umt_optparse("usage: %prog compare-bin [options]") |
303 | - parser.add_option("-v", "--previous-version", dest="previous_version", |
304 | - default=False, metavar="PREVIOUS", |
305 | - help="compare against previous version") |
306 | + parser = umt_argparse("usage: %(prog)s compare-bin [options]") |
307 | + parser.add_argument("-v", "--previous-version", dest="previous_version", |
308 | + default=False, metavar="PREVIOUS", |
309 | + help="compare against previous version") |
310 | |
311 | - parser.add_option("-P", "--proposed", dest="proposed", |
312 | - default=False, action='store_true', |
313 | - help="look for previous version in -proposed") |
314 | + parser.add_argument("-P", "--proposed", dest="proposed", |
315 | + default=False, action='store_true', |
316 | + help="look for previous version in -proposed") |
317 | |
318 | - parser.add_option("-a", "--arch", dest="arch", |
319 | - default=False, metavar="ARCH", |
320 | - help="use debs for specified architecture") |
321 | + parser.add_argument("-a", "--arch", dest="arch", |
322 | + default=False, metavar="ARCH", |
323 | + help="use debs for specified architecture") |
324 | |
325 | - parser.add_option("-r", "--release", dest="release", |
326 | - default=False, metavar="RELEASE", |
327 | - help="old version repository to compare to") |
328 | + parser.add_argument("-r", "--release", dest="release", |
329 | + default=False, metavar="RELEASE", |
330 | + help="old version repository to compare to") |
331 | |
332 | - parser.add_option("-f", "--force", dest="force", default=False, |
333 | - action='store_true', |
334 | - help="force deletion of ../reports") |
335 | + parser.add_argument("-f", "--force", dest="force", default=False, |
336 | + action='store_true', |
337 | + help="force deletion of ../reports") |
338 | |
339 | - parser.add_option("-l", "--legacy", dest="legacy", default=False, |
340 | - action='store_true', |
341 | - help="use legacy version of debcompare") |
342 | + parser.add_argument("-l", "--legacy", dest="legacy", default=False, |
343 | + action='store_true', |
344 | + help="use legacy version of debcompare") |
345 | |
346 | - parser.add_option("--ppa", dest="ppa", default=False, |
347 | - metavar="PPA (eg ubuntu-security/ppa)", |
348 | - help="fetch new binaries from PPA (requires UCT)") |
349 | + parser.add_argument("--ppa", dest="ppa", default=False, |
350 | + metavar="PPA (eg ubuntu-security/ppa)", |
351 | + help="fetch new binaries from PPA (requires UCT)") |
352 | |
353 | - parser.add_option("--prev-ppa", dest="prev_ppa", default=False, |
354 | - metavar="PPA (eg ubuntu-security/ppa)", |
355 | - help="fetch previous version binaries from PPA (requires UCT)") |
356 | + parser.add_argument("--prev-ppa", dest="prev_ppa", default=False, |
357 | + metavar="PPA (eg ubuntu-security/ppa)", |
358 | + help="fetch previous version binaries from PPA (requires UCT)") |
359 | |
360 | - parser.add_option("--prev-test-repo", dest="test_repo", default=False, |
361 | - action='store_true', |
362 | - help="fetch previous version binaries test repo") |
363 | + parser.add_argument("--prev-test-repo", dest="test_repo", default=False, |
364 | + action='store_true', |
365 | + help="fetch previous version binaries test repo") |
366 | |
367 | - parser.add_option("-e", "--edit", dest="edit", default=False, |
368 | - action='store_true', |
369 | - help="launch $EDITOR for each report") |
370 | + parser.add_argument("-e", "--edit", dest="edit", default=False, |
371 | + action='store_true', |
372 | + help="launch $EDITOR for each report") |
373 | |
374 | - parser.add_option("-i", default=False, dest="insecure", |
375 | - action='store_true', |
376 | - help="allow downloads from insecure repositories (EoL releases)") |
377 | + parser.add_argument("-i", default=False, dest="insecure", |
378 | + action='store_true', |
379 | + help="allow downloads from insecure repositories (EoL releases)") |
380 | |
381 | - (opt, args) = parser.parse_args() |
382 | + (opt, args) = parser.parse_known_args() |
383 | |
384 | details = parse_package_details(skip_sanity = True, override_previous=opt.previous_version) |
385 | |
386 | @@ -1596,16 +1596,16 @@ def copy_to_repo(opt, details, quiet=False, source_dest=source_dest, binary_dest |
387 | |
388 | def add_repo_arguments(parser): |
389 | '''Add the command-line arguments used by repo''' |
390 | - parser.add_option("-r", "--release", dest="release", default=False, |
391 | - help="specify repository to copy to") |
392 | - parser.add_option("--purge", dest="purge", default=False, action='store_true', |
393 | - help="purge repository of all packages before copying") |
394 | + parser.add_argument("-r", "--release", dest="release", default=False, |
395 | + help="specify repository to copy to") |
396 | + parser.add_argument("--purge", dest="purge", default=False, action='store_true', |
397 | + help="purge repository of all packages before copying") |
398 | |
399 | def cmd_repo(): |
400 | '''Copy all built packages into local repository''' |
401 | - parser = umt_optparse("usage: %prog repo [options]") |
402 | + parser = umt_argparse("usage: %(prog)s repo [options]") |
403 | add_repo_arguments(parser) |
404 | - (opt, args) = parser.parse_args() |
405 | + (opt, args) = parser.parse_known_args() |
406 | details = parse_package_details(release = opt.release, skip_sanity=True) |
407 | copy_to_repo(opt, details) |
408 | success("SUCCESS") |
409 | @@ -1613,24 +1613,24 @@ def cmd_repo(): |
410 | def cmd_upload(): |
411 | '''Uploads with dput''' |
412 | |
413 | - parser = umt_optparse("usage: %prog upload [options]") |
414 | + parser = umt_argparse("usage: %(prog)s upload [options]") |
415 | |
416 | - parser.add_option("-d", "--destination", dest="destination", default='ubuntu', metavar="DESTINATION", |
417 | - help="specify destination for upload. Default: ubuntu. Eg: --destination=security-proposed:lucid") |
418 | + parser.add_argument("-d", "--destination", dest="destination", default='ubuntu', metavar="DESTINATION", |
419 | + help="specify destination for upload. Default: ubuntu. Eg: --destination=security-proposed:lucid") |
420 | |
421 | - parser.add_option("-f", "--file", dest="file", default=None, metavar="CHANGES_FILE", |
422 | - help="specify a changes file to upload") |
423 | - parser.add_option("--force", dest="force", default=False, |
424 | - action="store_true", |
425 | - help="Force upload, ignoring potential errors such as versioning problems. By default, upload confirmation prompt will still be displayed. (not recommended!)") |
426 | - parser.add_option("-y", "--yes", dest="yes", action="store_true", |
427 | - help="Skip upload confirmation prompt") |
428 | - parser.add_option("-a", "--aptcache", dest="aptcache", default=False, action='store_true', |
429 | - help="search with apt-cache instead of rmadison (not recommended!)") |
430 | - parser.add_option("-e", "--embargoed", dest="embargoed", default=False, action='store_true', |
431 | - help="Force an embargoed upload to the Ubuntu Security PPA. Default: False") |
432 | + parser.add_argument("-f", "--file", dest="file", default=None, metavar="CHANGES_FILE", |
433 | + help="specify a changes file to upload") |
434 | + parser.add_argument("--force", dest="force", default=False, |
435 | + action="store_true", |
436 | + help="Force upload, ignoring potential errors such as versioning problems. By default, upload confirmation prompt will still be displayed. (not recommended!)") |
437 | + parser.add_argument("-y", "--yes", dest="yes", action="store_true", |
438 | + help="Skip upload confirmation prompt") |
439 | + parser.add_argument("-a", "--aptcache", dest="aptcache", default=False, action='store_true', |
440 | + help="search with apt-cache instead of rmadison (not recommended!)") |
441 | + parser.add_argument("-e", "--embargoed", dest="embargoed", default=False, action='store_true', |
442 | + help="Force an embargoed upload to the Ubuntu Security PPA. Default: False") |
443 | |
444 | - (opt, args) = parser.parse_args() |
445 | + (opt, args) = parser.parse_known_args() |
446 | |
447 | if opt.file: |
448 | changes_file = opt.file |
449 | @@ -1934,18 +1934,18 @@ def cmd_adt(): |
450 | if source_map.cve_lib.is_active_release(rel) or source_map.cve_lib.is_active_esm_release(rel): |
451 | valid_releases.append(rel) |
452 | |
453 | - parser = umt_optparse("usage: %prog adt [options]") |
454 | + parser = umt_argparse("usage: %(prog)s adt [options]") |
455 | |
456 | - parser.add_option("--only-regressions", default=False, action='store_true', |
457 | - help="shows only packages that had a regression") |
458 | - parser.add_option("--verbose", default=False, action='store_true', |
459 | - help="shows output in terminal as verbose") |
460 | - parser.add_option("--html", default=False, action='store_true', |
461 | - help="saves a html output to ../adt and open it in a browser") |
462 | - parser.add_option("--url", default=None, |
463 | - help="Specify the URL to the update_excuses.yaml to use. %s can be used as a placeholder for the release name.") |
464 | + parser.add_argument("--only-regressions", default=False, action='store_true', |
465 | + help="shows only packages that had a regression") |
466 | + parser.add_argument("--verbose", default=False, action='store_true', |
467 | + help="shows output in terminal as verbose") |
468 | + parser.add_argument("--html", default=False, action='store_true', |
469 | + help="saves a html output to ../adt and open it in a browser") |
470 | + parser.add_argument("--url", default=None, |
471 | + help="Specify the URL to the update_excuses.yaml to use. %s can be used as a placeholder for the release name.") |
472 | |
473 | - (opt, args) = parser.parse_args() |
474 | + (opt, args) = parser.parse_known_args() |
475 | |
476 | # validate we know what PPA is |
477 | if release and release in valid_releases: |
478 | @@ -1992,12 +1992,12 @@ def cmd_adt(): |
479 | |
480 | def cmd_grep(): |
481 | '''List source packages matching regex''' |
482 | - parser = umt_optparse("usage: %prog grep regex") |
483 | + parser = umt_argparse("usage: %(prog)s grep regex") |
484 | |
485 | - parser.add_option("-R", "--repo", dest="repo", default="ubuntu", action='store', |
486 | - help="Which repo to search (ubuntu/debian/partner), defaults to ubuntu.") |
487 | + parser.add_argument("-R", "--repo", dest="repo", default="ubuntu", action='store', |
488 | + help="Which repo to search (ubuntu/debian/partner), defaults to ubuntu.") |
489 | |
490 | - (opt, args) = parser.parse_args() |
491 | + (opt, args) = parser.parse_known_args() |
492 | |
493 | if len(args) == 0: |
494 | err("Need to specify a regex.\n") |
495 | @@ -2023,15 +2023,15 @@ def cmd_search(): |
496 | '''Search for best source packages for each release''' |
497 | print("Running search command.") |
498 | |
499 | - parser = umt_optparse("usage: %prog search package") |
500 | + parser = umt_argparse("usage: %(prog)s search package") |
501 | |
502 | - parser.add_option("-R", "--rmadison", dest="rmadison", default=False, action='store_true', |
503 | - help="search with rmadison instead of apt-cache") |
504 | + parser.add_argument("-R", "--rmadison", dest="rmadison", default=False, action='store_true', |
505 | + help="search with rmadison instead of apt-cache") |
506 | |
507 | - parser.add_option("-p", "--proposed", dest="proposed", default=False, action='store_true', |
508 | - help="include -proposed packages in results") |
509 | + parser.add_argument("-p", "--proposed", dest="proposed", default=False, action='store_true', |
510 | + help="include -proposed packages in results") |
511 | |
512 | - (opt, args) = parser.parse_args() |
513 | + (opt, args) = parser.parse_known_args() |
514 | |
515 | if len(args) == 0: |
516 | err("Need to specify the source package.\n") |
517 | @@ -2069,74 +2069,6 @@ def cmd_search(): |
518 | print("%s: %s, Pocket: %s, Component: %s" % (release, |
519 | pkg_list[release][0], pkg_list[release][1], pkg_list[release][2])) |
520 | |
521 | -def cmd_qrt(): |
522 | - '''Run QRT tests for the package in the current directory of unpacked source''' |
523 | - parser = umt_optparse("usage: %prog qrt [options] [-- test-qrt-script.py options]") |
524 | - add_repo_arguments(parser) |
525 | - parser.add_option("-a", "--arch", dest="arch", default="amd64", |
526 | - help="Architecture to test (default: amd64)") |
527 | - parser.add_option("-s", "--sudo", dest="sudo", default=False, action='store_true', |
528 | - help="Whether to run the QRT tests via sudo as a regular user") |
529 | - parser.add_option("-u", "--user", dest="user", default=os.getlogin(), metavar='USER', |
530 | - help="The username to run the QRT tests as (default: current user)") |
531 | - parser.add_option("-q", "--qrt-path", dest="qrt_path", default=os.getenv("QRT", ""), metavar='QRT_PATH', |
532 | - help="Path to the local copy of the qa-regression-tools (QRT) repo") |
533 | - parser.add_option("--no-update", dest="no_update", default=False, action='store_true', |
534 | - help="Don't update UVT VM before initial test run") |
535 | - parser.add_option("--no-snapshot", dest="no_snapshot", default=False, action='store_true', |
536 | - help="Don't revert or update snapshot of UVT VM on update") |
537 | - parser.add_option("-P", "--enable-proposed", dest="enable_proposed", default=False, action='store_true', |
538 | - help="Enable -proposed within the VM") |
539 | - parser.add_option("--skip-baseline", dest="skip_baseline", default=False, action='store_true', |
540 | - help="Don't try and run the tests against the current archive build as a baseline") |
541 | - parser.add_option("-n", "--dry-run", dest="dry_run", default=False, action='store_true', |
542 | - help="Don't actually execute tests, instead print what would be run") |
543 | - parser.add_option("-b", "--backend", dest="backend", default="uvt", |
544 | - help="VM backend to use (uvt or lxd) (default: uvt)") |
545 | - parser.add_option("-p", "--vm-prefix", dest="vm_prefix", default="sec", |
546 | - help="Prefix to use for UVT/LXD VM names (default: sec)") |
547 | - parser.add_option("-v", "--vm", dest="vm", default=None, |
548 | - help="VM to use for tests (default: use {vm-prefix}-release-{arch})") |
549 | - parser.add_option("--debug", default=False, action='store_true', |
550 | - help="Report additional debug details") |
551 | - parser.add_option("-f", "--force", dest="force", default=False, action='store_true', |
552 | - help="force deletion of ../tests before running") |
553 | - parser.add_option("-F", "--ignore-failures", dest="ignore_failures", default=False, action='store_true', |
554 | - help="continue even if test failures encountered when running qrt tests") |
555 | - parser.add_option("-t", "--test-name", dest="test_name", metavar='NAME', default=None, action='store', |
556 | - help="run QRT script test-NAME.py instead of the current package") |
557 | - parser.add_option("--ppa", dest="ppa", default=False, |
558 | - metavar="PPA (eg ubuntu-security/ppa)", |
559 | - help="fetch new binaries from PPA (requires UCT)") |
560 | - parser.add_option("--prev-ppa", dest="prev_ppa", default=False, |
561 | - metavar="PPA (eg ubuntu-security/ppa)", |
562 | - help="fetch previous version binaries from PPA (requires UCT)") |
563 | - parser.add_option("--skip-repo", dest="skip_repo", default=False, |
564 | - help="Do not copy any packages to local repo") |
565 | - parser.add_option("--previous-version", dest="previous_version", |
566 | - default=False, metavar="PREVIOUS", |
567 | - help="compare against previous version") |
568 | - (opt, args) = parser.parse_args() |
569 | - |
570 | - validate_toplevel() |
571 | - details = parse_package_details(skip_sanity=True, override_previous=opt.previous_version) |
572 | - |
573 | - run_qrt_tests(opt, args, details) |
574 | - # also alert if there appear to be other bits in QRT worth looking at |
575 | - for d in ['build_testing', 'notes_testing']: |
576 | - testing_dir = os.path.join(opt.qrt_path, d, details["package"]) |
577 | - try: |
578 | - files = os.listdir(testing_dir) |
579 | - except: |
580 | - files = [] |
581 | - finally: |
582 | - if len(files) > 0: |
583 | - warn("QRT also contains the following relevant files for " + details["package"] + ":") |
584 | - for f in files: |
585 | - warn(" " + os.path.join(d, details["package"], f)) |
586 | - warn("Please ensure you consult these") |
587 | - |
588 | - |
589 | class QRTBackend: |
590 | class NotImplementedError(Exception): |
591 | def __init__(self, msg="🚧 Please implement me 🚧", *args, **kwargs): |
592 | @@ -2389,16 +2321,84 @@ class LXDQRTBackend(QRTBackend): |
593 | os.unlink(local_path) |
594 | self.exec("apt update", root=True) |
595 | |
596 | +qrt_backends = {'uvt': UVTQRTBackend, |
597 | + 'lxd': LXDQRTBackend} |
598 | + |
599 | +def cmd_qrt(): |
600 | + '''Run QRT tests for the package in the current directory of unpacked source''' |
601 | + parser = umt_argparse("usage: %(prog)s qrt [options] [-- test-qrt-script.py options]") |
602 | + add_repo_arguments(parser) |
603 | + parser.add_argument("-a", "--arch", dest="arch", default="amd64", |
604 | + help="Architecture to test (default: amd64)") |
605 | + parser.add_argument("-s", "--sudo", dest="sudo", default=False, action='store_true', |
606 | + help="Whether to run the QRT tests via sudo as a regular user") |
607 | + parser.add_argument("-u", "--user", dest="user", default=os.getlogin(), metavar='USER', |
608 | + help="The username to run the QRT tests as (default: current user)") |
609 | + parser.add_argument("-q", "--qrt-path", dest="qrt_path", default=os.getenv("QRT", ""), metavar='QRT_PATH', |
610 | + help="Path to the local copy of the qa-regression-tools (QRT) repo") |
611 | + parser.add_argument("--no-update", dest="no_update", default=False, action='store_true', |
612 | + help="Don't update UVT VM before initial test run") |
613 | + parser.add_argument("--no-snapshot", dest="no_snapshot", default=False, action='store_true', |
614 | + help="Don't revert or update snapshot of UVT VM on update") |
615 | + parser.add_argument("-P", "--enable-proposed", dest="enable_proposed", default=False, action='store_true', |
616 | + help="Enable -proposed within the VM") |
617 | + parser.add_argument("--skip-baseline", dest="skip_baseline", default=False, action='store_true', |
618 | + help="Don't try and run the tests against the current archive build as a baseline") |
619 | + parser.add_argument("-n", "--dry-run", dest="dry_run", default=False, action='store_true', |
620 | + help="Don't actually execute tests, instead print what would be run") |
621 | + parser.add_argument("-b", "--backend", dest="backend", default="uvt", |
622 | + choices=qrt_backends.keys(), |
623 | + help="VM backend to use (default: uvt)") |
624 | + parser.add_argument("-p", "--vm-prefix", dest="vm_prefix", default="sec", |
625 | + help="Prefix to use for UVT/LXD VM names (default: sec)") |
626 | + parser.add_argument("-v", "--vm", dest="vm", default=None, |
627 | + help="VM to use for tests (default: use {vm-prefix}-release-{arch})") |
628 | + parser.add_argument("--debug", default=False, action='store_true', |
629 | + help="Report additional debug details") |
630 | + parser.add_argument("-f", "--force", dest="force", default=False, action='store_true', |
631 | + help="force deletion of ../tests before running") |
632 | + parser.add_argument("-F", "--ignore-failures", dest="ignore_failures", default=False, action='store_true', |
633 | + help="continue even if test failures encountered when running qrt tests") |
634 | + parser.add_argument("-t", "--test-name", dest="test_name", metavar='NAME', default=None, action='store', |
635 | + help="run QRT script test-NAME.py instead of the current package") |
636 | + parser.add_argument("--ppa", dest="ppa", default=False, |
637 | + metavar="PPA (eg ubuntu-security/ppa)", |
638 | + help="fetch new binaries from PPA (requires UCT)") |
639 | + parser.add_argument("--prev-ppa", dest="prev_ppa", default=False, |
640 | + metavar="PPA (eg ubuntu-security/ppa)", |
641 | + help="fetch previous version binaries from PPA (requires UCT)") |
642 | + parser.add_argument("--skip-repo", dest="skip_repo", default=False, |
643 | + help="Do not copy any packages to local repo") |
644 | + parser.add_argument("--previous-version", dest="previous_version", |
645 | + default=False, metavar="PREVIOUS", |
646 | + help="compare against previous version") |
647 | + (opt, args) = parser.parse_known_args() |
648 | + |
649 | + validate_toplevel() |
650 | + details = parse_package_details(skip_sanity=True, override_previous=opt.previous_version) |
651 | + |
652 | + run_qrt_tests(opt, args, details) |
653 | + # also alert if there appear to be other bits in QRT worth looking at |
654 | + for d in ['build_testing', 'notes_testing']: |
655 | + testing_dir = os.path.join(opt.qrt_path, d, details["package"]) |
656 | + try: |
657 | + files = os.listdir(testing_dir) |
658 | + except: |
659 | + files = [] |
660 | + finally: |
661 | + if len(files) > 0: |
662 | + warn("QRT also contains the following relevant files for " + details["package"] + ":") |
663 | + for f in files: |
664 | + warn(" " + os.path.join(d, details["package"], f)) |
665 | + warn("Please ensure you consult these") |
666 | + |
667 | + |
668 | + |
669 | def run_qrt_tests(opt, args, details): |
670 | okrc = [0] |
671 | if opt.ignore_failures: |
672 | okrc.append(1) |
673 | |
674 | - # validate backend early |
675 | - if opt.backend not in ['uvt', 'lxd']: |
676 | - err("Unsupported backend %s" % opt.backend) |
677 | - sys.exit(1) |
678 | - |
679 | binary_dest = globals()["binary_dest"] |
680 | test_name = 'test-' + (opt.test_name if opt.test_name is not None else details["package"]) |
681 | # if we also are using a PPA for |
682 | @@ -2436,13 +2436,7 @@ def run_qrt_tests(opt, args, details): |
683 | else: |
684 | vm = opt.vm_prefix + "-" + details["release"] + "-" + opt.arch |
685 | |
686 | - if opt.backend == 'uvt': |
687 | - backend = UVTQRTBackend(vm, user=user, debug=opt.debug, no_snapshot=opt.no_snapshot) |
688 | - elif opt.backend == 'lxd': |
689 | - backend = LXDQRTBackend(vm, user=user, debug=opt.debug, no_snapshot=opt.no_snapshot) |
690 | - else: |
691 | - # shouldn't get here |
692 | - sys.exit(1) |
693 | + backend = qrt_backends[opt.backend](vm, user=user, debug=opt.debug, no_snapshot=opt.no_snapshot) |
694 | |
695 | print("Running QRT test " + qrt_test + " for " + details["package"] + " as " + user + (" via sudo" if opt.sudo else "") + " with " + backend.name) |
696 | |
697 | @@ -2626,29 +2620,29 @@ def run_qrt_tests(opt, args, details): |
698 | |
699 | def cmd_autopkgtest(): |
700 | '''Run AUTOPKGTEST tests for the package in the current directory of unpacked source''' |
701 | - parser = umt_optparse("usage: %prog autopkgtest [options] [-- autopkgtest-virt-qemu options]") |
702 | - parser.add_option("-a", "--arch", dest="arch", default="amd64", |
703 | - help="Architecture to test (default: amd64)") |
704 | - parser.add_option("-p", "--images-path", dest="images_path", default="~/images/", |
705 | - help="Location QEMU autopkgtest images to use for tests (default: ~/images/)") |
706 | - parser.add_option("-i", "--image", dest="image", default=None, |
707 | - help="QEMU autopkgtest image name to use for tests (default: {images-path}/autopkgtest-{release}-{arch}.img)") |
708 | - parser.add_option("-s", "--skip-baseline", dest="skip_baseline", default=False, action='store_true', |
709 | - help="Don't try and run the tests against the archive build as a baseline") |
710 | - parser.add_option("-n", "--dry-run", dest="dry_run", default=False, action='store_true', |
711 | - help="Don't actually execute tests, instead print what would be run") |
712 | - parser.add_option("--debug", default=False, action='store_true', |
713 | - help="Report additional debug details") |
714 | - parser.add_option("-f", "--force", dest="force", default=False, action='store_true', |
715 | - help="force deletion of ../autopkgtest before running") |
716 | - parser.add_option("-F", "--ignore-failures", dest="ignore_failures", default=False, action='store_true', |
717 | - help="continue even if test failures encountered when running autopkgtests") |
718 | - parser.add_option("-A", "--autopkgtest-config", dest="autopkgtest_config", default=None, |
719 | - help="A configuration file to use to pass extra arguments to autopkgtest (ie gets expanded to @AUTOPKGTEST_CONFIG when passed to autopkgtest)") |
720 | - parser.add_option("--previous-version", dest="previous_version", |
721 | - default=False, metavar="PREVIOUS", |
722 | - help="compare against previous version") |
723 | - (opt, args) = parser.parse_args() |
724 | + parser = umt_argparse("usage: %(prog)s autopkgtest [options] [-- autopkgtest-virt-qemu options]") |
725 | + parser.add_argument("-a", "--arch", dest="arch", default="amd64", |
726 | + help="Architecture to test (default: amd64)") |
727 | + parser.add_argument("-p", "--images-path", dest="images_path", default="~/images/", |
728 | + help="Location QEMU autopkgtest images to use for tests (default: ~/images/)") |
729 | + parser.add_argument("-i", "--image", dest="image", default=None, |
730 | + help="QEMU autopkgtest image name to use for tests (default: {images-path}/autopkgtest-{release}-{arch}.img)") |
731 | + parser.add_argument("-s", "--skip-baseline", dest="skip_baseline", default=False, action='store_true', |
732 | + help="Don't try and run the tests against the archive build as a baseline") |
733 | + parser.add_argument("-n", "--dry-run", dest="dry_run", default=False, action='store_true', |
734 | + help="Don't actually execute tests, instead print what would be run") |
735 | + parser.add_argument("--debug", default=False, action='store_true', |
736 | + help="Report additional debug details") |
737 | + parser.add_argument("-f", "--force", dest="force", default=False, action='store_true', |
738 | + help="force deletion of ../autopkgtest before running") |
739 | + parser.add_argument("-F", "--ignore-failures", dest="ignore_failures", default=False, action='store_true', |
740 | + help="continue even if test failures encountered when running autopkgtests") |
741 | + parser.add_argument("-A", "--autopkgtest-config", dest="autopkgtest_config", default=None, |
742 | + help="A configuration file to use to pass extra arguments to autopkgtest (ie gets expanded to @AUTOPKGTEST_CONFIG when passed to autopkgtest)") |
743 | + parser.add_argument("--previous-version", dest="previous_version", |
744 | + default=False, metavar="PREVIOUS", |
745 | + help="compare against previous version") |
746 | + (opt, args) = parser.parse_known_args() |
747 | |
748 | validate_toplevel() |
749 | details = parse_package_details(skip_sanity=True, override_previous=opt.previous_version) |
750 | @@ -2778,31 +2772,31 @@ def cmd_testflinger(): |
751 | '''Run TESTFLINGER tests for the package in the current directory of unpacked source''' |
752 | testflinger_queues = lookup_testflinger_queues() |
753 | |
754 | - parser = umt_optparse("usage: %prog testflinger [options]") |
755 | - parser.add_option("-l", "--list-queues", dest="list_queues", action='store_true', default=False, |
756 | - help="List supported testflinger queues") |
757 | - parser.add_option("-q", "--queues", dest="queues", default=','.join(testflinger_queues.keys()), |
758 | - help="Comma separated list of testflinger queues to use (default: all)") |
759 | - parser.add_option("-I", "--image", dest="image", default=None, |
760 | - help="Testflinger image name to use (default to current release)") |
761 | - parser.add_option("-n", "--dry-run", dest="dry_run", default=False, action='store_true', |
762 | - help="Don't actually execute tests, instead print what would be run") |
763 | - parser.add_option("--debug", default=False, action='store_true', |
764 | - help="Report additional debug details") |
765 | - parser.add_option("-f", "--force", dest="force", default=False, action='store_true', |
766 | - help="force deletion of ../testflinger before running") |
767 | - parser.add_option("-F", "--ignore-failures", dest="ignore_failures", default=False, action='store_true', |
768 | - help="continue even if test failures encountered when running testflinger") |
769 | - parser.add_option("-T", "--template", dest="template", default=None, |
770 | - help="A testflinger job template to use - this allows to specify extra commands etc") |
771 | - parser.add_option("--repo", dest="repo", default=None, |
772 | - metavar="Anything suitable for `add-apt-repository REPO` (ie. 'ppa:ubuntu-security-proposed/ppa' or 'https://https://USER:PASS@private-ppa.launchpad.net/ubuntu-security/ppa/ubuntu' etc)", |
773 | - help="Add REPO to test machine to test new binaries from it rather than using yantok") |
774 | - parser.add_option("-j", "--jump-host", dest="jump_host", default=os.getenv("USER") + "@yantok.canonical.com:/srv/enablement/www", |
775 | - help="A jump host to temporarily store debs to be loaded on test machine (default $USER@yantok.canonical.com:/srv/enablement/www)") |
776 | - parser.add_option("-i", "--jump-host-internal-ip", dest="jump_host_ip", default="10.101.47.1", |
777 | - help="The internal IP of JUMP_HOST (default 10.101.47.1 for yanktok)") |
778 | - (opt, args) = parser.parse_args() |
779 | + parser = umt_argparse("usage: %(prog)s testflinger [options]") |
780 | + parser.add_argument("-l", "--list-queues", dest="list_queues", action='store_true', default=False, |
781 | + help="List supported testflinger queues") |
782 | + parser.add_argument("-q", "--queues", dest="queues", default=','.join(testflinger_queues.keys()), |
783 | + help="Comma separated list of testflinger queues to use (default: all)") |
784 | + parser.add_argument("-I", "--image", dest="image", default=None, |
785 | + help="Testflinger image name to use (default to current release)") |
786 | + parser.add_argument("-n", "--dry-run", dest="dry_run", default=False, action='store_true', |
787 | + help="Don't actually execute tests, instead print what would be run") |
788 | + parser.add_argument("--debug", default=False, action='store_true', |
789 | + help="Report additional debug details") |
790 | + parser.add_argument("-f", "--force", dest="force", default=False, action='store_true', |
791 | + help="force deletion of ../testflinger before running") |
792 | + parser.add_argument("-F", "--ignore-failures", dest="ignore_failures", default=False, action='store_true', |
793 | + help="continue even if test failures encountered when running testflinger") |
794 | + parser.add_argument("-T", "--template", dest="template", default=None, |
795 | + help="A testflinger job template to use - this allows to specify extra commands etc") |
796 | + parser.add_argument("--repo", dest="repo", default=None, |
797 | + metavar="Anything suitable for `add-apt-repository REPO` (ie. 'ppa:ubuntu-security-proposed/ppa' or 'https://https://USER:PASS@private-ppa.launchpad.net/ubuntu-security/ppa/ubuntu' etc)", |
798 | + help="Add REPO to test machine to test new binaries from it rather than using yantok") |
799 | + parser.add_argument("-j", "--jump-host", dest="jump_host", default=os.getenv("USER") + "@yantok.canonical.com:/srv/enablement/www", |
800 | + help="A jump host to temporarily store debs to be loaded on test machine (default $USER@yantok.canonical.com:/srv/enablement/www)") |
801 | + parser.add_argument("-i", "--jump-host-internal-ip", dest="jump_host_ip", default="10.101.47.1", |
802 | + help="The internal IP of JUMP_HOST (default 10.101.47.1 for yanktok)") |
803 | + (opt, args) = parser.parse_known_args() |
804 | |
805 | validate_toplevel() |
806 | details = parse_package_details(skip_sanity=True) |
807 | @@ -3167,108 +3161,113 @@ def prepare_tool_env(opt, details): |
808 | except: |
809 | pass |
810 | |
811 | -def add_source_build_opts(parser): |
812 | +def add_source_build_opts(parser: argparse.ArgumentParser): |
813 | '''Adds options relevant to source package building.''' |
814 | - parser.add_option("--quick-source-build", default=False, action='store_true', |
815 | - help="Use dpkg-source and dpkg-genchanges in place of debuild. This does not clean the source directory and disables dependency installation. Use carefully!") |
816 | + parser.add_argument("--quick-source-build", default=False, action='store_true', |
817 | + help="Use dpkg-source and dpkg-genchanges in place of debuild. This does not clean the source directory and disables dependency installation. Use carefully!") |
818 | |
819 | - parser.add_option("-d", "--dependency-resolution", metavar="METHOD", default='auto', action='store', |
820 | - help="Specify how to resolve build dependencies: 'auto'(default, uses debian/control and parses apt-get failures), 'manual'(apt-get build-dep only), 'minimal'(just minimal build requirements), or 'none'(do nothing)") |
821 | + parser.add_argument("-d", "--dependency-resolution", metavar="METHOD", default='auto', action='store', |
822 | + help="Specify how to resolve build dependencies: 'auto'(default, uses debian/control and parses apt-get failures), 'manual'(apt-get build-dep only), 'minimal'(just minimal build requirements), or 'none'(do nothing)") |
823 | |
824 | - parser.add_option("--skip-maintainer", default=False, action='store_true', |
825 | - help="Do not automatically update the Maintainer field when building the source package.") |
826 | + parser.add_argument("--skip-maintainer", default=False, action='store_true', |
827 | + help="Do not automatically update the Maintainer field when building the source package.") |
828 | |
829 | - parser.add_option("--merge", default=False, action='store_true', |
830 | - help="Generate debdiff against version specified with --start-version.") |
831 | + parser.add_argument("--merge", default=False, action='store_true', |
832 | + help="Generate debdiff against version specified with --start-version.") |
833 | |
834 | - parser.add_option("--simple-maintainer-update", default=False, action='store_true', |
835 | - help="Use the simpler 'u-maint' to do Maintainer field updates.") |
836 | + parser.add_argument("--simple-maintainer-update", default=False, action='store_true', |
837 | + help="Use the simpler 'u-maint' to do Maintainer field updates.") |
838 | |
839 | - parser.add_option("--search-rmadison", dest="rmadison", default=False, action='store_true', |
840 | - help="search for package component with rmadison instead of apt-cache") |
841 | + parser.add_argument("--search-rmadison", dest="rmadison", default=False, action='store_true', |
842 | + help="search for package component with rmadison instead of apt-cache") |
843 | |
844 | - parser.add_option("--search-proposed", dest="proposed", default=False, action='store_true', |
845 | - help="search for package component in -proposed pocket") |
846 | + parser.add_argument("--search-proposed", dest="proposed", default=False, action='store_true', |
847 | + help="search for package component in -proposed pocket") |
848 | |
849 | - parser.add_option("--add-debuild-opts", dest="debuild_opts", default=None, |
850 | - help="additional arguments to pass along to debuild") |
851 | + parser.add_argument("--add-debuild-opts", dest="debuild_opts", default=None, |
852 | + help="additional arguments to pass along to debuild") |
853 | |
854 | -def add_binary_build_opts(parser): |
855 | +def add_binary_build_opts(parser: argparse.ArgumentParser): |
856 | '''Adds options relevant to binary package building.''' |
857 | |
858 | - parser.add_option("-n", "--notall", dest="all", default=True, action='store_false', |
859 | - help="Don't build Architecture: all packages") |
860 | + parser.add_argument("-n", "--notall", dest="all", default=True, action='store_false', |
861 | + help="Don't build Architecture: all packages") |
862 | |
863 | - parser.add_option("--ccache", dest="ccache", default=False, action='store_true', |
864 | - help="install and use ccache during build") |
865 | + parser.add_argument("--ccache", dest="ccache", default=False, action='store_true', |
866 | + help="install and use ccache during build") |
867 | |
868 | - parser.add_option("--cov-build", metavar='PATH', default=None, action='store', |
869 | - help="use the cov-build tool at PATH during the build") |
870 | + parser.add_argument("--cov-build", metavar='PATH', default=None, action='store', |
871 | + help="use the cov-build tool at PATH during the build") |
872 | |
873 | - parser.add_option("-H", "--hardening", dest="hardening", default=False, action='store_true', |
874 | - help="install and use hardening-wrapper during build") |
875 | + parser.add_argument("-H", "--hardening", dest="hardening", default=False, action='store_true', |
876 | + help="install and use hardening-wrapper during build") |
877 | |
878 | - parser.add_option("--sbuild-dep-resolver", metavar="METHOD", default=None, action='store', |
879 | - help="Specify sbuild resolver (man sbuild): 'apt' (sbuild default), 'aptitude', or 'internal'. If not specified, uses sbuild default (or the value of $build_dep_resolver in ~/.sbuildrc)") |
880 | + parser.add_argument("--sbuild-dep-resolver", metavar="METHOD", default=None, action='store', |
881 | + help="Specify sbuild resolver (man sbuild): 'apt' (sbuild default), 'aptitude', or 'internal'. If not specified, uses sbuild default (or the value of $build_dep_resolver in ~/.sbuildrc)") |
882 | |
883 | - parser.add_option("--purge-schroot", metavar="METHOD", default=None, action='store', |
884 | - help="Specify sbuild purge behavior (man sbuild): 'always' (sbuild default), 'successful', or 'never'. If not specified, uses sbuild default (or the value of $purge_session/$purge_build_directory in ~/.sbuildrc)") |
885 | + parser.add_argument("--purge-schroot", metavar="METHOD", default=None, action='store', |
886 | + help="Specify sbuild purge behavior (man sbuild): 'always' (sbuild default), 'successful', or 'never'. If not specified, uses sbuild default (or the value of $purge_session/$purge_build_directory in ~/.sbuildrc)") |
887 | |
888 | |
889 | -def add_common_build_opts(parser): |
890 | +def add_common_build_opts(parser: argparse.ArgumentParser): |
891 | '''Adds common options.''' |
892 | |
893 | - parser.add_option("-e", "--extradeps", dest="extra_deps", default="", metavar="DEP,DEP,...", |
894 | - help="comma separated list of extra dependencies to be installed before build-dep") |
895 | - |
896 | - parser.add_option("-r", "--release", dest="release", default=False, |
897 | - help="specify release to build") |
898 | - |
899 | - parser.add_option("-f", "--force", dest="force", default=False, action='store_true', |
900 | - help="force deletion of ../source and ../binary before build") |
901 | - parser.add_option("-s", "--skip", dest="skip", default=False, action='store_true', |
902 | - help="skip pocket and release sanity checks") |
903 | - parser.add_option("--force-updates", dest="force_updates", default=False, action='store_true', |
904 | - help="Include -updates pocket when building") |
905 | - parser.add_option("--force-proposed", dest="force_proposed", default=False, action='store_true', |
906 | - help="Include -proposed pocket when building") |
907 | - parser.add_option("--force-orig", dest="force_sa", default=False, action='store_true', |
908 | - help="Force an orig upload") |
909 | - parser.add_option("--force-no-orig", dest="force_sd", default=False, action='store_true', |
910 | - help="Force no orig upload") |
911 | - parser.add_option("-c", "--chroot", dest="chroot", default="", metavar="CHROOT", |
912 | - help="specify chroot to use") |
913 | - parser.add_option("--component", dest="component", default=None, metavar="COMPONENT", |
914 | - help="specify component to use (default: autodetected)") |
915 | - parser.add_option("--add-repo", dest="add_repo", default=False, action='store_true', |
916 | - help="Add local apt archive to sources.list. Note: apt-key should first be run in the chroot for this to work") |
917 | + parser.add_argument("-e", "--extradeps", dest="extra_deps", default="", metavar="DEP,DEP,...", |
918 | + help="comma separated list of extra dependencies to be installed before build-dep") |
919 | + |
920 | + parser.add_argument("-r", "--release", dest="release", default=False, |
921 | + help="specify release to build") |
922 | + |
923 | + parser.add_argument("-f", "--force", dest="force", default=False, action='store_true', |
924 | + help="force deletion of ../source and ../binary before build") |
925 | + parser.add_argument("-s", "--skip", dest="skip", default=False, action='store_true', |
926 | + help="skip pocket and release sanity checks") |
927 | + parser.add_argument("--force-updates", dest="force_updates", default=False, action='store_true', |
928 | + help="Include -updates pocket when building") |
929 | + parser.add_argument("--force-proposed", dest="force_proposed", default=False, action='store_true', |
930 | + help="Include -proposed pocket when building") |
931 | + parser.add_argument("--force-orig", dest="force_sa", default=False, action='store_true', |
932 | + help="Force an orig upload") |
933 | + parser.add_argument("--force-no-orig", dest="force_sd", default=False, action='store_true', |
934 | + help="Force no orig upload") |
935 | + parser.add_argument("-c", "--chroot", dest="chroot", default="", metavar="CHROOT", |
936 | + help="specify chroot to use") |
937 | + parser.add_argument("--component", dest="component", default=None, metavar="COMPONENT", |
938 | + help="specify component to use (default: autodetected)") |
939 | + parser.add_argument("--add-repo", dest="add_repo", default=False, action='store_true', |
940 | + help="Add local apt archive to sources.list. Note: apt-key should first be run in the chroot for this to work") |
941 | cpus = "%d" % (os.sysconf("SC_NPROCESSORS_ONLN")) |
942 | if 'pkgbuild_parallel' in ust and not ust['pkgbuild_parallel'].startswith('auto'): |
943 | if re.search('^[0-9]+$', ust['pkgbuild_parallel']): |
944 | cpus = ust['pkgbuild_parallel'] |
945 | else: |
946 | warn("Invalid setting '%s' for pkgbuild_parallel. Using autodetection" % (ust['pkgbuild_parallel'])) |
947 | - parser.add_option("--parallel", default=cpus, metavar="THREADS", |
948 | - help="how many CPUs to use for building, via DEB_BUILD_OPTIONS (default: autodetected %s or via pkgbuild_parallel in conf)" % (cpus)) |
949 | - |
950 | - |
951 | -def opts_override_config(option, opt, value, parser): |
952 | - if '=' not in value: |
953 | - report = '%s: no name/value pair given\n' % (opt) |
954 | - report += 'Current ~/.ubuntu-security-tools.conf settings:\n\n' |
955 | - for name in ust: |
956 | - report += '%s=%s\n' % (name, ust[name]) |
957 | - raise optparse.OptionValueError(report) |
958 | - (name, setting) = value.split('=') |
959 | - ust[name] = setting |
960 | - |
961 | -def umt_optparse(usage): |
962 | + parser.add_argument("--parallel", default=cpus, metavar="THREADS", |
963 | + help="how many CPUs to use for building, via DEB_BUILD_OPTIONS (default: autodetected %s or via pkgbuild_parallel in conf)" % (cpus)) |
964 | + |
965 | + |
966 | +class OverrideConfigAction(argparse.Action): |
967 | + def __init__(self, option_strings, dest, nargs=None, **kwargs): |
968 | + if nargs is not None: |
969 | + raise ValueError("nargs not allowed") |
970 | + super().__init__(option_strings, dest, **kwargs) |
971 | + def __call__(self, parser, namespace, value, option_string=None): |
972 | + if '=' not in value: |
973 | + report = '%s: no name/value pair given\n' % (option_string) |
974 | + report += 'Current ~/.ubuntu-security-tools.conf settings:\n\n' |
975 | + for name in ust: |
976 | + report += '%s=%s\n' % (name, ust[name]) |
977 | + raise argparse.ArgumentError(report) |
978 | + (name, setting) = value.split('=') |
979 | + ust[name] = setting |
980 | + |
981 | +def umt_argparse(usage): |
982 | '''Build parser and adds options common to all commands.''' |
983 | - parser = optparse.OptionParser(usage=usage) |
984 | + parser = argparse.ArgumentParser(usage=usage) |
985 | |
986 | - parser.add_option("-C", "--config", action='callback', type="string", |
987 | + parser.add_argument("-C", "--config", |
988 | + action=OverrideConfigAction, |
989 | metavar="NAME=VALUE", |
990 | - callback=opts_override_config, |
991 | help="override ~/.ubuntu-security-tools.conf values") |
992 | return parser |
993 |
Merging without review after 1 week open.