-
Notifications
You must be signed in to change notification settings - Fork 69
Regain Python 2.6 support #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -925,16 +925,26 @@ def _lsb_release_info(self): | |
| Returns: | ||
| A dictionary containing all information items. | ||
| """ | ||
| if not self.include_lsb: | ||
| cmd = ['lsb_release', '-a'] | ||
| process = subprocess.Popen( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to pipe to devnull anymore and I can't find anywhere where stderr is used meaningfully unless we get an error. Can we move the processing of stderr until that one error branch? (Or better yet: pipe it to /dev/null and not process it at all!) |
||
| cmd, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE) | ||
| stdout, stderr = process.communicate() | ||
| stdout, stderr = stdout.decode('utf-8'), stderr.decode('utf-8') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's continue to use |
||
| code = process.returncode | ||
| if code == 0: | ||
| content = stdout.splitlines() | ||
| return self._parse_lsb_release_content(content) | ||
| elif code == 127: # Command not found | ||
| return {} | ||
| with open(os.devnull, 'w') as devnull: | ||
| try: | ||
| cmd = ('lsb_release', '-a') | ||
| stdout = subprocess.check_output(cmd, stderr=devnull) | ||
| except OSError: # Command not found | ||
| return {} | ||
| content = stdout.decode(sys.getfilesystemencoding()).splitlines() | ||
| return self._parse_lsb_release_content(content) | ||
| else: | ||
| if sys.version_info[:2] >= (3, 5): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grab |
||
| raise subprocess.CalledProcessError(code, cmd, stdout, stderr) | ||
| elif sys.version_info[:2] >= (2, 7): | ||
| raise subprocess.CalledProcessError(code, cmd, stdout) | ||
| elif sys.version_info[:2] == (2, 6): | ||
| raise subprocess.CalledProcessError(code, cmd) | ||
|
|
||
| @staticmethod | ||
| def _parse_lsb_release_content(lines): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genuinely curious, does 2.6 not support assuming format indexes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't. It's a 2.7 and up thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. See https://docs.python.org/2/library/string.html#format-string-syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for verifying this!