Merge lp:~cjwatson/lazr.restfulclient/lsb-release into lp:lazr.restfulclient

Proposed by Colin Watson
Status: Rejected
Rejected by: Colin Watson
Proposed branch: lp:~cjwatson/lazr.restfulclient/lsb-release
Merge into: lp:lazr.restfulclient
Diff against target: 35 lines (+10/-7)
1 file modified
src/lazr/restfulclient/authorize/oauth.py (+10/-7)
To merge this branch: bzr merge lp:~cjwatson/lazr.restfulclient/lsb-release
Reviewer Review Type Date Requested Status
Colin Watson (community) Disapprove
Review via email: mp+277835@code.launchpad.net

Commit message

Inline a small part of platform.linux_distribution, since it's deprecated in Python 3.5 and will be removed in 3.7.

Description of the change

Inline a small part of platform.linux_distribution, since it's deprecated in Python 3.5 and will be removed in 3.7. This only supports platforms where /etc/lsb-release exists, and otherwise falls back to platform.system; we can extend it if that's actually needed, but it probably isn't.

To post a comment you must log in.
147. By Colin Watson

Inline a small part of platform.linux_distribution, since it's deprecated in Python 3.5 and will be removed in 3.7.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

I did complain upstream saying that they should simply parse /etc/os-release, with fallback got /usr/lib/os-release, but no avail.

I would prefer for the new code to parse the first one of ['/etc/os-release', '/usr/lib/os-release'] as per http://www.freedesktop.org/software/systemd/man/os-release.html

Revision history for this message
Colin Watson (cjwatson) wrote :

I would be more motivated to do that if you could suggest an example situation where it actually makes a difference? It feels like busywork otherwise, since we'll probably still have to include lsb-release support.

Revision history for this message
Colin Watson (cjwatson) wrote :

I noticed today that there's a "distro" module on PyPI and in Debian which is actively maintained and provides much the same interface as was previously in the stdlib, but including more modern data sources such as os-release. I'm therefore withdrawing this MP in favour of https://code.launchpad.net/~cjwatson/lazr.restfulclient/distro/+merge/344799.

review: Disapprove

Unmerged revisions

147. By Colin Watson

Inline a small part of platform.linux_distribution, since it's deprecated in Python 3.5 and will be removed in 3.7.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restfulclient/authorize/oauth.py'
2--- src/lazr/restfulclient/authorize/oauth.py 2014-07-28 15:35:35 +0000
3+++ src/lazr/restfulclient/authorize/oauth.py 2015-11-18 14:26:19 +0000
4@@ -26,6 +26,7 @@
5 from ConfigParser import SafeConfigParser
6 import os
7 import platform
8+import re
9 import stat
10 import socket
11 # Work around relative import behavior. The below is equivalent to
12@@ -107,14 +108,16 @@
13 This key identifies the platform and the computer's
14 hostname. It does not identify the active user.
15 """
16+ _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
17+ distname = ''
18 try:
19- distname, version, release_id = platform.linux_distribution()
20- except Exception:
21- # This can happen in pre-2.6 versions of Python. We don't
22- # use platform.dist() because it looks like old versions
23- # of dist can give inconsistent answers on a single
24- # computer.
25- distname = ''
26+ with open("/etc/lsb-release", "r") as etclsbrel:
27+ for line in etclsbrel:
28+ m = _distributor_id_file_re.search(line)
29+ if m:
30+ distname = m.group(1).strip()
31+ except EnvironmentError:
32+ pass
33 if distname == '':
34 distname = platform.system() # (eg. "Windows")
35 return self.KEY_FORMAT % (distname, socket.gethostname())

Subscribers

People subscribed via source and target branches