Skip to content

Commit

Permalink
Regain Python 2.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstewart committed Dec 29, 2017
1 parent 55fb75e commit b5b6a14
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def __init__(self, f):
self._f = f

def __get__(self, obj, owner):
assert obj is not None, 'call {} on an instance'.format(self._fname)
assert obj is not None, 'call {0} on an instance'.format(self._fname)
ret = obj.__dict__[self._fname] = self._f(obj)
return ret

Expand Down Expand Up @@ -917,6 +917,14 @@ def _parse_os_release_content(lines):
pass
return props

def check_output(*args, **kwargs):
"""Run command with arguments and return its output as a byte string.
Same as subprocess.check_output(), but works before Python 2.7."""

p = subprocess.Popen(stdout=subprocess.PIPE, *args, **kwargs)
return p.communicate()[0].strip()

@cached_property
def _lsb_release_info(self):
"""
Expand All @@ -930,7 +938,7 @@ def _lsb_release_info(self):
with open(os.devnull, 'w') as devnull:
try:
cmd = ('lsb_release', '-a')
stdout = subprocess.check_output(cmd, stderr=devnull)
stdout = check_output(cmd, stderr=devnull)
except OSError: # Command not found
return {}
content = stdout.decode(sys.getfilesystemencoding()).splitlines()
Expand Down

0 comments on commit b5b6a14

Please sign in to comment.