[ovs-dev] utilities: Make ovs-pipegen.py Python 3 friendly

Message ID 35fe2f7d9a5472bea8f855a772e64f31ffe67abc.1520959703.git.tredaelli@redhat.com
State Accepted
Delegated to: Russell Bryant
Headers show
Series
  • [ovs-dev] utilities: Make ovs-pipegen.py Python 3 friendly
Related show

Commit Message

Timothy Redaelli March 13, 2018, 4:48 p.m.
Replace "print f" with "print(f)" and "xrange" with "range".

The changes are backward compatibile with Python 2.

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 utilities/ovs-pipegen.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Russell Bryant March 14, 2018, 3:06 p.m. | #1
I've applied this to master.

I'll also submit a follow-up patch in a moment which adds this script
to the list of Python files checked with flake8, which will help
prevent some basic compatibility issues in the future.

On Tue, Mar 13, 2018 at 12:48 PM, Timothy Redaelli <tredaelli@redhat.com> wrote:
> Replace "print f" with "print(f)" and "xrange" with "range".
>
> The changes are backward compatibile with Python 2.
>
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
> ---
>  utilities/ovs-pipegen.py | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/utilities/ovs-pipegen.py b/utilities/ovs-pipegen.py
> index 4bf240f3a..f040a7e1b 100755
> --- a/utilities/ovs-pipegen.py
> +++ b/utilities/ovs-pipegen.py
> @@ -71,15 +71,15 @@ def pipeline(size):
>      pipeline = [l2, l3, l4, l2]
>
>      flows = []
> -    for stage in xrange(len(pipeline)):
> +    for stage in range(len(pipeline)):
>          action = resubmit(stage + 1)
> -        flows += [pipeline[stage](stage, action) for _ in xrange(size)]
> +        flows += [pipeline[stage](stage, action) for _ in range(size)]
>          flows.append(flow_str(stage, "", action, priority=1))
>
>      flows.append(flow_str(len(pipeline), "", "in_port"))
>
>      for f in flows:
> -        print f
> +        print(f)
>
>
>  def main():
> --
> 2.14.3
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Patch

diff --git a/utilities/ovs-pipegen.py b/utilities/ovs-pipegen.py
index 4bf240f3a..f040a7e1b 100755
--- a/utilities/ovs-pipegen.py
+++ b/utilities/ovs-pipegen.py
@@ -71,15 +71,15 @@  def pipeline(size):
     pipeline = [l2, l3, l4, l2]
 
     flows = []
-    for stage in xrange(len(pipeline)):
+    for stage in range(len(pipeline)):
         action = resubmit(stage + 1)
-        flows += [pipeline[stage](stage, action) for _ in xrange(size)]
+        flows += [pipeline[stage](stage, action) for _ in range(size)]
         flows.append(flow_str(stage, "", action, priority=1))
 
     flows.append(flow_str(len(pipeline), "", "in_port"))
 
     for f in flows:
-        print f
+        print(f)
 
 
 def main():