bug 1311580 - Fix mozinfo os_version / linux_distro on Linux. r?jmaher draft
authorTed Mielczarek <ted@mielczarek.org>
Wed, 19 Oct 2016 21:04:21 -0400
changeset 427213 f903d1801fa0952e801cb195f7915d3fdee3aa41
parent 426771 90d8afaddf9150853b0b68b35b30c1e54a8683e7
child 428197 b117fc46430cd6ac56d64358407b1678cfc9108b
push id32960
push userbmo:ted@mielczarek.org
push dateThu, 20 Oct 2016 01:30:16 +0000
reviewersjmaher
bugs1311580
milestone52.0a1
bug 1311580 - Fix mozinfo os_version / linux_distro on Linux. r?jmaher MozReview-Commit-ID: FD9fzKg6Ei4
testing/mozbase/mozinfo/mozinfo/mozinfo.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -87,35 +87,26 @@ if system in ["Microsoft", "Windows"]:
         version = "%d.%d.%d" % (major, minor, build_number)
 
     os_version = "%d.%d" % (major, minor)
 elif system.startswith('MINGW'):
     # windows/mingw python build (msys)
     info['os'] = 'win'
     os_version = version = unknown
 elif system == "Linux":
-    if hasattr(platform, "linux_distribution"):
-        (distro, os_version, codename) = platform.linux_distribution()
-    else:
-        (distro, os_version, codename) = platform.dist()
-    if not processor:
-        processor = machine
-    version = "%s %s" % (distro, os_version)
-
-    # Bug in Python 2's `platform` library:
-    # It will return a triple of empty strings if the distribution is not supported.
-    # It works on Python 3. If we don't have an OS version,
-    # the unit tests fail to run.
-    if not distro and not os_version and not codename:
-        distro = 'lfs'
-        version = release
-        os_version = release
+    # Try to get a useful distro name/version out of os-release.
+    try:
+        os_info = dict(map(lambda x: x.strip('"'), l.split('=')) for l in open('/etc/os-release', 'rb').read().splitlines())
+    except IOError:
+        os_info = {}
 
     info['os'] = 'linux'
-    info['linux_distro'] = distro
+    version = os_version = os_info.get('VERSION_ID', release)
+    info['linux_distro'] = os_info.get('NAME', 'lfs')
+
 elif system in ['DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD']:
     info['os'] = 'bsd'
     version = os_version = sys.platform
 elif system == "Darwin":
     (release, versioninfo, machine) = platform.mac_ver()
     version = "OS X %s" % release
     versionNums = release.split('.')[:2]
     os_version = "%s.%s" % (versionNums[0], versionNums[1])