From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28788 invoked by alias); 22 Oct 2011 01:22:23 -0000 Received: (qmail 28778 invoked by uid 22791); 22 Oct 2011 01:22:22 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ausc60ps301.us.dell.com (HELO ausc60ps301.us.dell.com) (143.166.148.206) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 22 Oct 2011 01:22:03 +0000 X-Loopcount0: from 10.170.28.39 From: To: , Date: Sun, 23 Oct 2011 21:00:00 -0000 Subject: RE: Option parsing in gdb python Message-ID: <09787EF419216C41A903FD14EE5506DD030CE5DD39@AUSX7MCPC103.AMER.DELL.COM> References: In-Reply-To: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-10/txt/msg00169.txt.bz2 Since argparse is the successor to optparse and is easier to use and more e= xtensible, would you consider doing this in argparse instead? paul -----Original Message----- From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf = Of Robert Lupton the Good Sent: Friday, October 21, 2011 9:19 PM To: gdb@sourceware.org Subject: Option parsing in gdb python I just spent a few minutes fiddling with optparse (deprecated in python 2.7= , but I don't think I care) to make it usable from gdb python (the problem = is that by default it uses sys.argv[0] for help messages, and exits on erro= r). With my subclass you can say e.g. parser =3D GdbOptionParser("show image [opts] [nx [ny]]") parser.add_option("-a", "--all", action=3D"store_true", help=3D= "Display the whole image/mask") parser.add_option("-w", "--width", type=3D"int", default=3D8, h= elp=3D"Field width for pixels") (opts, args) =3D parser.parse_args(args) and things "just work". I'd be happy to donate the code to fsf/gdb R import gdb import optparse class GdbOptionParser(optparse.OptionParser): def __init__(self, usage, *args, **kwargs): optparse.OptionParser.__init__(self, *args, **kwargs) # OptionParse= r is an old-style class self.set_usage(usage) def parse_args(self, args, values=3DNone): """Call optparse.OptionParser.parse_args after running gdb.string_t= o_argv on args""" return optparse.OptionParser.parse_args(self, gdb.string_to_argv(ar= gs), values) def exit(self, status=3D0, msg=3DNone): raise gdb.GdbError(msg)