[SRU][Bionic][Patch 1/2] tools/kvm_stat: fix python3 issues

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[SRU][Bionic][Patch 1/2] tools/kvm_stat: fix python3 issues

Juerg Haefliger
From: Stefan Raspl <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1798776

Python3 returns a float for a regular division - switch to a division
operator that returns an integer.
Furthermore, filters return a generator object instead of the actual
list - wrap result in yet another list, which makes it still work in
both, Python2 and 3.

Signed-off-by: Stefan Raspl <[hidden email]>
Signed-off-by: Radim Krčmář <[hidden email]>
(cherry picked from commit 58f33cfe73076b6497bada4f7b5bda961ed68083)
Signed-off-by: Juerg Haefliger <[hidden email]>
---
 tools/kvm/kvm_stat/kvm_stat | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index 56c4b3f8a01b..e10b90a8917a 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -759,7 +759,7 @@ class DebugfsProvider(Provider):
             if len(vms) == 0:
                 self.do_read = False
 
-            self.paths = filter(lambda x: "{}-".format(pid) in x, vms)
+            self.paths = list(filter(lambda x: "{}-".format(pid) in x, vms))
 
         else:
             self.paths = []
@@ -1219,10 +1219,10 @@ class Tui(object):
         (x, term_width) = self.screen.getmaxyx()
         row = 2
         for line in text:
-            start = (term_width - len(line)) / 2
+            start = (term_width - len(line)) // 2
             self.screen.addstr(row, start, line)
             row += 1
-        self.screen.addstr(row + 1, (term_width - len(hint)) / 2, hint,
+        self.screen.addstr(row + 1, (term_width - len(hint)) // 2, hint,
                            curses.A_STANDOUT)
         self.screen.getkey()
 
--
2.19.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[SRU][Bionic][Patch 2/2] tools/kvm_stat: switch to python3

Juerg Haefliger
From: Stefan Raspl <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1798776

The current shebang does not work in environments that only support python3
and have no python2 installed. Plus there does not seem to be a way to
support python2 and python3 at the same time. Since all known python3 issues
were fixed, and as python3 is the way to go, let's switch over.
Note that the code is still python2 compliant, so folks in bad use can
simply revert the shebang.

Suggested-by: Christian Ehrhardt <[hidden email]>
Signed-off-by: Stefan Raspl <[hidden email]>
Signed-off-by: Paolo Bonzini <[hidden email]>
(cherry picked from commit 09f70c3b70e7d9e209a820b54dda42502fa40711)
Signed-off-by: Juerg Haefliger <[hidden email]>
---
 tools/kvm/kvm_stat/kvm_stat | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index e10b90a8917a..aa4d404184a8 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 #
 # top-like utility for displaying kvm statistics
 #
--
2.19.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU][Bionic][Patch 1+2/2] tools/kvm_stat: fix python3 issues

Stefan Bader-2
In reply to this post by Juerg Haefliger
On 15.01.19 11:17, Juerg Haefliger wrote:

> From: Stefan Raspl <[hidden email]>
>
> BugLink: https://bugs.launchpad.net/bugs/1798776
>
> Python3 returns a float for a regular division - switch to a division
> operator that returns an integer.
> Furthermore, filters return a generator object instead of the actual
> list - wrap result in yet another list, which makes it still work in
> both, Python2 and 3.
>
> Signed-off-by: Stefan Raspl <[hidden email]>
> Signed-off-by: Radim Krčmář <[hidden email]>
> (cherry picked from commit 58f33cfe73076b6497bada4f7b5bda961ed68083)
> Signed-off-by: Juerg Haefliger <[hidden email]>
Acked-by: Stefan Bader <[hidden email]>

> ---
>  tools/kvm/kvm_stat/kvm_stat | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
> index 56c4b3f8a01b..e10b90a8917a 100755
> --- a/tools/kvm/kvm_stat/kvm_stat
> +++ b/tools/kvm/kvm_stat/kvm_stat
> @@ -759,7 +759,7 @@ class DebugfsProvider(Provider):
>              if len(vms) == 0:
>                  self.do_read = False
>  
> -            self.paths = filter(lambda x: "{}-".format(pid) in x, vms)
> +            self.paths = list(filter(lambda x: "{}-".format(pid) in x, vms))
>  
>          else:
>              self.paths = []
> @@ -1219,10 +1219,10 @@ class Tui(object):
>          (x, term_width) = self.screen.getmaxyx()
>          row = 2
>          for line in text:
> -            start = (term_width - len(line)) / 2
> +            start = (term_width - len(line)) // 2
>              self.screen.addstr(row, start, line)
>              row += 1
> -        self.screen.addstr(row + 1, (term_width - len(hint)) / 2, hint,
> +        self.screen.addstr(row + 1, (term_width - len(hint)) // 2, hint,
>                             curses.A_STANDOUT)
>          self.screen.getkey()
>  
>


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

ACK: [SRU][Bionic][Patch 1/2] tools/kvm_stat: fix python3 issues

Kleber Souza
In reply to this post by Juerg Haefliger
On 1/15/19 11:17 AM, Juerg Haefliger wrote:

> From: Stefan Raspl <[hidden email]>
>
> BugLink: https://bugs.launchpad.net/bugs/1798776
>
> Python3 returns a float for a regular division - switch to a division
> operator that returns an integer.
> Furthermore, filters return a generator object instead of the actual
> list - wrap result in yet another list, which makes it still work in
> both, Python2 and 3.
>
> Signed-off-by: Stefan Raspl <[hidden email]>
> Signed-off-by: Radim Krčmář <[hidden email]>
> (cherry picked from commit 58f33cfe73076b6497bada4f7b5bda961ed68083)
> Signed-off-by: Juerg Haefliger <[hidden email]>
Acked-by: Kleber Sacilotto de Souza <[hidden email]>

> ---
>  tools/kvm/kvm_stat/kvm_stat | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
> index 56c4b3f8a01b..e10b90a8917a 100755
> --- a/tools/kvm/kvm_stat/kvm_stat
> +++ b/tools/kvm/kvm_stat/kvm_stat
> @@ -759,7 +759,7 @@ class DebugfsProvider(Provider):
>              if len(vms) == 0:
>                  self.do_read = False
>  
> -            self.paths = filter(lambda x: "{}-".format(pid) in x, vms)
> +            self.paths = list(filter(lambda x: "{}-".format(pid) in x, vms))
>  
>          else:
>              self.paths = []
> @@ -1219,10 +1219,10 @@ class Tui(object):
>          (x, term_width) = self.screen.getmaxyx()
>          row = 2
>          for line in text:
> -            start = (term_width - len(line)) / 2
> +            start = (term_width - len(line)) // 2
>              self.screen.addstr(row, start, line)
>              row += 1
> -        self.screen.addstr(row + 1, (term_width - len(hint)) / 2, hint,
> +        self.screen.addstr(row + 1, (term_width - len(hint)) // 2, hint,
>                             curses.A_STANDOUT)
>          self.screen.getkey()
>  



--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

APPLIED: [SRU][Bionic][Patch 1/2] tools/kvm_stat: fix python3 issues

Khaled Elmously
In reply to this post by Juerg Haefliger
On 2019-01-15 11:17:53 , Juerg Haefliger wrote:

> From: Stefan Raspl <[hidden email]>
>
> BugLink: https://bugs.launchpad.net/bugs/1798776
>
> Python3 returns a float for a regular division - switch to a division
> operator that returns an integer.
> Furthermore, filters return a generator object instead of the actual
> list - wrap result in yet another list, which makes it still work in
> both, Python2 and 3.
>
> Signed-off-by: Stefan Raspl <[hidden email]>
> Signed-off-by: Radim Krčmář <[hidden email]>
> (cherry picked from commit 58f33cfe73076b6497bada4f7b5bda961ed68083)
> Signed-off-by: Juerg Haefliger <[hidden email]>
> ---
>  tools/kvm/kvm_stat/kvm_stat | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
> index 56c4b3f8a01b..e10b90a8917a 100755
> --- a/tools/kvm/kvm_stat/kvm_stat
> +++ b/tools/kvm/kvm_stat/kvm_stat
> @@ -759,7 +759,7 @@ class DebugfsProvider(Provider):
>              if len(vms) == 0:
>                  self.do_read = False
>  
> -            self.paths = filter(lambda x: "{}-".format(pid) in x, vms)
> +            self.paths = list(filter(lambda x: "{}-".format(pid) in x, vms))
>  
>          else:
>              self.paths = []
> @@ -1219,10 +1219,10 @@ class Tui(object):
>          (x, term_width) = self.screen.getmaxyx()
>          row = 2
>          for line in text:
> -            start = (term_width - len(line)) / 2
> +            start = (term_width - len(line)) // 2
>              self.screen.addstr(row, start, line)
>              row += 1
> -        self.screen.addstr(row + 1, (term_width - len(hint)) / 2, hint,
> +        self.screen.addstr(row + 1, (term_width - len(hint)) // 2, hint,
>                             curses.A_STANDOUT)
>          self.screen.getkey()
>  
> --
> 2.19.1
>
>
> --
> kernel-team mailing list
> [hidden email]
> https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team