qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3
@ 2019-06-18 14:29 Igor Mammedov
  2019-06-19 13:29 ` Cleber Rosa
  0 siblings, 1 reply; 5+ messages in thread
From: Igor Mammedov @ 2019-06-18 14:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: armbru, ehabkost, crosa

python3 doesn't have raw_input(), so qmp-shell breaks.
Use input() instead and override it with raw_input()
if running on python2.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 scripts/qmp/qmp-shell | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 7776c7b141..8c49b39afa 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -308,7 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
         @return True if execution was ok, return False if disconnected.
         """
         try:
-            cmdline = raw_input(prompt)
+            try: # attempt to set Python2 override
+               import __builtin__;
+               getattr(__builtin__, 'raw_input', input)
+            except ModuleNotFoundError: pass
+            cmdline = input(prompt)
         except EOFError:
             print()
             return False
-- 
2.18.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3
  2019-06-18 14:29 [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3 Igor Mammedov
@ 2019-06-19 13:29 ` Cleber Rosa
  2019-06-20  9:11   ` Igor Mammedov
  0 siblings, 1 reply; 5+ messages in thread
From: Cleber Rosa @ 2019-06-19 13:29 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: armbru, qemu-devel, ehabkost

On Tue, Jun 18, 2019 at 10:29:31AM -0400, Igor Mammedov wrote:
> python3 doesn't have raw_input(), so qmp-shell breaks.
> Use input() instead and override it with raw_input()
> if running on python2.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  scripts/qmp/qmp-shell | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> index 7776c7b141..8c49b39afa 100755
> --- a/scripts/qmp/qmp-shell
> +++ b/scripts/qmp/qmp-shell
> @@ -308,7 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
>          @return True if execution was ok, return False if disconnected.
>          """
>          try:
> -            cmdline = raw_input(prompt)
> +            try: # attempt to set Python2 override
> +               import __builtin__;
> +               getattr(__builtin__, 'raw_input', input)
> +            except ModuleNotFoundError: pass

Something like:

   if sys.version_info[0] == 2:
       input = raw_input

Also does the job, and may be considered simpler and easier to read.

- Cleber.

> +            cmdline = input(prompt)
>          except EOFError:
>              print()
>              return False
> -- 
> 2.18.1
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3
  2019-06-19 13:29 ` Cleber Rosa
@ 2019-06-20  9:11   ` Igor Mammedov
  2019-06-20 13:45     ` Eduardo Habkost
  0 siblings, 1 reply; 5+ messages in thread
From: Igor Mammedov @ 2019-06-20  9:11 UTC (permalink / raw)
  To: Cleber Rosa; +Cc: armbru, ehabkost, qemu-devel

On Wed, 19 Jun 2019 09:29:24 -0400
Cleber Rosa <crosa@redhat.com> wrote:

> On Tue, Jun 18, 2019 at 10:29:31AM -0400, Igor Mammedov wrote:
> > python3 doesn't have raw_input(), so qmp-shell breaks.
> > Use input() instead and override it with raw_input()
> > if running on python2.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  scripts/qmp/qmp-shell | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> > index 7776c7b141..8c49b39afa 100755
> > --- a/scripts/qmp/qmp-shell
> > +++ b/scripts/qmp/qmp-shell
> > @@ -308,7 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> >          @return True if execution was ok, return False if disconnected.
> >          """
> >          try:
> > -            cmdline = raw_input(prompt)
> > +            try: # attempt to set Python2 override
> > +               import __builtin__;
> > +               getattr(__builtin__, 'raw_input', input)
> > +            except ModuleNotFoundError: pass  
> 
> Something like:
> 
>    if sys.version_info[0] == 2:
>        input = raw_input
> 
> Also does the job, and may be considered simpler and easier to read.

that causes scope issues on python3

> 
> - Cleber.
> 
> > +            cmdline = input(prompt)
> >          except EOFError:
> >              print()
> >              return False
> > -- 
> > 2.18.1
> >   
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3
  2019-06-20  9:11   ` Igor Mammedov
@ 2019-06-20 13:45     ` Eduardo Habkost
  2019-06-20 15:16       ` Igor Mammedov
  0 siblings, 1 reply; 5+ messages in thread
From: Eduardo Habkost @ 2019-06-20 13:45 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, armbru, Cleber Rosa

On Thu, Jun 20, 2019 at 11:11:03AM +0200, Igor Mammedov wrote:
> On Wed, 19 Jun 2019 09:29:24 -0400
> Cleber Rosa <crosa@redhat.com> wrote:
> 
> > On Tue, Jun 18, 2019 at 10:29:31AM -0400, Igor Mammedov wrote:
> > > python3 doesn't have raw_input(), so qmp-shell breaks.
> > > Use input() instead and override it with raw_input()
> > > if running on python2.
> > > 
> > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > ---
> > >  scripts/qmp/qmp-shell | 6 +++++-
> > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> > > index 7776c7b141..8c49b39afa 100755
> > > --- a/scripts/qmp/qmp-shell
> > > +++ b/scripts/qmp/qmp-shell
> > > @@ -308,7 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> > >          @return True if execution was ok, return False if disconnected.
> > >          """
> > >          try:
> > > -            cmdline = raw_input(prompt)
> > > +            try: # attempt to set Python2 override
> > > +               import __builtin__;
> > > +               getattr(__builtin__, 'raw_input', input)
> > > +            except ModuleNotFoundError: pass  
> > 
> > Something like:
> > 
> >    if sys.version_info[0] == 2:
> >        input = raw_input
> > 
> > Also does the job, and may be considered simpler and easier to read.
> 
> that causes scope issues on python3

Which issues?  It should work if you set it at the module top
level.  We had done this before in other scripts.  e.g.:

$ git grep -1 'range = xrange'
tests/qemu-iotests/044-if sys.version_info.major == 2:
tests/qemu-iotests/044:    range = xrange
tests/qemu-iotests/044-
--
tests/qemu-iotests/163-if sys.version_info.major == 2:
tests/qemu-iotests/163:    range = xrange
tests/qemu-iotests/163-


-- 
Eduardo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3
  2019-06-20 13:45     ` Eduardo Habkost
@ 2019-06-20 15:16       ` Igor Mammedov
  0 siblings, 0 replies; 5+ messages in thread
From: Igor Mammedov @ 2019-06-20 15:16 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, armbru, Cleber Rosa

On Thu, 20 Jun 2019 10:45:24 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Thu, Jun 20, 2019 at 11:11:03AM +0200, Igor Mammedov wrote:
> > On Wed, 19 Jun 2019 09:29:24 -0400
> > Cleber Rosa <crosa@redhat.com> wrote:
> >   
> > > On Tue, Jun 18, 2019 at 10:29:31AM -0400, Igor Mammedov wrote:  
> > > > python3 doesn't have raw_input(), so qmp-shell breaks.
> > > > Use input() instead and override it with raw_input()
> > > > if running on python2.
> > > > 
> > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > > ---
> > > >  scripts/qmp/qmp-shell | 6 +++++-
> > > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> > > > index 7776c7b141..8c49b39afa 100755
> > > > --- a/scripts/qmp/qmp-shell
> > > > +++ b/scripts/qmp/qmp-shell
> > > > @@ -308,7 +308,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> > > >          @return True if execution was ok, return False if disconnected.
> > > >          """
> > > >          try:
> > > > -            cmdline = raw_input(prompt)
> > > > +            try: # attempt to set Python2 override
> > > > +               import __builtin__;
> > > > +               getattr(__builtin__, 'raw_input', input)
> > > > +            except ModuleNotFoundError: pass    
> > > 
> > > Something like:
> > > 
> > >    if sys.version_info[0] == 2:
> > >        input = raw_input
> > > 
> > > Also does the job, and may be considered simpler and easier to read.  
> > 
> > that causes scope issues on python3  
> 
> Which issues?  It should work if you set it at the module top
> level.  We had done this before in other scripts.  e.g.:

it works if it is moved to the top, I'll post v2

> $ git grep -1 'range = xrange'
> tests/qemu-iotests/044-if sys.version_info.major == 2:
> tests/qemu-iotests/044:    range = xrange
> tests/qemu-iotests/044-
> --
> tests/qemu-iotests/163-if sys.version_info.major == 2:
> tests/qemu-iotests/163:    range = xrange
> tests/qemu-iotests/163-
> 
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-20 15:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 14:29 [Qemu-devel] [PATCH] qmp: make qmp-shell work with python3 Igor Mammedov
2019-06-19 13:29 ` Cleber Rosa
2019-06-20  9:11   ` Igor Mammedov
2019-06-20 13:45     ` Eduardo Habkost
2019-06-20 15:16       ` Igor Mammedov

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).