File: platform-lsbrelease.diff

package info (click to toggle)
python2.6 2.6.6-8%2Bdeb6u3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 65,368 kB
  • ctags: 106,965
  • sloc: ansic: 389,033; python: 375,783; asm: 9,734; sh: 4,934; makefile: 4,120; lisp: 2,933; objc: 775; xml: 62
file content (43 lines) | stat: -rw-r--r-- 1,637 bytes parent folder | download | duplicates (3)
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
# DP: Use /etc/lsb-release to identify the platform.

Index: python2.6-2.6.5+20100521/Lib/platform.py
===================================================================
--- python2.6-2.6.5+20100521.orig/Lib/platform.py	2010-05-21 15:53:08.607710061 +0200
+++ python2.6-2.6.5+20100521/Lib/platform.py	2010-05-21 15:53:08.615723091 +0200
@@ -290,6 +290,10 @@
         if parsed != output:
             print (input, parsed)
 
+_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: