[rtems-source-builder commit] sb/linux.py: Workaround for Python >= 3.8

Chris Johns chrisj at rtems.org
Tue Apr 28 00:27:38 UTC 2020


Module:    rtems-source-builder
Branch:    master
Commit:    ae9faa2726017fb75ae7715619387a23deecf9a5
Changeset: http://git.rtems.org/rtems-source-builder/commit/?id=ae9faa2726017fb75ae7715619387a23deecf9a5

Author:    Anders Montonen <Anders.Montonen at iki.fi>
Date:      Mon Apr 27 22:15:27 2020 +0300

sb/linux.py: Workaround for Python >= 3.8

The platform.dist() interface has been deprecated since Python 3.5, and
has been removed in Python 3.8.

Fixes:
Traceback (most recent call last):
  File "/home/anders/work/rtems/rsb/source-builder/sb/options.py", line 682, in load
    overrides = linux.load()
  File "/home/anders/work/rtems/rsb/source-builder/sb/linux.py", line 60, in load
    distro = platform.dist()[0]
AttributeError: module 'platform' has no attribute 'dist'

Signed-off-by: Anders Montonen <Anders.Montonen at iki.fi>

---

 source-builder/sb/linux.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/source-builder/sb/linux.py b/source-builder/sb/linux.py
index c3059a9..791bbd6 100644
--- a/source-builder/sb/linux.py
+++ b/source-builder/sb/linux.py
@@ -55,13 +55,17 @@ def load():
         '__tar':            ('exe',     'required', '/bin/tar')
         }
 
-    # Works for LSB distros
-    try:
-        distro = platform.dist()[0]
-        distro_ver = float(platform.dist()[1])
-    except ValueError:
-        # Non LSB distro found, use failover"
-        pass
+    # platform.dist() was removed in Python 3.8
+    if hasattr(platform, 'dist'):
+        # Works for LSB distros
+        try:
+            distro = platform.dist()[0]
+            distro_ver = float(platform.dist()[1])
+        except ValueError:
+         # Non LSB distro found, use failover"
+         pass
+    else:
+         distro = ''
 
     # Non LSB - fail over to issue
     if distro == '':



More information about the vc mailing list