From e257d5666568a9621b7dfece313c705e41e17070 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 23 Mar 2020 16:55:02 -0400 Subject: [PATCH] version: fix running under Python 2 This gets the unittests passing again for now. Change-Id: Ibed430a305bc26b907ad0ea424c7eec7de37e942 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/259994 Tested-by: Mike Frysinger Reviewed-by: Jonathan Nieder --- repo | 10 +++++++--- subcmds/version.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/repo b/repo index 66a2a07d..12904c3e 100755 --- a/repo +++ b/repo @@ -1060,9 +1060,13 @@ def _Version(): print('git %s' % (ParseGitVersion().full,)) print('Python %s' % sys.version) uname = platform.uname() - print('OS %s %s (%s)' % (uname.system, uname.release, uname.version)) - print('CPU %s (%s)' % - (uname.machine, uname.processor if uname.processor else 'unknown')) + if sys.version_info.major < 3: + # Python 3 returns a named tuple, but Python 2 is simpler. + print(uname) + else: + print('OS %s %s (%s)' % (uname.system, uname.release, uname.version)) + print('CPU %s (%s)' % + (uname.machine, uname.processor if uname.processor else 'unknown')) sys.exit(0) diff --git a/subcmds/version.py b/subcmds/version.py index 8721bf49..0bf200f3 100644 --- a/subcmds/version.py +++ b/subcmds/version.py @@ -56,6 +56,10 @@ class Version(Command, MirrorSafeCommand): print('git User-Agent %s' % user_agent.git) print('Python %s' % sys.version) uname = platform.uname() - print('OS %s %s (%s)' % (uname.system, uname.release, uname.version)) - print('CPU %s (%s)' % - (uname.machine, uname.processor if uname.processor else 'unknown')) + if sys.version_info.major < 3: + # Python 3 returns a named tuple, but Python 2 is simpler. + print(uname) + else: + print('OS %s %s (%s)' % (uname.system, uname.release, uname.version)) + print('CPU %s (%s)' % + (uname.machine, uname.processor if uname.processor else 'unknown'))