Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/
Date: Fri, 02 Aug 2013 09:49:21
Message-Id: 1375436937.9a141c62a44cd3d05e009129457f74c88b00e7d5.zmedico@gentoo
1 commit: 9a141c62a44cd3d05e009129457f74c88b00e7d5
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 2 09:48:57 2013 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Fri Aug 2 09:48:57 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=9a141c62
7
8 emerge: portage.util._argparse
9
10 ---
11 pym/_emerge/main.py | 56 ++++++++---------------------------------------------
12 1 file changed, 8 insertions(+), 48 deletions(-)
13
14 diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py
15 index edf40a5..2e68a05 100644
16 --- a/pym/_emerge/main.py
17 +++ b/pym/_emerge/main.py
18 @@ -18,6 +18,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
19 '_emerge.is_valid_package_atom:insert_category_into_atom'
20 )
21 from portage import os
22 +from portage.util._argparse import ArgumentParser
23
24 if sys.hexversion >= 0x3000000:
25 long = int
26 @@ -298,31 +299,26 @@ def parse_opts(tmpcmdline, silent=False):
27 "--ask": {
28 "shortopt" : "-a",
29 "help" : "prompt before performing any actions",
30 - "type" : "choice",
31 "choices" : true_y_or_n
32 },
33
34 "--autounmask": {
35 "help" : "automatically unmask packages",
36 - "type" : "choice",
37 "choices" : true_y_or_n
38 },
39
40 "--autounmask-unrestricted-atoms": {
41 "help" : "write autounmask changes with >= atoms if possible",
42 - "type" : "choice",
43 "choices" : true_y_or_n
44 },
45
46 "--autounmask-keep-masks": {
47 "help" : "don't add package.unmask entries",
48 - "type" : "choice",
49 "choices" : true_y_or_n
50 },
51
52 "--autounmask-write": {
53 "help" : "write changes made by --autounmask to disk",
54 - "type" : "choice",
55 "choices" : true_y_or_n
56 },
57
58 @@ -347,7 +343,6 @@ def parse_opts(tmpcmdline, silent=False):
59 "--buildpkg": {
60 "shortopt" : "-b",
61 "help" : "build binary packages",
62 - "type" : "choice",
63 "choices" : true_y_or_n
64 },
65
66 @@ -365,25 +360,21 @@ def parse_opts(tmpcmdline, silent=False):
67 },
68 "--color": {
69 "help":"enable or disable color output",
70 - "type":"choice",
71 "choices":("y", "n")
72 },
73
74 "--complete-graph": {
75 "help" : "completely account for all known dependencies",
76 - "type" : "choice",
77 "choices" : true_y_or_n
78 },
79
80 "--complete-graph-if-new-use": {
81 "help" : "trigger --complete-graph behavior if USE or IUSE will change for an installed package",
82 - "type" : "choice",
83 "choices" : y_or_n
84 },
85
86 "--complete-graph-if-new-ver": {
87 "help" : "trigger --complete-graph behavior if an installed package version will change (upgrade or downgrade)",
88 - "type" : "choice",
89 "choices" : y_or_n
90 },
91
92 @@ -401,19 +392,16 @@ def parse_opts(tmpcmdline, silent=False):
93
94 "--depclean-lib-check": {
95 "help" : "check for consumers of libraries before removing them",
96 - "type" : "choice",
97 "choices" : true_y_or_n
98 },
99
100 "--deselect": {
101 "help" : "remove atoms/sets from the world file",
102 - "type" : "choice",
103 "choices" : true_y_or_n
104 },
105
106 "--dynamic-deps": {
107 "help": "substitute the dependencies of installed packages with the dependencies of unbuilt ebuilds",
108 - "type": "choice",
109 "choices": y_or_n
110 },
111
112 @@ -427,7 +415,6 @@ def parse_opts(tmpcmdline, silent=False):
113
114 "--fail-clean": {
115 "help" : "clean temp files after build failure",
116 - "type" : "choice",
117 "choices" : true_y_or_n
118 },
119
120 @@ -437,7 +424,6 @@ def parse_opts(tmpcmdline, silent=False):
121 "only for debugging purposes, and it only affects built packages "
122 "that specify slot/sub-slot := operator dependencies using the "
123 "experimental \"4-slot-abi\" EAPI.",
124 - "type": "choice",
125 "choices": y_or_n
126 },
127
128 @@ -453,7 +439,6 @@ def parse_opts(tmpcmdline, silent=False):
129
130 "--keep-going": {
131 "help" : "continue as much as possible after an error",
132 - "type" : "choice",
133 "choices" : true_y_or_n
134 },
135
136 @@ -468,18 +453,15 @@ def parse_opts(tmpcmdline, silent=False):
137
138 "--misspell-suggestions": {
139 "help" : "enable package name misspell suggestions",
140 - "type" : "choice",
141 "choices" : ("y", "n")
142 },
143
144 "--with-bdeps": {
145 "help":"include unnecessary build time dependencies",
146 - "type":"choice",
147 "choices":("y", "n")
148 },
149 "--reinstall": {
150 "help":"specify conditions to trigger package reinstallation",
151 - "type":"choice",
152 "choices":["changed-use"]
153 },
154
155 @@ -494,21 +476,18 @@ def parse_opts(tmpcmdline, silent=False):
156 "--binpkg-respect-use": {
157 "help" : "discard binary packages if their use flags \
158 don't match the current configuration",
159 - "type" : "choice",
160 "choices" : true_y_or_n
161 },
162
163 "--getbinpkg": {
164 "shortopt" : "-g",
165 "help" : "fetch binary packages",
166 - "type" : "choice",
167 "choices" : true_y_or_n
168 },
169
170 "--getbinpkgonly": {
171 "shortopt" : "-G",
172 "help" : "fetch binary packages only",
173 - "type" : "choice",
174 "choices" : true_y_or_n
175 },
176
177 @@ -537,7 +516,6 @@ def parse_opts(tmpcmdline, silent=False):
178
179 "--package-moves": {
180 "help" : "perform package moves when necessary",
181 - "type" : "choice",
182 "choices" : true_y_or_n
183 },
184
185 @@ -554,19 +532,16 @@ def parse_opts(tmpcmdline, silent=False):
186 "--quiet": {
187 "shortopt" : "-q",
188 "help" : "reduced or condensed output",
189 - "type" : "choice",
190 "choices" : true_y_or_n
191 },
192
193 "--quiet-build": {
194 "help" : "redirect build output to logs",
195 - "type" : "choice",
196 "choices" : true_y_or_n,
197 },
198
199 "--quiet-fail": {
200 "help" : "suppresses display of the build log on stdout",
201 - "type" : "choice",
202 "choices" : true_y_or_n,
203 },
204
205 @@ -575,7 +550,6 @@ def parse_opts(tmpcmdline, silent=False):
206 "operator dependencies can be satisfied by a newer slot, so that "
207 "older packages slots will become eligible for removal by the "
208 "--depclean action as soon as possible."),
209 - "type" : "choice",
210 "choices" : true_y_or_n
211 },
212
213 @@ -584,7 +558,6 @@ def parse_opts(tmpcmdline, silent=False):
214 "used at both build-time and run-time are built, " + \
215 "if the dependency is not already installed with the " + \
216 "same version and revision.",
217 - "type" : "choice",
218 "choices" : true_y_or_n
219 },
220
221 @@ -593,21 +566,18 @@ def parse_opts(tmpcmdline, silent=False):
222 "used at both build-time and run-time are built, " + \
223 "if the dependency is not already installed with the " + \
224 "same version. Revision numbers are ignored.",
225 - "type" : "choice",
226 "choices" : true_y_or_n
227 },
228
229 "--rebuild-if-unbuilt": {
230 "help" : "Rebuild packages when dependencies that are " + \
231 "used at both build-time and run-time are built.",
232 - "type" : "choice",
233 "choices" : true_y_or_n
234 },
235
236 "--rebuilt-binaries": {
237 "help" : "replace installed packages with binary " + \
238 "packages that have been rebuilt",
239 - "type" : "choice",
240 "choices" : true_y_or_n
241 },
242
243 @@ -624,7 +594,6 @@ def parse_opts(tmpcmdline, silent=False):
244
245 "--root-deps": {
246 "help" : "modify interpretation of depedencies",
247 - "type" : "choice",
248 "choices" :("True", "rdeps")
249 },
250
251 @@ -632,19 +601,16 @@ def parse_opts(tmpcmdline, silent=False):
252 "shortopt" : "-w",
253 "help" : "add specified packages to the world set " + \
254 "(inverse of --oneshot)",
255 - "type" : "choice",
256 "choices" : true_y_or_n
257 },
258
259 "--selective": {
260 "help" : "identical to --noreplace",
261 - "type" : "choice",
262 "choices" : true_y_or_n
263 },
264
265 "--use-ebuild-visibility": {
266 "help" : "use unbuilt ebuild metadata for visibility checks on built packages",
267 - "type" : "choice",
268 "choices" : true_y_or_n
269 },
270
271 @@ -658,41 +624,35 @@ def parse_opts(tmpcmdline, silent=False):
272 "--usepkg": {
273 "shortopt" : "-k",
274 "help" : "use binary packages",
275 - "type" : "choice",
276 "choices" : true_y_or_n
277 },
278
279 "--usepkgonly": {
280 "shortopt" : "-K",
281 "help" : "use only binary packages",
282 - "type" : "choice",
283 "choices" : true_y_or_n
284 },
285
286 "--verbose": {
287 "shortopt" : "-v",
288 "help" : "verbose output",
289 - "type" : "choice",
290 "choices" : true_y_or_n
291 },
292 }
293
294 - from optparse import OptionParser
295 - parser = OptionParser()
296 - if parser.has_option("--help"):
297 - parser.remove_option("--help")
298 + parser = ArgumentParser(add_help=False)
299
300 for action_opt in actions:
301 - parser.add_option("--" + action_opt, action="store_true",
302 + parser.add_argument("--" + action_opt, action="store_true",
303 dest=action_opt.replace("-", "_"), default=False)
304 for myopt in options:
305 - parser.add_option(myopt, action="store_true",
306 + parser.add_argument(myopt, action="store_true",
307 dest=myopt.lstrip("--").replace("-", "_"), default=False)
308 for shortopt, longopt in shortmapping.items():
309 - parser.add_option("-" + shortopt, action="store_true",
310 + parser.add_argument("-" + shortopt, action="store_true",
311 dest=longopt.lstrip("--").replace("-", "_"), default=False)
312 for myalias, myopt in longopt_aliases.items():
313 - parser.add_option(myalias, action="store_true",
314 + parser.add_argument(myalias, action="store_true",
315 dest=myopt.lstrip("--").replace("-", "_"), default=False)
316
317 for myopt, kwargs in argument_options.items():
318 @@ -700,12 +660,12 @@ def parse_opts(tmpcmdline, silent=False):
319 args = [myopt]
320 if shortopt is not None:
321 args.append(shortopt)
322 - parser.add_option(dest=myopt.lstrip("--").replace("-", "_"),
323 + parser.add_argument(dest=myopt.lstrip("--").replace("-", "_"),
324 *args, **kwargs)
325
326 tmpcmdline = insert_optional_args(tmpcmdline)
327
328 - myoptions, myargs = parser.parse_args(args=tmpcmdline)
329 + myoptions, myargs = parser.parse_known_args(args=tmpcmdline)
330
331 if myoptions.ask in true_y:
332 myoptions.ask = True