From 648124f1bf9f817e82a41d5b1689b666b9f1d4d7 Mon Sep 17 00:00:00 2001 From: Mihai Date: Wed, 4 May 2016 23:53:39 +0200 Subject: [PATCH] Ensure that UTF-8 output works even without a terminal --- docktree/__init__.py | 6 +++++- setup.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docktree/__init__.py b/docktree/__init__.py index 74e5b5b..d787dbc 100755 --- a/docktree/__init__.py +++ b/docktree/__init__.py @@ -5,6 +5,7 @@ import sys import locale import argparse +import codecs try: from docker import Client @@ -12,6 +13,9 @@ print("Cannot import Docker API, is docker_py installed?", file=sys.stderr) sys.exit(1) +if sys.version_info < (3,): + sys.stdout = codecs.getwriter('utf8')(sys.stdout) + # Pseudographics ZERO, ONE, TWO, THREE = ( @@ -88,7 +92,7 @@ def prune(branch): def draw_branch(branch, marks=[]): for i, (img, chldrn) in enumerate(branch): for x in marks: - print(ONE if x else ZERO, end='', file=self.file) + print(ONE if x else ZERO, end=u'', file=self.file) if i < len(branch) - 1: print(THREE + img.name, file=self.file) draw_branch(chldrn, marks + [1]) diff --git a/setup.py b/setup.py index 0f08869..44d00b2 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='docktree', - version='0.3.0', + version='0.3.1', description='Display the local Docker image layers as a tree', long_description=long_description, url='https://github.com/cmihai/docktree',