From: Eduardo Habkost <ehabkost@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
John Snow <jsnow@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH for-2.11 v2 1/5] qmp-shell: Use optparse module
Date: Tue, 15 Aug 2017 17:06:46 -0300 [thread overview]
Message-ID: <20170815200646.GX3108@localhost.localdomain> (raw)
In-Reply-To: <20170815095607.GF9674@redhat.com>
On Tue, Aug 15, 2017 at 10:56:07AM +0100, Daniel P. Berrange wrote:
> On Tue, Aug 15, 2017 at 11:47:28AM +0200, Markus Armbruster wrote:
> > Eduardo Habkost <ehabkost@redhat.com> writes:
> >
> > > It makes command-line parsing and generation of help text much
> > > simpler.
> >
> > There's really no excuse for parsing command line arguments by hand in
> > Python.
> >
> > > The optparse module is deprecated since Python 2.7, but argparse
> > > is not available in Python 2.6 (the minimum Python version
> > > required for building QEMU).
> >
> > We have a few uses of argparse in the tree. Are they okay?
> >
> > We also use getopt in places. Perhaps we should pick one way to parse
> > command lines and stick to it.
>
> I just came up against this problem with keycodemapdb which I'm adding as
> a submodule to qemu. I used argparse there because it is the modern
> recommended API for python >= 2.7. I examined possibilty of using
> optparse instead, but it lacks key features - in particular the idea
> of 'subcommands' is entirely missing from optparse.
>
> The 'argparse' module is part of python core, but is *also* available
> as a standalone module that is implemented in terms of optparse.
>
> So, I would suggest that we just copy the 'argparse' module into the
> QEMU 'scripts/thirdparty' directory.
>
> Then in any files which need argparse, you can do this
>
> try:
> import argparse
> except:
> import os, sys
> sys.path.append(os.path.join(os.path.dirname(__file__), "thirdparty"))
> import argparse
What about:
try:
import argparse
except:
from thirdparty import argparse
(I think we could move all our Python modules [qemu.py, qmp.py]
to ./scripts/qemu/, so this would become "qemu.thirdparty").
>
> so that it tries to use the argparse provided by python, and falls back
> to pulling in the one in our scripts/thirdparty directory.
>
> When we finally bump our min python to 2.7, we can simply drop this
> compat code for the import statement. This avoids need for us to
> re-write code to use a deprecated API, with a worse feature set.
Sounds good to me.
--
Eduardo
next prev parent reply other threads:[~2017-08-15 20:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 20:39 [Qemu-devel] [PATCH for-2.11 v2 0/5] qmp-shell non-interactive mode, delete scripts/qmp/qmp Eduardo Habkost
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 1/5] qmp-shell: Use optparse module Eduardo Habkost
2017-08-09 9:17 ` Stefan Hajnoczi
2017-08-15 9:47 ` Markus Armbruster
2017-08-15 9:56 ` Daniel P. Berrange
2017-08-15 20:06 ` Eduardo Habkost [this message]
2017-08-18 15:42 ` Stefan Hajnoczi
2017-08-15 9:59 ` Daniel P. Berrange
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 2/5] qmp-shell: Pass split cmdargs to __build_cmd() Eduardo Habkost
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 3/5] qmp-shell: execute_cmdargs() method Eduardo Habkost
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 4/5] qmp-shell: Accept QMP command as argument Eduardo Habkost
2017-08-09 9:15 ` Stefan Hajnoczi
2017-08-15 10:03 ` Markus Armbruster
2017-08-15 20:39 ` Eduardo Habkost
2017-08-16 6:25 ` Markus Armbruster
2017-08-18 17:05 ` Eduardo Habkost
2017-08-21 9:22 ` Markus Armbruster
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 5/5] Remove scripts/qmp/qmp Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170815200646.GX3108@localhost.localdomain \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=jsnow@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).