Re: [ovs-dev] [PATCH] ovs-bugtool: Fix for python3.

2020-11-05 Thread Ilya Maximets
On 2/29/20 12:20 AM, Ben Pfaff wrote:
> On Tue, Feb 25, 2020 at 11:59:06AM -0800, William Tu wrote:
>> Currently ovs-bugtool does not work due to Python2 deprecated.
>> When moving to Python3, a couple of things are broken in ovs-bugtool,
>> ex: import libraries issues such as StringIO and commands.
>> Also there are some bytes to string convertion in this patch
>> because in Python3,strings are now always Unicode and a new type 'bytes'
>> is added for handling binary strings.
>>
>> Signed-off-by: William Tu 
> 
> Some of these are a little puzzling.  I see a lot more use of list()
> than I would have expected to be necessary.
> 
> For example, I don't know why this change is needed:
>> -for (k, v) in data.items():
>> +for (k, v) in list(data.items()):
>>  cap = v['cap']
>>  if 'cmd_args' in v:

This change is needed, because in python2 items() returns a new list,
but in python3 it returns a 'view object' which is not exactly an iterator,
but something similar.  So, we can't use this view object for iteration
while modifying original dictionary just like we can't use iteritems()
in python2 for this purpose.

replying here just because the same change proposed again:
 
https://patchwork.ozlabs.org/project/openvswitch/patch/1604531775-44045-1-git-send-email-u9012...@gmail.com/

Best regards, Ilya Maximets.
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH] ovs-bugtool: Fix for python3.

2020-02-28 Thread William Tu
On Fri, Feb 28, 2020 at 3:21 PM Ben Pfaff  wrote:
>
> On Tue, Feb 25, 2020 at 11:59:06AM -0800, William Tu wrote:
> > Currently ovs-bugtool does not work due to Python2 deprecated.
> > When moving to Python3, a couple of things are broken in ovs-bugtool,
> > ex: import libraries issues such as StringIO and commands.
> > Also there are some bytes to string convertion in this patch
> > because in Python3,strings are now always Unicode and a new type 'bytes'
> > is added for handling binary strings.
> >
> > Signed-off-by: William Tu 
>
> Some of these are a little puzzling.  I see a lot more use of list()
> than I would have expected to be necessary.
>
> For example, I don't know why this change is needed:
> > -for (k, v) in data.items():
> > +for (k, v) in list(data.items()):
> >  cap = v['cap']
> >  if 'cmd_args' in v:
>
> and I think that this can be just "if 'output' not in v:"
> > -if 'output' not in v.keys():
> > +if 'output' not in list(v.keys()):
> >  v['output'] = StringIOmtime()
> >  if v['repeat_count'] > 0:
> >  if cap not in process_lists:
>
Thanks Ben.
Actually for this patch, I first use a python conversion tool called "2to3".
https://docs.python.org/2/library/2to3.html

Then start to test and fix one by one.
I will look into these changes again.

William
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH] ovs-bugtool: Fix for python3.

2020-02-28 Thread Ben Pfaff
On Tue, Feb 25, 2020 at 11:59:06AM -0800, William Tu wrote:
> Currently ovs-bugtool does not work due to Python2 deprecated.
> When moving to Python3, a couple of things are broken in ovs-bugtool,
> ex: import libraries issues such as StringIO and commands.
> Also there are some bytes to string convertion in this patch
> because in Python3,strings are now always Unicode and a new type 'bytes'
> is added for handling binary strings.
> 
> Signed-off-by: William Tu 

Some of these are a little puzzling.  I see a lot more use of list()
than I would have expected to be necessary.

For example, I don't know why this change is needed:
> -for (k, v) in data.items():
> +for (k, v) in list(data.items()):
>  cap = v['cap']
>  if 'cmd_args' in v:

and I think that this can be just "if 'output' not in v:"
> -if 'output' not in v.keys():
> +if 'output' not in list(v.keys()):
>  v['output'] = StringIOmtime()
>  if v['repeat_count'] > 0:
>  if cap not in process_lists:

Thanks,

Ben.
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev