[PATCH v2 06/18] python: backport 'qmp-shell: add common_parser()'

John Snow posted 18 patches 5 months, 1 week ago
Maintainers: John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
There is a newer version of this series
[PATCH v2 06/18] python: backport 'qmp-shell: add common_parser()'
Posted by John Snow 5 months, 1 week ago
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit 20a88c2471f37d10520b2409046d59e1d0f1e905
Signed-off-by: John Snow <jsnow@redhat.com>
---
 python/qemu/qmp/qmp_shell.py | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/python/qemu/qmp/qmp_shell.py b/python/qemu/qmp/qmp_shell.py
index 98e684e9e8a..02028e94b5a 100644
--- a/python/qemu/qmp/qmp_shell.py
+++ b/python/qemu/qmp/qmp_shell.py
@@ -514,21 +514,27 @@ def die(msg: str) -> NoReturn:
     sys.exit(1)
 
 
+def common_parser() -> argparse.ArgumentParser:
+    """Build common parsing options used by qmp-shell and qmp-shell-wrap."""
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-H', '--hmp', action='store_true',
+                        help='Use HMP interface')
+    parser.add_argument('-v', '--verbose', action='store_true',
+                        help='Verbose (echo commands sent and received)')
+    parser.add_argument('-p', '--pretty', action='store_true',
+                        help='Pretty-print JSON')
+    parser.add_argument('-l', '--logfile',
+                        help='Save log of all QMP messages to PATH')
+    return parser
+
+
 def main() -> None:
     """
     qmp-shell entry point: parse command line arguments and start the REPL.
     """
-    parser = argparse.ArgumentParser()
-    parser.add_argument('-H', '--hmp', action='store_true',
-                        help='Use HMP interface')
+    parser = common_parser()
     parser.add_argument('-N', '--skip-negotiation', action='store_true',
                         help='Skip negotiate (for qemu-ga)')
-    parser.add_argument('-v', '--verbose', action='store_true',
-                        help='Verbose (echo commands sent and received)')
-    parser.add_argument('-p', '--pretty', action='store_true',
-                        help='Pretty-print JSON')
-    parser.add_argument('-l', '--logfile',
-                        help='Save log of all QMP messages to PATH')
 
     default_server = os.environ.get('QMP_SOCKET')
     parser.add_argument('qmp_server', action='store',
@@ -564,16 +570,7 @@ def main_wrap() -> None:
     qmp-shell-wrap entry point: parse command line arguments and
     start the REPL.
     """
-    parser = argparse.ArgumentParser()
-    parser.add_argument('-H', '--hmp', action='store_true',
-                        help='Use HMP interface')
-    parser.add_argument('-v', '--verbose', action='store_true',
-                        help='Verbose (echo commands sent and received)')
-    parser.add_argument('-p', '--pretty', action='store_true',
-                        help='Pretty-print JSON')
-    parser.add_argument('-l', '--logfile',
-                        help='Save log of all QMP messages to PATH')
-
+    parser = common_parser()
     parser.add_argument('command', nargs=argparse.REMAINDER,
                         help='QEMU command line to invoke')
 
-- 
2.50.1
Re: [PATCH v2 06/18] python: backport 'qmp-shell: add common_parser()'
Posted by Daniel P. Berrangé 5 months ago
On Wed, Sep 03, 2025 at 01:11:12AM -0400, John Snow wrote:
> Signed-off-by: John Snow <jsnow@redhat.com>
> cherry picked from commit 20a88c2471f37d10520b2409046d59e1d0f1e905
> Signed-off-by: John Snow <jsnow@redhat.com>

Duplicate s-o-b

> ---
>  python/qemu/qmp/qmp_shell.py | 35 ++++++++++++++++-------------------
>  1 file changed, 16 insertions(+), 19 deletions(-)

Wierdly the diffstat when I looked qmp_shell.py is very different
from what your patch here shows, but the end result appears the
same. Perhaps one of us has different settings for $HOME/.gitconfig
that affects diff display

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>


> 
> diff --git a/python/qemu/qmp/qmp_shell.py b/python/qemu/qmp/qmp_shell.py
> index 98e684e9e8a..02028e94b5a 100644
> --- a/python/qemu/qmp/qmp_shell.py
> +++ b/python/qemu/qmp/qmp_shell.py
> @@ -514,21 +514,27 @@ def die(msg: str) -> NoReturn:
>      sys.exit(1)
>  
>  
> +def common_parser() -> argparse.ArgumentParser:
> +    """Build common parsing options used by qmp-shell and qmp-shell-wrap."""
> +    parser = argparse.ArgumentParser()
> +    parser.add_argument('-H', '--hmp', action='store_true',
> +                        help='Use HMP interface')
> +    parser.add_argument('-v', '--verbose', action='store_true',
> +                        help='Verbose (echo commands sent and received)')
> +    parser.add_argument('-p', '--pretty', action='store_true',
> +                        help='Pretty-print JSON')
> +    parser.add_argument('-l', '--logfile',
> +                        help='Save log of all QMP messages to PATH')
> +    return parser
> +
> +
>  def main() -> None:
>      """
>      qmp-shell entry point: parse command line arguments and start the REPL.
>      """
> -    parser = argparse.ArgumentParser()
> -    parser.add_argument('-H', '--hmp', action='store_true',
> -                        help='Use HMP interface')
> +    parser = common_parser()
>      parser.add_argument('-N', '--skip-negotiation', action='store_true',
>                          help='Skip negotiate (for qemu-ga)')
> -    parser.add_argument('-v', '--verbose', action='store_true',
> -                        help='Verbose (echo commands sent and received)')
> -    parser.add_argument('-p', '--pretty', action='store_true',
> -                        help='Pretty-print JSON')
> -    parser.add_argument('-l', '--logfile',
> -                        help='Save log of all QMP messages to PATH')
>  
>      default_server = os.environ.get('QMP_SOCKET')
>      parser.add_argument('qmp_server', action='store',
> @@ -564,16 +570,7 @@ def main_wrap() -> None:
>      qmp-shell-wrap entry point: parse command line arguments and
>      start the REPL.
>      """
> -    parser = argparse.ArgumentParser()
> -    parser.add_argument('-H', '--hmp', action='store_true',
> -                        help='Use HMP interface')
> -    parser.add_argument('-v', '--verbose', action='store_true',
> -                        help='Verbose (echo commands sent and received)')
> -    parser.add_argument('-p', '--pretty', action='store_true',
> -                        help='Pretty-print JSON')
> -    parser.add_argument('-l', '--logfile',
> -                        help='Save log of all QMP messages to PATH')
> -
> +    parser = common_parser()
>      parser.add_argument('command', nargs=argparse.REMAINDER,
>                          help='QEMU command line to invoke')
>  
> -- 
> 2.50.1
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2 06/18] python: backport 'qmp-shell: add common_parser()'
Posted by John Snow 5 months ago
On Mon, Sep 8, 2025 at 12:47 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Sep 03, 2025 at 01:11:12AM -0400, John Snow wrote:
> > Signed-off-by: John Snow <jsnow@redhat.com>
> > cherry picked from commit 20a88c2471f37d10520b2409046d59e1d0f1e905
> > Signed-off-by: John Snow <jsnow@redhat.com>
>
> Duplicate s-o-b

One is from the original commit, the other is from the backport.
Wasn't sure if that was truly needed, but figured it wouldn't hurt
anything.

>
> > ---
> >  python/qemu/qmp/qmp_shell.py | 35 ++++++++++++++++-------------------
> >  1 file changed, 16 insertions(+), 19 deletions(-)
>
> Wierdly the diffstat when I looked qmp_shell.py is very different
> from what your patch here shows, but the end result appears the
> same. Perhaps one of us has different settings for $HOME/.gitconfig
> that affects diff display

Possible. I didn't exactly take care to preserve the commits
themselves exactly as they were ...

>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>
>
> >
> > diff --git a/python/qemu/qmp/qmp_shell.py b/python/qemu/qmp/qmp_shell.py
> > index 98e684e9e8a..02028e94b5a 100644
> > --- a/python/qemu/qmp/qmp_shell.py
> > +++ b/python/qemu/qmp/qmp_shell.py
> > @@ -514,21 +514,27 @@ def die(msg: str) -> NoReturn:
> >      sys.exit(1)
> >
> >
> > +def common_parser() -> argparse.ArgumentParser:
> > +    """Build common parsing options used by qmp-shell and qmp-shell-wrap."""
> > +    parser = argparse.ArgumentParser()
> > +    parser.add_argument('-H', '--hmp', action='store_true',
> > +                        help='Use HMP interface')
> > +    parser.add_argument('-v', '--verbose', action='store_true',
> > +                        help='Verbose (echo commands sent and received)')
> > +    parser.add_argument('-p', '--pretty', action='store_true',
> > +                        help='Pretty-print JSON')
> > +    parser.add_argument('-l', '--logfile',
> > +                        help='Save log of all QMP messages to PATH')
> > +    return parser
> > +
> > +
> >  def main() -> None:
> >      """
> >      qmp-shell entry point: parse command line arguments and start the REPL.
> >      """
> > -    parser = argparse.ArgumentParser()
> > -    parser.add_argument('-H', '--hmp', action='store_true',
> > -                        help='Use HMP interface')
> > +    parser = common_parser()
> >      parser.add_argument('-N', '--skip-negotiation', action='store_true',
> >                          help='Skip negotiate (for qemu-ga)')
> > -    parser.add_argument('-v', '--verbose', action='store_true',
> > -                        help='Verbose (echo commands sent and received)')
> > -    parser.add_argument('-p', '--pretty', action='store_true',
> > -                        help='Pretty-print JSON')
> > -    parser.add_argument('-l', '--logfile',
> > -                        help='Save log of all QMP messages to PATH')
> >
> >      default_server = os.environ.get('QMP_SOCKET')
> >      parser.add_argument('qmp_server', action='store',
> > @@ -564,16 +570,7 @@ def main_wrap() -> None:
> >      qmp-shell-wrap entry point: parse command line arguments and
> >      start the REPL.
> >      """
> > -    parser = argparse.ArgumentParser()
> > -    parser.add_argument('-H', '--hmp', action='store_true',
> > -                        help='Use HMP interface')
> > -    parser.add_argument('-v', '--verbose', action='store_true',
> > -                        help='Verbose (echo commands sent and received)')
> > -    parser.add_argument('-p', '--pretty', action='store_true',
> > -                        help='Pretty-print JSON')
> > -    parser.add_argument('-l', '--logfile',
> > -                        help='Save log of all QMP messages to PATH')
> > -
> > +    parser = common_parser()
> >      parser.add_argument('command', nargs=argparse.REMAINDER,
> >                          help='QEMU command line to invoke')
> >
> > --
> > 2.50.1
> >
>
> With regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
>
Re: [PATCH v2 06/18] python: backport 'qmp-shell: add common_parser()'
Posted by Daniel P. Berrangé 5 months ago
On Mon, Sep 08, 2025 at 01:39:58PM -0400, John Snow wrote:
> On Mon, Sep 8, 2025 at 12:47 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Wed, Sep 03, 2025 at 01:11:12AM -0400, John Snow wrote:
> > > Signed-off-by: John Snow <jsnow@redhat.com>
> > > cherry picked from commit 20a88c2471f37d10520b2409046d59e1d0f1e905
> > > Signed-off-by: John Snow <jsnow@redhat.com>
> >
> > Duplicate s-o-b
> 
> One is from the original commit, the other is from the backport.
> Wasn't sure if that was truly needed, but figured it wouldn't hurt
> anything.

Yes, I realized when looking at later commits, that's fine.

> 
> >
> > > ---
> > >  python/qemu/qmp/qmp_shell.py | 35 ++++++++++++++++-------------------
> > >  1 file changed, 16 insertions(+), 19 deletions(-)
> >
> > Wierdly the diffstat when I looked qmp_shell.py is very different
> > from what your patch here shows, but the end result appears the
> > same. Perhaps one of us has different settings for $HOME/.gitconfig
> > that affects diff display
> 
> Possible. I didn't exactly take care to preserve the commits
> themselves exactly as they were ...



With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|