1 |
commit: 510e60106fdd7e12bfef37aa6d494f060bf30857 |
2 |
Author: Slawek Lis <slis <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Mar 26 08:18:45 2014 +0000 |
4 |
Commit: Slawek Lis <slis <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Mar 26 08:18:45 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=510e6010 |
7 |
|
8 |
Switch from getopt to argparse |
9 |
|
10 |
--- |
11 |
pym/gentoolkit/revdep_rebuild/settings.py | 137 ++++++++++++++---------------- |
12 |
1 file changed, 64 insertions(+), 73 deletions(-) |
13 |
|
14 |
diff --git a/pym/gentoolkit/revdep_rebuild/settings.py b/pym/gentoolkit/revdep_rebuild/settings.py |
15 |
index 7909aa6..4774cec 100644 |
16 |
--- a/pym/gentoolkit/revdep_rebuild/settings.py |
17 |
+++ b/pym/gentoolkit/revdep_rebuild/settings.py |
18 |
@@ -4,7 +4,7 @@ |
19 |
|
20 |
from __future__ import print_function |
21 |
|
22 |
-import getopt |
23 |
+import argparse |
24 |
import os |
25 |
import sys |
26 |
import re |
27 |
@@ -48,84 +48,75 @@ DEFAULTS = { |
28 |
} |
29 |
|
30 |
|
31 |
-def print_usage(): |
32 |
- """Outputs the help message""" |
33 |
- print( APP_NAME + ': (' + VERSION +')') |
34 |
- print() |
35 |
- print('This is free software; see the source for copying conditions.') |
36 |
- print() |
37 |
- print('Usage: ' + APP_NAME + ' [OPTIONS] [--] [EMERGE_OPTIONS]') |
38 |
- print() |
39 |
- print('Broken reverse dependency rebuilder, python implementation.') |
40 |
- print() |
41 |
- print('Available options:') |
42 |
- print(''' |
43 |
- -C, --nocolor Turn off colored output |
44 |
- -d, --debug Print debug informations |
45 |
- -e, --exact Emerge based on exact package version |
46 |
- -h, --help Print this usage |
47 |
- -i, --ignore Ignore temporary files from previous runs |
48 |
- (also won't create any) |
49 |
- -L, --library NAME Unconditionally emerge existing packages that use |
50 |
- --library=NAME the library with NAME. NAME can be a full or partial |
51 |
- library name |
52 |
- -l, --no-ld-path Do not set LD_LIBRARY_PATH |
53 |
- -o, --no-order Do not check the build order |
54 |
- (Saves time, but may cause breakage.) |
55 |
- -p, --pretend Do a trial run without actually emerging anything |
56 |
- (also passed to emerge command) |
57 |
- -q, --quiet Be less verbose (also passed to emerge command) |
58 |
- -v, --verbose Be more verbose (also passed to emerge command) |
59 |
-''') |
60 |
- print( 'Calls emerge, options after -- are ignored by ' + APP_NAME) |
61 |
- print('and passed directly to emerge.') |
62 |
- |
63 |
- |
64 |
def parse_options(): |
65 |
"""Parses the command line options an sets settings accordingly""" |
66 |
|
67 |
# TODO: Verify: options: no-ld-path, no-order, no-progress |
68 |
#are not appliable |
69 |
- |
70 |
+ from rebuild import VERSION, APP_NAME |
71 |
settings = DEFAULTS.copy() |
72 |
- try: |
73 |
- opts, args = getopt.getopt(sys.argv[1:], |
74 |
- 'dehiklopqvCL:P', |
75 |
- ['nocolor', 'debug', 'exact', 'help', 'ignore', |
76 |
- 'keep-temp', 'library=', 'no-ld-path', 'no-order', |
77 |
- 'pretend', 'no-pretend', 'no-progress', 'quiet', 'verbose']) |
78 |
- |
79 |
- for key, val in opts: |
80 |
- if key in ('-h', '--help'): |
81 |
- print_usage() |
82 |
- sys.exit(0) |
83 |
- elif key in ('-q', '--quiet'): |
84 |
- settings['quiet'] = True |
85 |
- settings['VERBOSITY'] = 0 |
86 |
- elif key in ('-v', '--verbose'): |
87 |
- settings['VERBOSITY'] = 2 |
88 |
- elif key in ('-d', '--debug'): |
89 |
- settings['debug'] = True |
90 |
- settings['VERBOSITY'] = 3 |
91 |
- elif key in ('-p', '--pretend'): |
92 |
- settings['PRETEND'] = True |
93 |
- elif key == '--no-pretend': |
94 |
- settings['NO_PRETEND'] = True |
95 |
- elif key in ('-e', '--exact'): |
96 |
- settings['EXACT'] = True |
97 |
- elif key in ('-C', '--nocolor', '--no-color'): |
98 |
- settings['nocolor'] = True |
99 |
- elif key in ('-L', '--library', '--library='): |
100 |
- settings['library'].update(val.split(',')) |
101 |
- elif key in ('-i', '--ignore'): |
102 |
- settings['USE_TMP_FILES'] = False |
103 |
- |
104 |
- settings['pass_through_options'] = " " + " ".join(args) |
105 |
- except getopt.GetoptError: |
106 |
- #logging.info(red('Unrecognized option\n')) |
107 |
- print(red('Unrecognized option\n')) |
108 |
- print_usage() |
109 |
- sys.exit(2) |
110 |
+ |
111 |
+ parser = argparse.ArgumentParser( |
112 |
+ description='Broken reverse dependency rebuilder, python implementation.', |
113 |
+ epilog='Calls emerge, options after -- are ignored by %s ' |
114 |
+ 'and passed directly to emerge.' % APP_NAME, |
115 |
+ add_help=False |
116 |
+ ) |
117 |
+ |
118 |
+ parser.add_argument('-h', '--help', |
119 |
+ action='help', |
120 |
+ help='Print this usage and exit') |
121 |
+ parser.add_argument('-V', '--version', |
122 |
+ action='version', |
123 |
+ help='Show version informations', |
124 |
+ version='%(prog)s ' + VERSION) |
125 |
+ |
126 |
+ parser.add_argument('-i', '--ignore', |
127 |
+ action='store_true', |
128 |
+ help='Ignore temporary files from previous runs ' |
129 |
+ '(also won\'t create any)') |
130 |
+ |
131 |
+ parser.add_argument('-L', '--library', |
132 |
+ action='append', |
133 |
+ help='Unconditionally emerge existing packages that use ' |
134 |
+ 'the library with NAME. NAME can be a full or partial ' |
135 |
+ 'name') |
136 |
+ parser.add_argument('-l', '--no-ld-path', |
137 |
+ action='store_true', |
138 |
+ help='Do not set LD_LIBRARY_PATH') |
139 |
+ parser.add_argument('-o', '--no-order', |
140 |
+ action='store_true', |
141 |
+ help='Do not check the build order ' |
142 |
+ '(Saves time, but may cause breakage.)') |
143 |
+ parser.add_argument('-p', '--pretend', |
144 |
+ action='store_true', |
145 |
+ help='Do a trial run without actually emerging anything ' |
146 |
+ '(also passed to emerge command)') |
147 |
+ |
148 |
+ parser.add_argument('-C', '--nocolor', |
149 |
+ action='store_true', |
150 |
+ help='Turn off colored output') |
151 |
+ parser.add_argument('-q', '--quiet', |
152 |
+ action='store_true', |
153 |
+ help='Be less verbose (also passed to emerge command)') |
154 |
+ parser.add_argument('-v', '--verbose', |
155 |
+ action='store_true', |
156 |
+ help='Be more verbose (also passed to emerge command)') |
157 |
+ parser.add_argument('-d', '--debug', |
158 |
+ action='store_true', |
159 |
+ help='Print debug informations') |
160 |
+ |
161 |
+ parser.add_argument('portage_options', nargs='*') |
162 |
+ |
163 |
+ args = parser.parse_args() |
164 |
+ |
165 |
+ settings['VERBOSITY'] = 3 if args.debug else 2 if args.verbose else 0 if args.quiet else 1 |
166 |
+ settings['quiet'] = args.quiet |
167 |
+ settings['PRETEND'] = args.pretend |
168 |
+ settings['nocolor'] = args.nocolor |
169 |
+ settings['library'].update(set(args.library)) |
170 |
+ settings['USE_TMP_FILES'] = not args.ignore |
171 |
+ settings['pass_through_options'] = " " + " ".join(args.portage_options) |
172 |
|
173 |
return settings |