Skip to contentSkip to conversation

libselinux: selinux.py - use os.walk() instead of os.path.walk()

PATCH In review Petr Lautrbach 2 participants 4 messages Apr 21, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: selinux.py - use os.walk() instead of os.path.walk()

From: Miro Hrončok <[email protected]>

os.path.walk() function is deprecated and has been removed in Python 3

---

A simple fix which allows to use same construction in Python 2 and Python 3. It's reported and proposed in https://bugzilla.redhat.com/show_bug.cgi?id=1195004

 libselinux/src/selinuxswig_python.i | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
libselinux/src/selinuxswig_python.i +3 -3
index ae72246..c9a2341 100644
@@ -31,9 +31,9 @@ def restorecon(path, recursive=False):
             lsetfilecon(path, context)
 
         if recursive:
-            os.path.walk(path, lambda arg, dirname, fnames:
-                             map(restorecon, [os.path.join(dirname, fname)
-                                              for fname in fnames]), None)
+            for root, dirs, files in os.walk(path):
+                for name in files + dirs:
+                   restorecon(os.path.join(root, name))
 
 def chcon(path, context, recursive=False):
     """ Set the SELinux context on a given path """
Signature · 1 line
2.3.5
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Petr Lautrbach

From: Miro Hrončok <[email protected]>

os.path.walk() function is deprecated and has been removed in Python 3

Thanks!

Quoted 27 lines

---

A simple fix which allows to use same construction in Python 2 and Python 3. It's reported and proposed in https://bugzilla.redhat.com/show_bug.cgi?id=1195004

 libselinux/src/selinuxswig_python.i | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
libselinux/src/selinuxswig_python.i +3 -3
index ae72246..c9a2341 100644
@@ -31,9 +31,9 @@ def restorecon(path, recursive=False):
             lsetfilecon(path, context)
 
         if recursive:
-            os.path.walk(path, lambda arg, dirname, fnames:
-                             map(restorecon, [os.path.join(dirname, fname)
-                                              for fname in fnames]), None)
+            for root, dirs, files in os.walk(path):
+                for name in files + dirs:
+                   restorecon(os.path.join(root, name))
 
 def chcon(path, context, recursive=False):
     """ Set the SELinux context on a given path """
#2 lore raw
Quoted 10 lines · Steve Lawrence
Quoted 5 lines · Petr Lautrbach

From: Miro Hrončok <[email protected]>

os.path.walk() function is deprecated and has been removed in Python 3

Thanks!

Might it be that you've accidentally edited a wrong ChangeLog?

Update libselinux ChangeLog

libsemanage/ChangeLog +2 -0
@@ -1,3 +1,5 @@
+       * Use os.walk() instead of the deprecated os.path.walk(), from Petr
+         Lautrbach & Miro Hrončok
 
 
 

Petr

Quoted 29 lines
Quoted 28 lines

---

A simple fix which allows to use same construction in Python 2 and Python 3. It's reported and proposed in https://bugzilla.redhat.com/show_bug.cgi?id=1195004

 libselinux/src/selinuxswig_python.i | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
libselinux/src/selinuxswig_python.i +3 -3
index ae72246..c9a2341 100644
@@ -31,9 +31,9 @@ def restorecon(path, recursive=False):
             lsetfilecon(path, context)
 
         if recursive:
-            os.path.walk(path, lambda arg, dirname, fnames:
-                             map(restorecon, [os.path.join(dirname, fname)
-                                              for fname in fnames]), None)
+            for root, dirs, files in os.walk(path):
+                for name in files + dirs:
+                   restorecon(os.path.join(root, name))
 
 def chcon(path, context, recursive=False):
     """ Set the SELinux context on a given path """
Signature · 1 line
Petr Lautrbach
#3 lore raw
Quoted 8 lines · Petr Lautrbach
Quoted 7 lines · Steve Lawrence
Quoted 5 lines · Petr Lautrbach

From: Miro Hrončok <[email protected]>

os.path.walk() function is deprecated and has been removed in Python 3

Quoted 8 lines
Quoted 3 lines

Thanks!

Might it be that you've accidentally edited a wrong ChangeLog?

Update libselinux ChangeLog

Yep. Thanks. That's been fixed.

- Steve

Quoted 41 lines
libsemanage/ChangeLog +2 -0
@@ -1,3 +1,5 @@
+       * Use os.walk() instead of the deprecated os.path.walk(), from Petr
+         Lautrbach & Miro Hrončok
 
 
 

Petr

Quoted 29 lines
Quoted 28 lines

---

A simple fix which allows to use same construction in Python 2 and Python 3. It's reported and proposed in https://bugzilla.redhat.com/show_bug.cgi?id=1195004

 libselinux/src/selinuxswig_python.i | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
libselinux/src/selinuxswig_python.i +3 -3
index ae72246..c9a2341 100644
@@ -31,9 +31,9 @@ def restorecon(path, recursive=False):
             lsetfilecon(path, context)
 
         if recursive:
-            os.path.walk(path, lambda arg, dirname, fnames:
-                             map(restorecon, [os.path.join(dirname, fname)
-                                              for fname in fnames]), None)
+            for root, dirs, files in os.walk(path):
+                for name in files + dirs:
+                   restorecon(os.path.join(root, name))
 
 def chcon(path, context, recursive=False):
     """ Set the SELinux context on a given path """