From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6798 invoked by alias); 24 Oct 2011 21:06:03 -0000 Received: (qmail 6788 invoked by uid 22791); 24 Oct 2011 21:06:02 -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 kay.astro.Princeton.EDU (HELO mail.astro.princeton.edu) (128.112.24.221) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Oct 2011 21:05:48 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astro.princeton.edu (Postfix) with ESMTP id 607EA1BC00724 for ; Mon, 24 Oct 2011 17:05:47 -0400 (EDT) Received: from mail.astro.princeton.edu ([127.0.0.1]) by localhost (kay.astro.princeton.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id A4htdvzQ9UuP for ; Mon, 24 Oct 2011 17:05:47 -0400 (EDT) X-Submitted: to mail.astro.princeton.edu (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: rhl) with ESMTP for ; Mon, 24 Oct 2011 17:05:47 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Apple Message framework v1251.1) Subject: RE: Option parsing in gdb python From: Robert Lupton the Good In-Reply-To: <1319403653.11425.ezmlm@sourceware.org> Date: Mon, 24 Oct 2011 21:28:00 -0000 Content-Transfer-Encoding: quoted-printable Message-Id: <1C69408D-CEF9-4B86-A2E2-4A7547F069D9@astro.princeton.edu> References: <1319403653.11425.ezmlm@sourceware.org> To: gdb@sourceware.org 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/msg00177.txt.bz2 Paul Koning wrote: > Since argparse is the successor to optparse and is easier to use and more= extensible, would you consider doing this in argparse instead? I can do this (and did; read on, Dear Reader). Does gdb python have a posi= tion on python 2.6 support? If so, and if gdb accepts this parser, we shou= ld provide both and wrap the imports in try blocks try: import argparse =85 except ImportError: pass etc. OK, using argparse here goes: parser =3D GdbArgumentParser("show image") parser.add_argument("-a", "--all", action=3D"store_true", help= =3D"Display the whole image/mask") parser.add_argument("image", help=3D"Expression giving image to = show") parser.add_argument("width", help=3D"Width of patch to print", d= efault=3D1, nargs=3D"?") opts =3D parser.parse_args(args) R import argparse class GdbArgumentParser(argparse.ArgumentParser): def parse_args(self, args=3DNone, namespace=3DNone): if args: args =3D gdb.string_to_argv(args) return argparse.ArgumentParser.parse_args(self, args, namespace) =20=20=20=20=20=20=20=20 def exit(self, status=3D0, msg=3DNone): raise gdb.GdbError(msg)