diff mbox

python/semanage: Update Infiniband code to work on python3

Message ID 20171113085626.5636-1-vmojzis@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Vit Mojzis Nov. 13, 2017, 8:56 a.m. UTC
Update Infiniband "port" and "key" listing and export to work on
python3.
{}.keys() does not support .sort() operation on Py3.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
 python/semanage/seobject.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Petr Lautrbach Nov. 14, 2017, 8:33 a.m. UTC | #1
On Mon, Nov 13, 2017 at 09:56:26AM +0100, Vit Mojzis wrote:
> Update Infiniband "port" and "key" listing and export to work on
> python3.
> {}.keys() does not support .sort() operation on Py3.
> 
> Signed-off-by: Vit Mojzis <vmojzis@redhat.com>

Both patches look good to me. I'll merge them tomorrow if there's no
other comments.

Thanks,

Petr


> ---
>  python/semanage/seobject.py | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index 380256b..770745e 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -1543,9 +1543,8 @@ class ibpkeyRecords(semanageRecords):
>      def customized(self):
>          l = []
>          ddict = self.get_all(True)
> -        keys = ddict.keys()
> -        keys.sort()
> -        for k in keys:
> +
> +        for k in sorted(ddict.keys()):
>              if k[0] == k[1]:
>                  l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
>              else:
> @@ -1557,11 +1556,10 @@ class ibpkeyRecords(semanageRecords):
>          keys = ddict.keys()
>          if len(keys) == 0:
>              return
> -        keys.sort()
>  
>          if heading:
>              print("%-30s %-18s %s\n" % (_("SELinux IB Pkey Type"), _("Subnet_Prefix"), _("Pkey Number")))
> -        for i in keys:
> +        for i in sorted(keys):
>              rec = "%-30s %-18s " % i
>              rec += "%s" % ddict[i][0]
>              for p in ddict[i][1:]:
> @@ -1785,9 +1783,8 @@ class ibendportRecords(semanageRecords):
>      def customized(self):
>          l = []
>          ddict = self.get_all(True)
> -        keys = ddict.keys()
> -        keys.sort()
> -        for k in keys:
> +
> +        for k in sorted(ddict.keys()):
>              l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
>          return l
>  
> @@ -1796,11 +1793,10 @@ class ibendportRecords(semanageRecords):
>          keys = ddict.keys()
>          if len(keys) == 0:
>              return
> -        keys.sort()
>  
>          if heading:
>              print("%-30s %-18s %s\n" % (_("SELinux IB End Port Type"), _("IB Device Name"), _("Port Number")))
> -        for i in keys:
> +        for i in sorted(keys):
>              rec = "%-30s %-18s " % i
>              rec += "%s" % ddict[i][0]
>              for p in ddict[i][1:]:
> -- 
> 2.9.4
> 
>
Petr Lautrbach Nov. 15, 2017, 1:21 p.m. UTC | #2
On Tue, Nov 14, 2017 at 09:33:54AM +0100, Petr Lautrbach wrote:
> On Mon, Nov 13, 2017 at 09:56:26AM +0100, Vit Mojzis wrote:
> > Update Infiniband "port" and "key" listing and export to work on
> > python3.
> > {}.keys() does not support .sort() operation on Py3.
> > 
> > Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
> 
> Both patches look good to me. I'll merge them tomorrow if there's no
> other comments.
> 

Merged. Thanks!

> 
> 
> > ---
> >  python/semanage/seobject.py | 16 ++++++----------
> >  1 file changed, 6 insertions(+), 10 deletions(-)
> > 
> > diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> > index 380256b..770745e 100644
> > --- a/python/semanage/seobject.py
> > +++ b/python/semanage/seobject.py
> > @@ -1543,9 +1543,8 @@ class ibpkeyRecords(semanageRecords):
> >      def customized(self):
> >          l = []
> >          ddict = self.get_all(True)
> > -        keys = ddict.keys()
> > -        keys.sort()
> > -        for k in keys:
> > +
> > +        for k in sorted(ddict.keys()):
> >              if k[0] == k[1]:
> >                  l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
> >              else:
> > @@ -1557,11 +1556,10 @@ class ibpkeyRecords(semanageRecords):
> >          keys = ddict.keys()
> >          if len(keys) == 0:
> >              return
> > -        keys.sort()
> >  
> >          if heading:
> >              print("%-30s %-18s %s\n" % (_("SELinux IB Pkey Type"), _("Subnet_Prefix"), _("Pkey Number")))
> > -        for i in keys:
> > +        for i in sorted(keys):
> >              rec = "%-30s %-18s " % i
> >              rec += "%s" % ddict[i][0]
> >              for p in ddict[i][1:]:
> > @@ -1785,9 +1783,8 @@ class ibendportRecords(semanageRecords):
> >      def customized(self):
> >          l = []
> >          ddict = self.get_all(True)
> > -        keys = ddict.keys()
> > -        keys.sort()
> > -        for k in keys:
> > +
> > +        for k in sorted(ddict.keys()):
> >              l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
> >          return l
> >  
> > @@ -1796,11 +1793,10 @@ class ibendportRecords(semanageRecords):
> >          keys = ddict.keys()
> >          if len(keys) == 0:
> >              return
> > -        keys.sort()
> >  
> >          if heading:
> >              print("%-30s %-18s %s\n" % (_("SELinux IB End Port Type"), _("IB Device Name"), _("Port Number")))
> > -        for i in keys:
> > +        for i in sorted(keys):
> >              rec = "%-30s %-18s " % i
> >              rec += "%s" % ddict[i][0]
> >              for p in ddict[i][1:]:
> > -- 
> > 2.9.4
> > 
> > 
>
diff mbox

Patch

diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index 380256b..770745e 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -1543,9 +1543,8 @@  class ibpkeyRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             if k[0] == k[1]:
                 l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
             else:
@@ -1557,11 +1556,10 @@  class ibpkeyRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB Pkey Type"), _("Subnet_Prefix"), _("Pkey Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]:
@@ -1785,9 +1783,8 @@  class ibendportRecords(semanageRecords):
     def customized(self):
         l = []
         ddict = self.get_all(True)
-        keys = ddict.keys()
-        keys.sort()
-        for k in keys:
+
+        for k in sorted(ddict.keys()):
             l.append("-a -t %s -r %s -z %s %s" % (ddict[k][0], ddict[k][1], k[1], k[0]))
         return l
 
@@ -1796,11 +1793,10 @@  class ibendportRecords(semanageRecords):
         keys = ddict.keys()
         if len(keys) == 0:
             return
-        keys.sort()
 
         if heading:
             print("%-30s %-18s %s\n" % (_("SELinux IB End Port Type"), _("IB Device Name"), _("Port Number")))
-        for i in keys:
+        for i in sorted(keys):
             rec = "%-30s %-18s " % i
             rec += "%s" % ddict[i][0]
             for p in ddict[i][1:]: