File: platform-lsbrelease.diff

package info (click to toggle)
python2.7 2.7.16-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,524 kB
  • sloc: python: 469,695; ansic: 444,315; sh: 17,604; asm: 14,304; makefile: 4,899; objc: 761; exp: 499; cpp: 128; xml: 76
file content (50 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# DP: Use /etc/lsb-release to identify the platform.

--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -293,7 +293,7 @@ _release_version = re.compile(r'([^0-9]+
 _supported_dists = (
     'SuSE', 'debian', 'fedora', 'redhat', 'centos',
     'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo',
-    'UnitedLinux', 'turbolinux')
+    'UnitedLinux', 'turbolinux', 'Ubuntu')
 
 def _parse_release_file(firstline):
 
@@ -322,6 +322,10 @@ def _parse_release_file(firstline):
             id = l[1]
     return '', version, id
 
+_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
+_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
+_codename_file_re = re.compile("(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I)
+
 def linux_distribution(distname='', version='', id='',
 
                        supported_dists=_supported_dists,
@@ -346,6 +350,25 @@ def linux_distribution(distname='', vers
         args given as parameters.
 
     """
+    # check for the LSB /etc/lsb-release file first, needed so
+    # that the distribution doesn't get identified as Debian.
+    try:
+        with open("/etc/lsb-release", "rU") as etclsbrel:
+            for line in etclsbrel:
+                m = _distributor_id_file_re.search(line)
+                if m:
+                    _u_distname = m.group(1).strip()
+                m = _release_file_re.search(line)
+                if m:
+                    _u_version = m.group(1).strip()
+                m = _codename_file_re.search(line)
+                if m:
+                    _u_id = m.group(1).strip()
+            if _u_distname and _u_version:
+                return (_u_distname, _u_version, _u_id)
+    except (EnvironmentError, UnboundLocalError):
+        pass
+
     try:
         etc = os.listdir('/etc')
     except os.error: