File: platform-lsbrelease

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (47 lines) | stat: -rw-r--r-- 1,654 bytes parent folder | download
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
Description: Use /etc/lsb-release to identify the platform.
Author: Matthias Klose <doko@debian.org>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/196526
Bug-cpython: http://bugs.python.org/issue1322
Bug-cpython: http://bugs.python.org/issue9514
Origin: cpython Debian packaging
Last-Update: 2011-12-19

--- a/lib-python/2.7/platform.py
+++ b/lib-python/2.7/platform.py
@@ -290,6 +290,10 @@
             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,
@@ -314,6 +318,25 @@
         args given as parameters.
 
     """
+    # check for the Debian/Ubuntu /etc/lsb-release file first, needed so
+    # that the distribution doesn't get identified as Debian.
+    try:
+        etclsbrel = open("/etc/lsb-release", "rU")
+        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: