From 2a20ef36bb66830a12ca9576937ffa238f457abf Mon Sep 17 00:00:00 2001 From: Amin Dandache Date: Thu, 21 Jul 2016 15:10:22 +0200 Subject: [PATCH] fix utf8 and python3 --- gitstatus.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/gitstatus.py b/gitstatus.py index da175ba..e049d08 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -21,7 +21,11 @@ __all__ = ["Print"] try: Print = eval("print") # python 3.0 case -except SyntaxError: + python_version = 3 + to_str = str +except SyntaxError as e: + python_version = 2 + to_str = unicode D = dict() try: exec ("from __future__ import print_function\np=print", D) @@ -126,14 +130,24 @@ else: if remote == "": remote = '.' +if python_version == 2: + remote = remote.decode('utf-8') + out = '\n'.join([ branch, - remote.decode('utf-8'), - str(len(staged)), - str(len(conflicts)), - str(len(changed)), - str(len(untracked)), - str(stashed), - str(clean) + remote, + to_str(len(staged)), + to_str(len(conflicts)), + to_str(len(changed)), + to_str(len(untracked)), + to_str(stashed), + to_str(clean), + to_str(python_version), ]) -Print(out) + + +if python_version == 2: + Print(out.encode('utf-8')) +else: + Print(out) +