1 |
commit: b2608987bf726600397a455638464cffd6af47a7 |
2 |
Author: Sebastian Pipping <sebastian <AT> pipping <DOT> org> |
3 |
AuthorDate: Sun Feb 21 19:36:19 2016 +0000 |
4 |
Commit: Sebastian Pipping <sping <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Feb 21 21:49:14 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/metagen.git/commit/?id=b2608987 |
7 |
|
8 |
Minimal migration to argparse |
9 |
|
10 |
metagen/main.py | 34 ++++++++++++++++------------------ |
11 |
1 file changed, 16 insertions(+), 18 deletions(-) |
12 |
|
13 |
diff --git a/metagen/main.py b/metagen/main.py |
14 |
index d9aded4..d243c24 100755 |
15 |
--- a/metagen/main.py |
16 |
+++ b/metagen/main.py |
17 |
@@ -14,7 +14,7 @@ EXAMPLES - man metagen |
18 |
import re |
19 |
import os |
20 |
import sys |
21 |
-from optparse import OptionParser |
22 |
+from argparse import ArgumentParser |
23 |
from commands import getstatusoutput |
24 |
|
25 |
from portage import config |
26 |
@@ -110,50 +110,48 @@ def validate_xml(my_xml): |
27 |
|
28 |
|
29 |
if __name__ == '__main__': |
30 |
- optParser = OptionParser(version=__version__) |
31 |
- optParser.add_option("-H", action="store", dest="herd", type="string", |
32 |
+ parser = ArgumentParser(prog='metagen') |
33 |
+ parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) |
34 |
+ |
35 |
+ parser.add_argument("-H", action="store", dest="herd", |
36 |
help="Name of herd. If not specified, It will be empty. " + |
37 |
"This requires either the -e or -m option.") |
38 |
|
39 |
- optParser.add_option("-e", action="store", dest="email", type="string", |
40 |
+ parser.add_argument("-e", action="store", dest="email", |
41 |
help="Maintainer's email address") |
42 |
|
43 |
- optParser.add_option("-n", action="store", dest="name", type="string", |
44 |
+ parser.add_argument("-n", action="store", dest="name", |
45 |
help="Maintainer's name") |
46 |
|
47 |
- optParser.add_option("-m", action="store_true", dest="echangelog", |
48 |
+ parser.add_argument("-m", action="store_true", dest="echangelog", |
49 |
default=False, |
50 |
help="Use name and email address from ECHANGELOG_USER "+ |
51 |
"environmental variable. "+ |
52 |
"This is a shortcut for -e <email> -n <name>") |
53 |
|
54 |
- optParser.add_option("-d", action="store", dest="desc", type="string", |
55 |
+ parser.add_argument("-d", action="store", dest="desc", |
56 |
help="Description of maintainership") |
57 |
|
58 |
- optParser.add_option("-l", action="store", dest="long", type="string", |
59 |
+ parser.add_argument("-l", action="store", dest="long", |
60 |
help="Long description of package.") |
61 |
|
62 |
- optParser.add_option("-o", action="store", dest="output", type="string", |
63 |
+ parser.add_argument("-o", action="store", dest="output", |
64 |
help="Specify location of output file.") |
65 |
|
66 |
- optParser.add_option("-f", action="store_true", dest="force", default=False, |
67 |
+ parser.add_argument("-f", action="store_true", dest="force", default=False, |
68 |
help="Force overwrite of existing metadata.") |
69 |
|
70 |
- optParser.add_option("-v", action="store_true", dest="verbose", default=True, |
71 |
+ parser.add_argument("-v", action="store_true", dest="verbose", default=True, |
72 |
help="Verbose. Output of file to stdout. (default)") |
73 |
|
74 |
- optParser.add_option("-q", action="store_false", dest="verbose", |
75 |
+ parser.add_argument("-q", action="store_false", dest="verbose", |
76 |
help="Squelch output of file to stdout.") |
77 |
|
78 |
- optParser.add_option("-Q", action="store_true", dest="no_write", |
79 |
+ parser.add_argument("-Q", action="store_true", dest="no_write", |
80 |
default=False, |
81 |
help="Do not write file to disk.") |
82 |
|
83 |
- (options, remainingArgs) = optParser.parse_args() |
84 |
- |
85 |
- if len(sys.argv) == 1: |
86 |
- optParser.print_help() |
87 |
- sys.exit(1) |
88 |
+ options = parser.parse_args() |
89 |
|
90 |
if options.desc or options.name: |
91 |
if not options.email and not options.echangelog: |