From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 289DF1388C0 for ; Sun, 21 Feb 2016 22:15:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 71EF521C0FB; Sun, 21 Feb 2016 22:15:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 05BB121C0FB for ; Sun, 21 Feb 2016 22:15:01 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D7104340B9F for ; Sun, 21 Feb 2016 22:14:59 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8C0B81897 for ; Sun, 21 Feb 2016 22:14:55 +0000 (UTC) From: "Sebastian Pipping" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sebastian Pipping" Message-ID: <1456091354.b2608987bf726600397a455638464cffd6af47a7.sping@gentoo> Subject: [gentoo-commits] proj/metagen:master commit in: metagen/ X-VCS-Repository: proj/metagen X-VCS-Files: metagen/main.py X-VCS-Directories: metagen/ X-VCS-Committer: sping X-VCS-Committer-Name: Sebastian Pipping X-VCS-Revision: b2608987bf726600397a455638464cffd6af47a7 X-VCS-Branch: master Date: Sun, 21 Feb 2016 22:14:55 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d35ad391-a019-4509-8f37-03c82d3d5e87 X-Archives-Hash: c40401ac077a98ed64b2b8f506e14abc commit: b2608987bf726600397a455638464cffd6af47a7 Author: Sebastian Pipping pipping org> AuthorDate: Sun Feb 21 19:36:19 2016 +0000 Commit: Sebastian Pipping gentoo org> CommitDate: Sun Feb 21 21:49:14 2016 +0000 URL: https://gitweb.gentoo.org/proj/metagen.git/commit/?id=b2608987 Minimal migration to argparse metagen/main.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/metagen/main.py b/metagen/main.py index d9aded4..d243c24 100755 --- a/metagen/main.py +++ b/metagen/main.py @@ -14,7 +14,7 @@ EXAMPLES - man metagen import re import os import sys -from optparse import OptionParser +from argparse import ArgumentParser from commands import getstatusoutput from portage import config @@ -110,50 +110,48 @@ def validate_xml(my_xml): if __name__ == '__main__': - optParser = OptionParser(version=__version__) - optParser.add_option("-H", action="store", dest="herd", type="string", + parser = ArgumentParser(prog='metagen') + parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) + + parser.add_argument("-H", action="store", dest="herd", help="Name of herd. If not specified, It will be empty. " + "This requires either the -e or -m option.") - optParser.add_option("-e", action="store", dest="email", type="string", + parser.add_argument("-e", action="store", dest="email", help="Maintainer's email address") - optParser.add_option("-n", action="store", dest="name", type="string", + parser.add_argument("-n", action="store", dest="name", help="Maintainer's name") - optParser.add_option("-m", action="store_true", dest="echangelog", + parser.add_argument("-m", action="store_true", dest="echangelog", default=False, help="Use name and email address from ECHANGELOG_USER "+ "environmental variable. "+ "This is a shortcut for -e -n ") - optParser.add_option("-d", action="store", dest="desc", type="string", + parser.add_argument("-d", action="store", dest="desc", help="Description of maintainership") - optParser.add_option("-l", action="store", dest="long", type="string", + parser.add_argument("-l", action="store", dest="long", help="Long description of package.") - optParser.add_option("-o", action="store", dest="output", type="string", + parser.add_argument("-o", action="store", dest="output", help="Specify location of output file.") - optParser.add_option("-f", action="store_true", dest="force", default=False, + parser.add_argument("-f", action="store_true", dest="force", default=False, help="Force overwrite of existing metadata.") - optParser.add_option("-v", action="store_true", dest="verbose", default=True, + parser.add_argument("-v", action="store_true", dest="verbose", default=True, help="Verbose. Output of file to stdout. (default)") - optParser.add_option("-q", action="store_false", dest="verbose", + parser.add_argument("-q", action="store_false", dest="verbose", help="Squelch output of file to stdout.") - optParser.add_option("-Q", action="store_true", dest="no_write", + parser.add_argument("-Q", action="store_true", dest="no_write", default=False, help="Do not write file to disk.") - (options, remainingArgs) = optParser.parse_args() - - if len(sys.argv) == 1: - optParser.print_help() - sys.exit(1) + options = parser.parse_args() if options.desc or options.name: if not options.email and not options.echangelog: